2023-03-10 04:43:38 +00:00
|
|
|
include $(PWD)/src/toolchain/Makefile
|
|
|
|
|
2023-02-17 06:09:13 +00:00
|
|
|
BACKEND_TF := $(wildcard infra/backend/*.tf)
|
|
|
|
ENVIRONMENT := production
|
2023-03-10 04:43:38 +00:00
|
|
|
REGION := sfo3
|
|
|
|
ROOT_DIR := $(shell pwd)
|
|
|
|
TERRAFORM := $(ROOT_DIR)/out/terraform
|
2023-02-17 06:09:13 +00:00
|
|
|
|
2023-03-10 07:43:21 +00:00
|
|
|
.DEFAULT_GOAL :=
|
|
|
|
.PHONY: default
|
|
|
|
default: \
|
|
|
|
toolchain \
|
|
|
|
apply
|
|
|
|
|
2023-02-17 06:09:13 +00:00
|
|
|
.PHONY:
|
|
|
|
clean:
|
|
|
|
rm -rf $(CACHE_DIR)
|
|
|
|
|
|
|
|
.PHONY:
|
|
|
|
credentials: \
|
|
|
|
$(CACHE_DIR)/secrets/credentials.tfvars
|
|
|
|
|
2023-03-10 04:43:38 +00:00
|
|
|
infra/backend/.terraform: \
|
|
|
|
$(OUT_DIR)/terraform \
|
|
|
|
$(BACKEND_TF)
|
|
|
|
env -C infra/backend $(TERRAFORM) init
|
2023-02-17 06:09:13 +00:00
|
|
|
|
2023-03-10 07:43:21 +00:00
|
|
|
infra/main/.terraform: \
|
|
|
|
$(OUT_DIR)/terraform \
|
|
|
|
$(BACKEND_TF)
|
|
|
|
env -C infra/main $(TERRAFORM) init \
|
|
|
|
-backend-config="../../config/$(ENVIRONMENT).tfbackend"
|
|
|
|
|
2023-03-10 04:43:38 +00:00
|
|
|
infra/backend/$(ENVIRONMENT).tfstate: \
|
|
|
|
$(CACHE_DIR)/secrets/credentials.tfvars \
|
|
|
|
$(OUT_DIR)/terraform \
|
|
|
|
infra/backend/.terraform
|
|
|
|
env -C infra/backend $(TERRAFORM) apply \
|
|
|
|
-var environment=$(ENVIRONMENT) \
|
|
|
|
-var namespace=$(ENVIRONMENT) \
|
|
|
|
-var region=$(REGION) \
|
|
|
|
-state ../../$@ \
|
|
|
|
-var-file ../../$<
|
2023-02-17 06:09:13 +00:00
|
|
|
|
2023-03-10 04:43:38 +00:00
|
|
|
config/$(ENVIRONMENT).tfbackend: \
|
|
|
|
infra/backend/$(ENVIRONMENT).tfstate \
|
|
|
|
$(OUT_DIR)/terraform
|
2023-03-10 07:43:21 +00:00
|
|
|
env -C infra/backend $(TERRAFORM) \
|
|
|
|
output -state ../../$< \
|
|
|
|
> $@
|
2023-02-17 06:09:13 +00:00
|
|
|
|
|
|
|
.PHONY:
|
2023-03-10 07:43:21 +00:00
|
|
|
apply: \
|
2023-03-10 04:43:38 +00:00
|
|
|
$(CACHE_DIR)/secrets/credentials.tfvars \
|
2023-03-10 07:43:21 +00:00
|
|
|
$(OUT_DIR)/terraform \
|
|
|
|
infra/main/.terraform
|
|
|
|
env -C infra/main $(TERRAFORM) apply \
|
|
|
|
-var-file ../../$<
|
2023-02-17 06:09:13 +00:00
|
|
|
|
|
|
|
$(CACHE_DIR)/secrets:
|
|
|
|
mkdir -p $@
|
|
|
|
|
2023-03-10 04:43:38 +00:00
|
|
|
$(CACHE_DIR)/secrets/%.tfvars: secrets/%.tfvars.gpg $(CACHE_DIR)/secrets
|
2023-02-17 06:09:13 +00:00
|
|
|
gpg --decrypt $< > $@
|
|
|
|
|
|
|
|
$(FETCH_DIR)/terraform:
|
|
|
|
$(call git_clone,$@,$(TERRAFORM_REPO),$(TERRAFORM_REF))
|
|
|
|
|
|
|
|
$(OUT_DIR)/terraform: $(FETCH_DIR)/terraform
|
2023-03-10 05:06:33 +00:00
|
|
|
$(call toolchain," \
|
2023-02-17 06:09:13 +00:00
|
|
|
cd $(FETCH_DIR)/terraform && \
|
|
|
|
export SSL_CERT_DIR=/etc/ssl/certs && \
|
2023-03-10 03:49:01 +00:00
|
|
|
export CGO_ENABLED=0 && \
|
2023-03-10 05:06:33 +00:00
|
|
|
export GOCACHE=/home/build/$(CACHE_DIR) && \
|
|
|
|
export GOPATH=/home/build/$(CACHE_DIR) && \
|
2023-03-10 03:49:01 +00:00
|
|
|
go build \
|
|
|
|
-v \
|
|
|
|
-trimpath \
|
|
|
|
-ldflags='-w -extldflags=-static' \
|
|
|
|
-o /home/build/$@ \
|
2023-02-17 06:09:13 +00:00
|
|
|
")
|