From 854982082a1e0f0cb22d9915fe692b500ab1aa1c Mon Sep 17 00:00:00 2001 From: Samuel Aubertin Date: Wed, 27 Sep 2023 18:11:39 +0200 Subject: [PATCH] alpha ? --- README.md | 4 +++- src/opack.mk | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 08b1fe6..306fb72 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/opack.mk b/src/opack.mk index ca679dc..7b177f3 100644 --- a/src/opack.mk +++ b/src/opack.mk @@ -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