Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell dustinlacewell/Makefile Secret

Last active Mar 27, 2019
Embed
What would you like to do?
# staging environment
STAGE ?= qa
STAGE_DIR := $(PWD)/stages/$(STAGE)
# summon details
SECRETS_FILE ?= secrets.yml
GOPASS ?= $(shell which gopass)
# deploy identity
DEPLOY_KEY ?= ~/.ssh/id_rsa.pub
export TF_VAR_deploy_key := $(shell cat $(DEPLOY_KEY))
# helper functions
compose = docker-compose -f compose-local $(1) $(2)
summon = cd $(STAGE_DIR) && summon -f $(SECRETS_FILE) -p $(GOPASS) $(1)
secret = $(call summon,env) | grep TF_VAR_$(1) | cut -d'=' -f2
terraform = $(call summon,terraform $(1) $(2))
target_args = $(if $(TARGET),"-target module.$(TARGET)","")
output_args = $(if $(MODULE),"-module=$(MODULE) $(RESOURCE)")
.PHONY: state
build:
$(call compose,build)
up: build
$(call compose,up,"--scale backend-migrate=0")
migrate:
$(call compose,up,backend-migrate)
state: SECRETS_FILE := /dev/null
state: STAGE_DIR := $(PWD)/state
state:
$(call terraform,init)
$(call terraform,apply,-auto-approve)
output:
@$(call terraform,output,$(output_args))
secret:
@$(call secret,$(SECRET))
init: state
$(call terraform,init)
plan, apply, destroy: init
$(call terraform,apply,$(target_args))
migrate-rds:
$(eval DB_HOST := $(shell $(call terraform,output,-module=aurora endpoint)))
$(eval DB_PASS := $(shell $(call secret,db_password)))
$(eval DB_USER := $(shell $(call secret,db_username)))
$(eval DB_URL := mysql://$(DB_USER):$(DB_PASS)@127.0.0.1/db)
$(eval SSH_HOST := $(shell $(call terraform,output,-module=kurento public_ip)))
$(eval SSH_PID := SSH_PID := $(shell ssh -N -L 3306:$(DB_HOST):3306 ubuntu@$(SSH_HOST) & echo "$$!"))
docker run -e DB_URL=$(DB_URL) -e DB_HOST=127.0.0.1 --net=host -it --rm infra_daphne python manage.py migrate
@kill $(SSH_PID)
# migrate-rds: DB_USER := $(shell $(call secret,db_username))
# migrate-rds: DB_PASS := $(shell $(call secret,db_password))
# migrate-rds: SSH_HOST := $(shell $(call terraform,output,-module=kurento public_ip))
# migrate-rds: DB_HOST := $(shell $(call terraform,output,-module=aurora endpoint))
# migrate-rds: DB_URL := mysql://$(DB_USER):$(DB_PASS)@127.0.0.1/db
# migrate-rds: SSH_PID := $(shell ssh -N -L 3306:$(DB_HOST):3306 ubuntu@$(SSH_HOST) & echo "$$!")
# migrate-rds:
# docker run -e DB_URL=$(DB_URL) -e DB_HOST=127.0.0.1 --net=host -it --rm infra_daphne python manage.py migrate
# @kill $(SSH_PID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.