From cb6ab6deacd7d75776f782679f11f2571e42eb05 Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Mon, 21 Jun 2021 11:55:18 +0300 Subject: [PATCH 1/3] Waypoint initial --- main.mk | 1 + waypoint/main.mk | 34 ++++++++++++++++++++++++++++++++++ waypoint/variables.mk | 6 ++++++ 3 files changed, 41 insertions(+) create mode 100644 waypoint/main.mk create mode 100644 waypoint/variables.mk diff --git a/main.mk b/main.mk index 7574034a..b8b69379 100644 --- a/main.mk +++ b/main.mk @@ -95,6 +95,7 @@ GOMPLATE ?= $(DOCKER) run \ -e AWS_PROFILE="$(AWS_PROFILE)" \ -e AWS_REGION="$(AWS_REGION)" \ -e NAMESPACE="$(NAMESPACE)" \ + -e ROOT_DIR="$(ROOT_DIR)" \ -e EC2_KEY_PAIR_NAME="$(EC2_KEY_PAIR_NAME)" \ -e TAG="$(TAG)" \ -e SSH_PUBLIC_KEY="$(SSH_PUBLIC_KEY)" \ diff --git a/waypoint/main.mk b/waypoint/main.mk new file mode 100644 index 00000000..b7a62d25 --- /dev/null +++ b/waypoint/main.mk @@ -0,0 +1,34 @@ +# Macroses +######################################################################################################################## + +WAYPOINT ?= $(DOCKER) run \ + --rm \ + --hostname="$(USER)-icmk-waypoint" \ + -v "$(ENV_DIR)":"$(ENV_DIR)" \ + -v "$(INFRA_DIR)":"$(INFRA_DIR)" \ + -v "$(ROOT_DIR)":"$(ROOT_DIR)" \ + -v "$(HOME)/.aws/":"/.aws:ro" \ + -w "$(ENV_DIR)" \ + -e AWS_PROFILE="$(AWS_PROFILE)" \ + -e ROOT_DIR="$(ROOT_DIR)" \ + -e ENV="$(ENV)" \ + $(WAYPOINT_DOCKER_IMAGE):$(WAYPOINT_VERSION) + +CMD_WAYPOINT_SERVICE_BUILD ?= \ + @\ + cd $(ENV_DIR) && \ + cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ + $(WAYPOINT) build -app $(SVC) + + + +# Tasks +######################################################################################################################## + +# Dependencies +######################################################################################################################## +# Ensures terraform is installed +waypoint: +ifeq (, $(WAYPOINT)) + $(error "waypoint is not installed or incorrectly configured.") +endif diff --git a/waypoint/variables.mk b/waypoint/variables.mk new file mode 100644 index 00000000..6aa75754 --- /dev/null +++ b/waypoint/variables.mk @@ -0,0 +1,6 @@ +# This file should contain variables used in current module +################################################################## +# main variables +WAYPOINT_VERSION ?= "latest" +WAYPOINT_DOCKER_IMAGE = hazelops/waypoint +WAYPOINT_CONFIG_FILE ?= $(ENV_DIR)/waypoint.hcl From e5dc14d209fac77a8ad5b2c0006aa8538f4d1955 Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Tue, 22 Jun 2021 22:27:48 +0300 Subject: [PATCH 2/3] Add Waypoint --- waypoint/main.mk | 52 ++++++++++++++++++++++++++++++++++++++++--- waypoint/variables.mk | 4 +++- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/waypoint/main.mk b/waypoint/main.mk index b7a62d25..6e6c6168 100644 --- a/waypoint/main.mk +++ b/waypoint/main.mk @@ -2,12 +2,15 @@ ######################################################################################################################## WAYPOINT ?= $(DOCKER) run \ + --user "root":"$(CURRENT_USERGROUP_ID)" \ --rm \ --hostname="$(USER)-icmk-waypoint" \ -v "$(ENV_DIR)":"$(ENV_DIR)" \ -v "$(INFRA_DIR)":"$(INFRA_DIR)" \ -v "$(ROOT_DIR)":"$(ROOT_DIR)" \ - -v "$(HOME)/.aws/":"/.aws:ro" \ + -v "$(HOME)/.aws/":"/home/waypoint/.aws:ro" \ + -v "$(HOME)/.aws/":"/root/.aws:ro" \ + -v "/var/run/docker.sock":"/var/run/docker.sock" \ -w "$(ENV_DIR)" \ -e AWS_PROFILE="$(AWS_PROFILE)" \ -e ROOT_DIR="$(ROOT_DIR)" \ @@ -15,20 +18,63 @@ WAYPOINT ?= $(DOCKER) run \ $(WAYPOINT_DOCKER_IMAGE):$(WAYPOINT_VERSION) CMD_WAYPOINT_SERVICE_BUILD ?= \ - @\ + \ cd $(ENV_DIR) && \ cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ $(WAYPOINT) build -app $(SVC) +CMD_WAYPOINT_SERVICE_DEPLOY ?= \ + @\ + cd $(ENV_DIR) && \ + cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ + $(WAYPOINT) deploy -release=false -app $(SVC) + +CMD_WAYPOINT_SERVICE_RELEASE ?= \ + @\ + cd $(ENV_DIR) && \ + cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ + $(WAYPOINT) release -app $(SVC) +CMD_WAYPOINT_INIT ?= \ + @\ + cd $(ENV_DIR) && \ + cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ + $(WAYPOINT) init +CMD_WAYPOINT_INSTALL ?= \ + @\ + cd $(ENV_DIR) && \ + cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ + $(WAYPOINT) install -accept-tos -platform=ecs -ecs-cluster=$(WAYPOINT_ECS_CLUSTER_NAME) -ecs-region=$(AWS_REGION) -runner=$(WAYPOINT_RUNNER_ENABLED) -ecs-server-image=$(WAYPOINT_DOCKER_IMAGE):$(WAYPOINT_VERSION) + +CMD_WAYPOINT_DESTROY ?= \ + @\ + cd $(ENV_DIR) && \ + cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ + $(WAYPOINT) destroy -auto-approve + +CMD_WAYPOINT_CONFIG_SET ?= @$(WAYPOINT) config source-set --type=aws-ssm --config region=$(AWS_REGION) # Tasks ######################################################################################################################## +waypoint: waypoint.install waypoint.init +waypoint.config: + $(CMD_WAYPOINT_CONFIG_SET) + +waypoint.init: gomplate waypoint-dependency + $(CMD_WAYPOINT_INIT) + $(CMD_WAYPOINT_CONFIG_SET) + + +waypoint.install: gomplate waypoint-dependency + $(CMD_WAYPOINT_INSTALL) + +waypoint.destroy: gomplate waypoint-dependency + $(CMD_WAYPOINT_DESTROY) # Dependencies ######################################################################################################################## # Ensures terraform is installed -waypoint: +waypoint-dependency: ifeq (, $(WAYPOINT)) $(error "waypoint is not installed or incorrectly configured.") endif diff --git a/waypoint/variables.mk b/waypoint/variables.mk index 6aa75754..0d4b2cc7 100644 --- a/waypoint/variables.mk +++ b/waypoint/variables.mk @@ -1,6 +1,8 @@ # This file should contain variables used in current module ################################################################## # main variables -WAYPOINT_VERSION ?= "latest" +WAYPOINT_VERSION ?= latest WAYPOINT_DOCKER_IMAGE = hazelops/waypoint WAYPOINT_CONFIG_FILE ?= $(ENV_DIR)/waypoint.hcl +WAYPOINT_ECS_CLUSTER_NAME ?= $(ENV)-$(NAMESPACE)-waypoint +WAYPOINT_RUNNER_ENABLED ?= false From 00a9f592a9c1f4c1d66e690263fc8c7a8a594fef Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Tue, 22 Jun 2021 22:29:29 +0300 Subject: [PATCH 3/3] Hide build command details --- waypoint/main.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/waypoint/main.mk b/waypoint/main.mk index 6e6c6168..d1dd5a7d 100644 --- a/waypoint/main.mk +++ b/waypoint/main.mk @@ -18,7 +18,7 @@ WAYPOINT ?= $(DOCKER) run \ $(WAYPOINT_DOCKER_IMAGE):$(WAYPOINT_VERSION) CMD_WAYPOINT_SERVICE_BUILD ?= \ - \ + @\ cd $(ENV_DIR) && \ cat $(WAYPOINT_CONFIG_FILE).gotpl | $(GOMPLATE) > $(WAYPOINT_CONFIG_FILE) && \ $(WAYPOINT) build -app $(SVC) @@ -64,7 +64,6 @@ waypoint.init: gomplate waypoint-dependency $(CMD_WAYPOINT_INIT) $(CMD_WAYPOINT_CONFIG_SET) - waypoint.install: gomplate waypoint-dependency $(CMD_WAYPOINT_INSTALL)