This commit is contained in:
Samuel Aubertin 2023-09-27 18:11:39 +02:00
parent dee53a0349
commit 854982082a
2 changed files with 8 additions and 5 deletions

View File

@ -71,6 +71,8 @@ Every default option ending with an `?` in "src/options.mk" can be overrided in
## Examples
A few examples are located in the [examples](examples) directory:
### Quick example
Here is the shortest Makefile that can be used to leverage skz-opack:
@ -116,7 +118,7 @@ Once the *opack* target dependency is finished, the VM is running and the system
Before using this example, you need to prepare the cloud environment:
1. [Create a GCP project](https://cloud.google.com/resource-manager/docs/creating-managing-projects) and declare its name by overriding `OPACK_GCE_PROJECT`.
2. [Create a service account](https://cloud.google.com/iam/docs/service-accounts-create) and [obtain its key](https://cloud.google.com/iam/docs/keys-create-delete), which path should be declared with `OPACK_GCE_JSON_KEY`.
3. [Create a GCS Bucket](https://cloud.google.com/storage/docs/creating-buckets) and declare its name with 'OPACK_GCE_BUCKET' (defaults to `OPACK_GCE_PROJECT`).
3. [Create a GCS Bucket](https://cloud.google.com/storage/docs/creating-buckets) and declare its name with `OPACK_GCE_BUCKET` (defaults to `OPACK_GCE_PROJECT`).
4. Enable the [Cloud Ressource Manager API](https://console.cloud.google.com/marketplace/product/google/cloudresourcemanager.googleapis.com) in order for the service account to use it with its key.
```make

View File

@ -101,9 +101,9 @@ $(OPACK_TERRAFORM_MODULE_DIR)/main.tf: $(OPACK_TERRAFORM_MODULE_DIR)
$(OPACK_TERRAFORM_DIR)/terraform.tfstate: | $(OPACK_PACKER_DIR)/disk.raw.tar.gz $(OPACK_TERRAFORM_DIR)/main.tf $(OPACK_TERRAFORM_MODULE_DIR)/main.tf
ifndef OPACK_DEBUG
$(call spinner,cd $(OPACK_TERRAFORM_DIR) && terraform init >> opack.log && terraform apply -auto-approve >> opack.log && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_IMPORT_CONTENT))' >> $(OPACK_TERRAFORM_MODULE_DIR)/main.tf && terraform import module.opack-module.google_compute_image.$(OPACK_TARGET) projects/$(OPACK_GCE_PROJECT)/global/images/$(OPACK_TARGET) >> opack.log && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_MODULE_CONTENT))' > $(OPACK_TERRAFORM_MODULE_DIR)/main.tf,█ $(shell date +'%H:%M:%S') Deploying with Terraform)
$(call spinner,cd $(OPACK_TERRAFORM_DIR) && terraform init >> opack.log && terraform apply -auto-approve >> opack.log && cd .. && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_IMPORT_CONTENT))' >> $(OPACK_TERRAFORM_MODULE_DIR)/main.tf && cd $(OPACK_TERRAFORM_DIR) && terraform import module.opack-module.google_compute_image.$(OPACK_TARGET) projects/$(OPACK_GCE_PROJECT)/global/images/$(OPACK_TARGET) >> opack.log && cd .. && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_MODULE_CONTENT))' > $(OPACK_TERRAFORM_MODULE_DIR)/main.tf,█ $(shell date +'%H:%M:%S') Deploying with Terraform)
else
cd $(OPACK_TERRAFORM_DIR) && terraform init && terraform apply -auto-approve && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_IMPORT_CONTENT))' >> $(OPACK_TERRAFORM_MODULE_DIR)/main.tf && terraform import module.opack-module.google_compute_image.$(OPACK_TARGET) projects/$(OPACK_GCE_PROJECT)/global/images/$(OPACK_TARGET) && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_MODULE_CONTENT))' > $(OPACK_TERRAFORM_MODULE_DIR)/main.tf
cd $(OPACK_TERRAFORM_DIR) && terraform init && terraform apply -auto-approve && cd .. && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_IMPORT_CONTENT))' >> $(OPACK_TERRAFORM_MODULE_DIR)/main.tf && cd $(OPACK_TERRAFORM_DIR) && terraform import module.opack-module.google_compute_image.$(OPACK_TARGET) projects/$(OPACK_GCE_PROJECT)/global/images/$(OPACK_TARGET) && cd .. && printf '$(subst $(newline),\n,$(OPACK_TERRAFORM_MODULE_CONTENT))' > $(OPACK_TERRAFORM_MODULE_DIR)/main.tf
endif
$(OPACK_VAGRANT_FILE):
@ -122,8 +122,9 @@ opack-cloud-ssh: opack-cloud
opack-cloud: | $(OPACK_TERRAFORM_DIR)/terraform.tfstate
cd $(OPACK_TERRAFORM_DIR) 2>/dev/null && terraform output -json ip 2>/dev/null | tr -d '"' | tr -d '[' | tr -d ']' > ../$@
while ! nc -z -w 10 $(shell cat opack-cloud) 22 2>/dev/null; do sleep 10; done
echo "$(shell date +'%H:%M:%S') skz-opack complete"; echo "▒ You can SSH into $(OPACK_TARGET) using $(OPACK_SYS_SSH_PRIVATE_KEY), or using 'make opack-cloud-ssh':";
while ! nc -z -w 10 $$(cat $@ 2> /dev/null) 22 2>/dev/null; do sleep 10; done
echo "$(shell date +'%H:%M:%S') skz-opack complete"; echo "▒ You can SSH into $(OPACK_TARGET) 'make opack-cloud-ssh' or using:"
echo "░ ssh -i $(OPACK_SYS_SSH_PRIVATE_KEY) $(OPACK_SYS_USER)@$$(cat $@ 2> /dev/null) ";
opack-clean:
ifndef OPACK_DEBUG