-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
163 lines (133 loc) · 4.2 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
.DEFAULT_GOAL := get
OS := $(shell uname -s | tr A-Z a-z)
export GOBIN := $(abspath .)/bin/$(OS)
export AWS_DEFAULT_REGION ?= us-east-2
DOMAIN_NAME ?= test.dev.superhub.io
COMPONENT_NAME ?= git-service
LOCAL_IMAGE ?= agilestacks/git-service
REGISTRY ?= $(shell $(aws) sts get-caller-identity | jq -r .Account).dkr.ecr.$(AWS_DEFAULT_REGION).amazonaws.com
IMAGE ?= $(REGISTRY)/agilestacks/$(DOMAIN_NAME)/git-service
IMAGE_VERSION ?= $(shell git rev-parse HEAD | colrm 7)
NAMESPACE ?= automation-hub
HUB_PROVIDES ?=
ifneq (,$(filter tls-ingress,$(HUB_PROVIDES)))
INGRESS:=ingress-tls
else
INGRESS:=ingress
endif
BACKUP_BUCKET ?= files.$(DOMAIN_NAME)
BACKUP_REGION ?= us-east-2
REPOS_PATH ?= /git
TS := $(shell date +"%Y-%m-%d-%H-%M-%S")
BACKUP_SNAPSHOT ?= s3://$(BACKUP_BUCKET)/$(DOMAIN_NAME)/backup/git-service/$(COMPONENT_NAME)/$(TS).tar.bz
kubectl ?= kubectl --context="$(DOMAIN_NAME)" --namespace="$(NAMESPACE)"
docker ?= docker
aws ?= aws
running_git_pod := $(kubectl) get pods -l provider=agilestacks.com,project=git-service,qualifier=gits \
-o jsonpath='{range.items[?(@.status.containerStatuses[0].ready==true)]}{.kind}{"\n"}{end}'
get:
go get github.com/agilestacks/git-service/cmd/gits
.PHONY: get
run: get
$(GOBIN)/gits \
-api_secret_env '' \
-no_ext_api_calls \
-repo_dir /tmp/gits \
-aws_region us-east-2 \
-aws_profile agilestacks \
-trace
.PHONY: run
fmt:
go fmt github.com/agilestacks/git-service/...
.PHONY: fmt
vet:
go vet -composites=false github.com/agilestacks/git-service/...
.PHONY: vet
key:
@ssh-keygen -t rsa -f gits-key -N ''
.PHONY: key
deploy: build ecr-login push kubernetes
ifneq ($(RESTORE_SNAPSHOT),)
deploy: wait restore
endif
.PHONY: deploy
wait:
@echo "Waiting for Git Service pod to stand up"; \
sleep 5; \
for i in $$(seq 1 30); do \
if test -n "$$($(running_git_pod))"; then \
echo "done"; \
exit 0; \
fi; \
echo "still waiting"; \
sleep 10; \
done; \
echo "timeout"; \
exit 1
.PHONY: wait
find-pod:
@$(kubectl) get pods
$(eval GITS_POD=$(shell $(kubectl) get pods -l project=git-service,provider=agilestacks.com,qualifier=gits --output=jsonpath={.items..metadata.name}))
.PHONY: find-pod
maintenance-on: find-pod
$(kubectl) exec $(GITS_POD) -- \
touch "$(REPOS_PATH)/_maintenance"
@sleep 5
.PHONY: maintenance-on
maintenance-off: find-pod
$(kubectl) exec $(GITS_POD) -- \
rm -f "$(REPOS_PATH)/_maintenance"
.PHONY: maintenance-off
backup: maintenance-on tar maintenance-off
tar: find-pod
$(kubectl) exec $(GITS_POD) -- /bin/sh -c \
"tar cjf - -C $(REPOS_PATH) . | aws --region=$(BACKUP_REGION) s3 cp - $(BACKUP_SNAPSHOT)"
@echo Outputs:
@echo kind = git-service
@echo component.git-service.snapshot = $(BACKUP_SNAPSHOT)
@echo
.PHONY: tar
connect: find-pod
$(kubectl) exec -ti $(GITS_POD) /bin/sh
.PHONY: connect
ifneq ($(RESTORE_SNAPSHOT),)
restore: maintenance-on untar maintenance-off
untar: find-pod
$(kubectl) exec $(GITS_POD) -- /bin/sh -c \
"aws s3 cp $(RESTORE_SNAPSHOT) - | tar xjpf - -C $(REPOS_PATH)"
.PHONY: untar
endif
delete-pod: find-pod
$(kubectl) delete pod $(GITS_POD)
.PHONY: delete-pod
clean:
@rm -f gits bin/gits
@rm -rf bin/darwin bin/linux
.PHONY: clean
build:
$(docker) build -t $(LOCAL_IMAGE):$(IMAGE_VERSION) -t $(LOCAL_IMAGE):latest .
.PHONY: build
ecr-login:
$(aws) ecr get-login-password --region $(AWS_DEFAULT_REGION) | $(docker) login --username AWS --password-stdin $(REGISTRY)
.PHONY: ecr-login
push:
$(docker) tag $(LOCAL_IMAGE):$(IMAGE_VERSION) $(IMAGE):$(IMAGE_VERSION)
$(docker) tag $(LOCAL_IMAGE):$(IMAGE_VERSION) $(IMAGE):latest
$(docker) push $(IMAGE):$(IMAGE_VERSION)
$(docker) push $(IMAGE):latest
.PHONY: push
kubernetes:
$(kubectl) apply -f templates/namespace.yaml
$(kubectl) apply -f templates/pvc.yaml
$(kubectl) apply -f templates/service.yaml
$(kubectl) apply -f templates/$(INGRESS).yaml
$(kubectl) apply -f templates/secret.yaml
$(kubectl) apply -f templates/deployment.yaml
.PHONY: kubernetes
undeploy:
-$(kubectl) delete -f templates/deployment.yaml
-$(kubectl) delete -f templates/secret.yaml
-$(kubectl) delete -f templates/$(INGRESS).yaml
-$(kubectl) delete -f templates/service.yaml
-$(kubectl) delete -f templates/pvc.yaml
.PHONY: undeploy