forked from vardius/go-api-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
103 lines (79 loc) · 4.22 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# This version-strategy uses git tags to set the version string
VERSION := $(shell git describe --tags --always --dirty)
GIT_COMMIT := $(shell git rev-list -1 HEAD)
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
version: ## Show version
@echo $(VERSION) \(git commit: $(GIT_COMMIT)\)
workflow-generate: ## Generate github workflows from templates
cd .github && sh workflows.sh
# HTTPS TASK
key: ## [HTTP] Generate key
openssl genrsa -out server.key 2048
openssl ecparam -genkey -name secp384r1 -out server.key
cert: ## [HTTP] Generate self signed certificate
openssl req -new -x509 -sha256 -key server.key -out server.pem -days 3650
# DOCKER TASKS
docker-build: ## [DOCKER] Build given container. Example: `make docker-build BIN=user`
docker build -f cmd/$(BIN)/Dockerfile --no-cache --build-arg BIN=$(BIN) --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) -t go-api-boilerplate-$(BIN) .
docker-run: ## [DOCKER] Run container on given port. Example: `make docker-run BIN=user PORT=3000`
docker run -i -t --rm -p=$(PORT):$(PORT) --name="go-api-boilerplate-$(BIN)" go-api-boilerplate-$(BIN)
docker-stop: ## [DOCKER] Stop docker container. Example: `make docker-stop BIN=user`
docker stop go-api-boilerplate-$(BIN)
docker-rm: docker-stop ## [DOCKER] Stop and then remove docker container. Example: `make docker-rm BIN=user`
docker rm go-api-boilerplate-$(BIN)
docker-publish: docker-tag-latest docker-tag-version docker-publish-latest docker-publish-version ## [DOCKER] Docker publish. Example: `make docker-publish BIN=user REGISTRY=https://your-registry.com`
docker-publish-latest:
@echo 'publish latest to $(REGISTRY)'
docker push $(REGISTRY)/go-api-boilerplate-$(BIN):latest
docker-publish-version:
@echo 'publish $(VERSION) to $(REGISTRY)'
docker push $(REGISTRY)/go-api-boilerplate-$(BIN):$(VERSION)
docker-tag: docker-tag-latest docker-tag-version ## [DOCKER] Tag current container. Example: `make docker-tag BIN=user REGISTRY=https://your-registry.com`
docker-tag-latest:
@echo 'create tag latest'
docker tag go-api-boilerplate-$(BIN) $(REGISTRY)/go-api-boilerplate-$(BIN):latest
docker-tag-version:
@echo 'create tag $(VERSION)'
docker tag go-api-boilerplate-$(BIN) $(REGISTRY)/go-api-boilerplate-$(BIN):$(VERSION)
docker-release: docker-build docker-publish ## [DOCKER] Docker release - build, tag and push the container. Example: `make docker-release BIN=user REGISTRY=https://your-registry.com`
# TERRAFORM TASKS
terraform-install: ## [TERRAFORM] Install terraform deployment to your kubernetes cluster. Example: `make terraform-install`
cd k8s \
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.crds.yaml \
terraform init \
terraform apply \
terraform output -raw templates | kubectl apply -f -
terraform-destroy: ## [TERRAFORM] Remove deployment kubernetes cluster. Example: `make terraform-destroy`
cd k8s \
terraform destroy
# TELEPRESENCE TASKS
telepresence-swap-local: ## [TELEPRESENCE] Replace the existing deployment with the Telepresence proxy for local process. Example: `make telepresence-swap-local BIN=user PORT=3000 DEPLOYMENT=go-api-boilerplate-user`
go build -o cmd/$(BIN)/$(BIN) cmd/$(BIN)/main.go
telepresence \
--swap-deployment $(DEPLOYMENT) \
--expose 3000 \
--run ./cmd/$(BIN)/$(BIN) \
--port=$(PORT) \
--method vpn-tcp
telepresence-swap-docker: ## [TELEPRESENCE] Replace the existing deployment with the Telepresence proxy for local docker image. Example: `make telepresence-swap-docker BIN=user PORT=3000 DEPLOYMENT=go-api-boilerplate-user`
telepresence \
--swap-deployment $(DEPLOYMENT) \
--docker-run -i -t --rm -p=$(PORT):$(PORT) --name="$(BIN)" $(BIN):latest
# HELPERS
# generate script to login to aws docker repo
CMD_REPOLOGIN := "eval $$\( aws ecr"
ifdef AWS_CLI_PROFILE
CMD_REPOLOGIN += " --profile $(AWS_CLI_PROFILE)"
endif
ifdef AWS_CLI_REGION
CMD_REPOLOGIN += " --region $(AWS_CLI_REGION)"
endif
CMD_REPOLOGIN += " get-login \)"
aws-repo-login: ## [HELPER] login to AWS-ECR
@eval $(CMD_REPOLOGIN)