forked from codecov/codecov-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.circle
222 lines (191 loc) · 8.33 KB
/
Makefile.circle
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
-include .envrc
name ?= api
sha := $(shell git rev-parse --short=7 HEAD)
build_date ?= $(shell git show -s --date=iso8601-strict --pretty=format:%cd $$sha)
tag ?= $(shell echo $$(git rev-list --count HEAD)$$(git show -s --format=.%ad.%h --date=format:%Y-%m-%d))
branch = $(shell git branch | grep \* | cut -f2 -d' ')
docker_version = $(shell git describe --always --tags --dirty | sed 's/^v//')
dockerhub_image := codecov/self-hosted-api
release_env = main
SEMANTIC_VERSION := `cat VERSION`
ifneq ($(branch), main)
release_env = pr
endif
#
GCR_REPO := ${CODECOV_API_IMAGE}
ENTERPRISE_GCR_REPO := ${CODECOV_API_ENTERPRISE_IMAGE}
REQUIREMENTS_TAG := requirements-v1-$(shell sha1sum requirements.txt | cut -d ' ' -f 1)-$(shell sha1sum Dockerfile.requirements | cut -d ' ' -f 1)
VERSION := release-$(shell git rev-parse --short=7 HEAD)
# CIRCLECI
# job: build
# builds an intermediate image with dependencies if there were changes to
# requirements.txt
build-requirements:
# if docker pull succeeds, we have already build this version of
# requirements.txt. Otherwise, build and push a version tagged
# with the hash of this requirements.txt
docker pull ${GCR_REPO}:${REQUIREMENTS_TAG} || DOCKER_BUILDKIT=1 docker build \
-f Dockerfile.requirements . \
-t ${GCR_REPO}:${REQUIREMENTS_TAG} \
--ssh default \
&& docker push ${GCR_REPO}:${REQUIREMENTS_TAG}; true
# CIRCLECI
# job: build
# pulls intermediate dependencies image and adds app code
build:
docker pull ${GCR_REPO}:${REQUIREMENTS_TAG}
DOCKER_BUILDKIT=1 docker build \
-f Dockerfile.circle . \
-t ${GCR_REPO}:latest \
--build-arg REQUIREMENTS_IMAGE=${GCR_REPO}:${REQUIREMENTS_TAG}
# CIRCLECI
# job: enterprise
# pulls intermediate dependencies image and adds app code. Cythonize and pyinstall (no dependencies).
build-enterprise:
docker pull ${GCR_REPO}:${REQUIREMENTS_TAG}
docker build \
-f Dockerfile.circle-enterprise . \
-t ${ENTERPRISE_GCR_REPO}:latest_no_dependencies \
--build-arg REQUIREMENTS_IMAGE=${GCR_REPO}:${REQUIREMENTS_TAG}
# CIRCLECI
# job: enterprise-runtime
# pulls enterprise dependencies without dependencies and add them
build-enterprise-runtime:
docker build \
-f Dockerfile.enterprise_runtime . \
-t ${ENTERPRISE_GCR_REPO}:latest \
--build-arg CODECOV_ENTERPRISE_RELEASE=${ENTERPRISE_GCR_REPO}:latest_no_dependencies
# CIRCLECI
# job: portable
# builds an image for deploying a portable version of the containers
build-portable: build-requirements
DOCKER_BUILDKIT=1 docker build -f Dockerfile.circle . -t codecov/$(name) \
--label "org.label-schema.build-date"="$(build_date)" \
--label "org.label-schema.name"="$(name)" \
--label "org.label-schema.vcs-ref"="$(sha)" \
--label "org.label-schema.vendor"="Codecov" \
--label "org.label-schema.version"="$(tag)" \
--label "org.vcs-branch"="$(branch)" \
--build-arg REQUIREMENTS_IMAGE=${GCR_REPO}:${REQUIREMENTS_TAG}
# CIRCLECI
# job: test
# used to push latest image tag after a successful test
push:
docker push ${GCR_REPO}:latest
# CIRCLECI
# job: enterprise
# used to push latest image tag after a successful test
push-enterprise:
docker push ${ENTERPRISE_GCR_REPO}:latest_no_dependencies
docker push ${ENTERPRISE_GCR_REPO}:latest
# CIRCLECI
# job: deploy
# tags latest image with git tag
tag:
docker pull ${GCR_REPO}:latest
docker tag ${GCR_REPO}:latest ${GCR_REPO}:${VERSION}
docker push ${GCR_REPO}:${VERSION}
# CIRCLECI
# job: enterprise
# tags latest image with git tag
tag-enterprise:
docker pull ${ENTERPRISE_GCR_REPO}:latest
docker pull ${ENTERPRISE_GCR_REPO}:latest_no_dependencies
docker tag ${ENTERPRISE_GCR_REPO}:latest ${ENTERPRISE_GCR_REPO}:${VERSION}
docker tag ${ENTERPRISE_GCR_REPO}:latest_no_dependencies ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies
docker push ${ENTERPRISE_GCR_REPO}:${VERSION}
docker push ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies
save:
docker save -o app.tar ${GCR_REPO}:${VERSION}
# build and tag with staging tag
# - when the docker image is uploaded to GCR with the "staging" tag, spinnaker will automatically detect the new image and deploy to the staging k8s cluster
staging:
docker load -i app.tar
docker tag "${GCR_REPO}:${VERSION}" "${GCR_REPO}:staging-${VERSION}"
docker push ${GCR_REPO}:staging-${VERSION}
# build and tag with production tag
# - when the docker image is uploaded to GCR with the "production" tag, spinnaker will automatically detect the new image and deploy to the production k8s cluster
production:
docker load -i app.tar
docker tag "${GCR_REPO}:${VERSION}" "${GCR_REPO}:production-${VERSION}"
docker push ${GCR_REPO}:production-${VERSION}
# CIRCLECI
# job: enterprise
# deploys tagged version of the private enterprise-api
enterprise:
docker pull ${ENTERPRISE_GCR_REPO}:${VERSION}
docker pull ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies
docker tag ${ENTERPRISE_GCR_REPO}:${VERSION} ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}
docker tag ${ENTERPRISE_GCR_REPO}:${VERSION} ${dockerhub_image}:rolling
docker tag ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}_no_dependencies
docker tag ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies ${dockerhub_image}:rolling_no_dependencies
docker push ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}
docker push ${dockerhub_image}:rolling
docker push ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}_no_dependencies
docker push ${dockerhub_image}:rolling_no_dependencies
# CIRCLECI
# job: enterprise-release
# deploys tagged version of the public enterprise-api
release-enterprise:
docker pull ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}
docker pull ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}_no_dependencies
docker tag ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION} ${dockerhub_image}:${SEMANTIC_VERSION}
docker tag ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION} ${dockerhub_image}:latest-stable
docker tag ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION} ${dockerhub_image}:latest-calver
docker tag ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}_no_dependencies ${dockerhub_image}:${SEMANTIC_VERSION}_no_dependencies
docker tag ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}_no_dependencies ${dockerhub_image}:latest-stable_no_dependencies
docker tag ${ENTERPRISE_GCR_REPO}:${SEMANTIC_VERSION}-${VERSION}_no_dependencies ${dockerhub_image}:latest-calver_no_dependencies
docker push ${dockerhub_image}:${SEMANTIC_VERSION}
docker push ${dockerhub_image}:latest-stable
docker push ${dockerhub_image}:latest-calver
docker push ${dockerhub_image}:${SEMANTIC_VERSION}_no_dependencies
docker push ${dockerhub_image}:latest-stable_no_dependencies
docker push ${dockerhub_image}:latest-calver_no_dependencies
dive:
docker load -i app.tar
CI=true dive ${GCR_REPO}:${VERSION} --lowestEfficiency=0.97 --highestUserWastedPercent=0.06
dive-enterprise:
CI=true dive ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies --lowestEfficiency=0.9999 --highestUserWastedPercent=0.02
deep-dive:
deep-dive --config .deep-dive.yaml ${ENTERPRISE_GCR_REPO}:${VERSION}_no_dependencies
# LOCAL
# used to test circleci jobs
# example$ make circleci-local JOB=build
circleci-local:
circleci local execute \
-c .circleci/local.yml \
--job ${JOB} \
--env GH_ACCESS_TOKEN=${GH_ACCESS_TOKEN} \
--env GCLOUD_SERVICE_KEY=${GCLOUD_SERVICE_KEY} \
--env GOOGLE_COMPUTE_ZONE=us-east4 \
--env GOOGLE_PROJECT_ID=codecov-enterprise-sandbox \
--env VERSION=${VERSION}
# LOCAL
# use locally to tag a new release version.
# this will trigger a build/test/deployment on circle ci
release:
git checkout main
git pull
git tag ${VERSION}
git push --tags
# LOCAL
# use lcoally to log-into dockerhub.
docker-login:
docker login -u="$$DOCKER_USERNAME" -p="$$DOCKER_PASSWORD"
# CIRCLECI
# job: portable
# deploys tagged version of the portable container to dockerhub.
docker-deploy: docker-deploy-$(release_env)
# CIRCLECI
# job: portable
# deploys tagged version of the portable container to dockerhub and updates the latest tag.
docker-deploy-main: build-portable
docker tag codecov/$(name) codecov/$(name):$(tag)
docker push codecov/$(name):latest
docker push codecov/$(name):$(tag)
# CIRCLECI
# job: portable
# deploys tagged version of the portable container to dockerhub when ran on PRs and locally.
docker-deploy-pr: build-portable
docker tag codecov/$(name) codecov/$(name):$(docker_version)
docker push codecov/$(name):$(docker_version)