Skip to content

Commit d71e835

Browse files
committed
add custom requirements image, Makefile commands to build images with them
1 parent dd90d42 commit d71e835

7 files changed

Lines changed: 154 additions & 307 deletions

File tree

Makefile

Lines changed: 97 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -1,280 +1,102 @@
1-
sha := $(shell git rev-parse --short=7 HEAD)
2-
long_sha := $(shell git rev-parse HEAD)
3-
release_version := `cat VERSION`
4-
build_date ?= $(shell git show -s --date=iso8601-strict --pretty=format:%cd $$sha)
5-
branch = $(shell git branch | grep \* | cut -f2 -d' ')
6-
epoch := $(shell date +"%s")
7-
AR_REPO ?= codecov/umbrella
8-
DOCKERHUB_REPO ?= codecov/self-hosted-api
9-
REQUIREMENTS_TAG := requirements-v1-$(shell sha1sum requirements.txt | cut -d ' ' -f 1)-$(shell sha1sum docker/Dockerfile.requirements | cut -d ' ' -f 1)
10-
VERSION := release-${sha}
11-
CODECOV_UPLOAD_TOKEN ?= "notset"
12-
CODECOV_STATIC_TOKEN ?= "notset"
13-
TIMESERIES_ENABLED ?= "true"
14-
CODECOV_URL ?= "https://api.codecov.io"
15-
export DOCKER_BUILDKIT=1
16-
export API_DOCKER_REPO=${AR_REPO}
17-
export API_DOCKER_VERSION=${VERSION}
18-
export CODECOV_TOKEN=${CODECOV_UPLOAD_TOKEN}
19-
API_DOMAIN ?= api
20-
PROXY_NETWORK ?= api_default
21-
22-
# Codecov CLI version to use
23-
CODECOV_CLI_VERSION := 0.5.1
24-
25-
include tools/devenv/Makefile.devenv
26-
27-
update-reqs:
28-
cd codecov-api && git pull
29-
cd worker && git pull
30-
cd shared && git pull
31-
cat worker/requirements.in codecov-api/requirements.in | sort -u > requirements.in
32-
pip-compile requirements.in
33-
34-
build:
35-
make build.requirements
36-
make build.app
37-
38-
check-for-migration-conflicts:
39-
python manage.py check_for_migration_conflicts
1+
export sha := $(shell git rev-parse --short=7 HEAD)
2+
export full_sha := $(shell git rev-parse HEAD)
3+
export long_sha := ${full_sha}
4+
export merge_sha := $(shell git merge-base HEAD^ origin/main)
5+
export VERSION := release-${sha}
406

41-
test:
42-
COVERAGE_CORE=sysmon python -m pytest --cov=./ --junitxml=junit.xml
7+
export build_date ?= $(shell git show -s --date=iso8601-strict --pretty=format:%cd $$sha)
8+
export branch := $(shell git branch | grep \* | cut -f2 -d' ')
439

44-
test.unit:
45-
COVERAGE_CORE=sysmon python -m pytest --cov=./ -m "not integration" --cov-report=xml:unit.coverage.xml --junitxml=unit.junit.xml
46-
47-
test.integration:
48-
COVERAGE_CORE=sysmon python -m pytest --cov=./ -m "integration" --cov-report=xml:integration.coverage.xml --junitxml=integration.junit.xml
49-
50-
lint:
51-
make lint.install
52-
make lint.run
53-
54-
lint.install:
55-
echo "Installing..."
56-
pip install -Iv ruff
57-
58-
lint.run:
59-
ruff check
60-
ruff format
10+
export DOCKER_BUILDKIT=1
6111

62-
lint.check:
63-
echo "Linting..."
64-
ruff check
65-
echo "Formatting..."
66-
ruff format --check
12+
export SHARED_SHA := $(shell git archive --format=tar HEAD libs/shared | sha1sum | head -c 40)
13+
export DOCKER_REQS_SHA := $(shell sha1sum docker/Dockerfile.requirements | head -c 40)
6714

68-
build.requirements:
69-
# if docker pull succeeds, we have already build this version of
70-
# requirements.txt. Otherwise, build and push a version tagged
71-
# with the hash of this requirements.txt
72-
touch .testenv
15+
# Generic target for building a requirements image. You probably want
16+
# `worker.build.requirements` or `api.build.requirements`.
17+
_build.requirements:
7318
docker pull ${AR_REPO}:${REQUIREMENTS_TAG} || docker build \
74-
-f docker/Dockerfile.requirements . \
75-
-t ${AR_REPO}:${REQUIREMENTS_TAG} \
76-
-t codecov/umbrella-ci-requirements:${REQUIREMENTS_TAG}
77-
78-
build.local:
79-
docker build -f docker/Dockerfile . \
80-
-t ${AR_REPO}:latest \
81-
-t ${AR_REPO}:${VERSION} \
82-
--build-arg REQUIREMENTS_IMAGE=${AR_REPO}:${REQUIREMENTS_TAG} \
83-
--build-arg BUILD_ENV=local
84-
85-
build.app:
86-
docker build -f docker/Dockerfile . \
87-
-t ${AR_REPO}:latest \
88-
-t ${AR_REPO}:${VERSION} \
89-
--label "org.label-schema.vendor"="Codecov" \
90-
--label "org.label-schema.version"="${release_version}-${sha}" \
91-
--label "org.opencontainers.image.revision"="$(long_sha)" \
92-
--label "org.opencontainers.image.source"="github.com/codecov/umbrella" \
93-
--build-arg REQUIREMENTS_IMAGE=${AR_REPO}:${REQUIREMENTS_TAG} \
94-
--build-arg RELEASE_VERSION=${VERSION} \
95-
--build-arg BUILD_ENV=cloud
96-
97-
build.self-hosted:
98-
make build.self-hosted-base
99-
make build.self-hosted-runtime
100-
101-
build.self-hosted-base:
102-
docker build -f docker/Dockerfile . \
103-
-t ${DOCKERHUB_REPO}:latest-no-dependencies \
104-
-t ${DOCKERHUB_REPO}:${VERSION}-no-dependencies \
105-
--build-arg REQUIREMENTS_IMAGE=${AR_REPO}:${REQUIREMENTS_TAG} \
106-
--build-arg RELEASE_VERSION=${VERSION} \
107-
--build-arg BUILD_ENV=self-hosted
108-
109-
build.self-hosted-runtime:
110-
docker build -f docker/Dockerfile . \
111-
-t ${DOCKERHUB_REPO}:latest \
112-
-t ${DOCKERHUB_REPO}:${VERSION} \
113-
--label "org.label-schema.vendor"="Codecov" \
114-
--label "org.label-schema.version"="${release_version}-${sha}" \
115-
--build-arg REQUIREMENTS_IMAGE=${AR_REPO}:${REQUIREMENTS_TAG} \
116-
--build-arg RELEASE_VERSION=${VERSION} \
117-
--build-arg BUILD_ENV=self-hosted-runtime
118-
119-
tag.latest:
120-
docker tag ${AR_REPO}:${VERSION} ${AR_REPO}:latest
121-
122-
tag.staging:
123-
docker tag ${AR_REPO}:${VERSION} ${AR_REPO}:staging-${VERSION}
124-
125-
tag.production:
126-
docker tag ${AR_REPO}:${VERSION} ${AR_REPO}:production-${VERSION}
127-
128-
tag.self-hosted-rolling:
129-
docker tag ${DOCKERHUB_REPO}:${VERSION}-no-dependencies ${DOCKERHUB_REPO}:rolling_no_dependencies
130-
docker tag ${DOCKERHUB_REPO}:${VERSION} ${DOCKERHUB_REPO}:rolling
131-
132-
tag.self-hosted-release:
133-
docker tag ${DOCKERHUB_REPO}:${VERSION}-no-dependencies ${DOCKERHUB_REPO}:${release_version}_no_dependencies
134-
docker tag ${DOCKERHUB_REPO}:${VERSION}-no-dependencies ${DOCKERHUB_REPO}:latest_calver_no_dependencies
135-
docker tag ${DOCKERHUB_REPO}:${VERSION}-no-dependencies ${DOCKERHUB_REPO}:latest_stable_no_dependencies
136-
docker tag ${DOCKERHUB_REPO}:${VERSION} ${DOCKERHUB_REPO}:${release_version}
137-
docker tag ${DOCKERHUB_REPO}:${VERSION} ${DOCKERHUB_REPO}:latest-stable
138-
docker tag ${DOCKERHUB_REPO}:${VERSION} ${DOCKERHUB_REPO}:latest-calver
139-
140-
load.requirements:
141-
docker load --input requirements.tar
142-
docker tag codecov/umbrella-ci-requirements:${REQUIREMENTS_TAG} ${AR_REPO}:${REQUIREMENTS_TAG}
143-
144-
load.self-hosted:
145-
docker load --input self-hosted-runtime.tar
146-
docker load --input self-hosted.tar
147-
148-
save.app:
149-
docker save -o app.tar ${AR_REPO}:${VERSION}
150-
151-
save.requirements:
152-
docker tag ${AR_REPO}:${REQUIREMENTS_TAG} codecov/umbrella-ci-requirements:${REQUIREMENTS_TAG}
153-
docker save -o requirements.tar codecov/umbrella-ci-requirements:${REQUIREMENTS_TAG}
154-
155-
save.self-hosted:
156-
make save.self-hosted-base
157-
make save.self-hosted-runtime
158-
159-
save.self-hosted-base:
160-
docker save -o self-hosted.tar ${DOCKERHUB_REPO}:${VERSION}-no-dependencies
161-
162-
save.self-hosted-runtime:
163-
docker save -o self-hosted-runtime.tar ${DOCKERHUB_REPO}:${VERSION}
164-
165-
push.latest:
166-
docker push ${AR_REPO}:latest
167-
168-
push.staging:
169-
docker push ${AR_REPO}:staging-${VERSION}
170-
171-
push.production:
172-
docker push ${AR_REPO}:production-${VERSION}
173-
174-
push.requirements:
175-
docker push ${AR_REPO}:${REQUIREMENTS_TAG}
176-
177-
push.self-hosted-release:
178-
docker push ${DOCKERHUB_REPO}:${release_version}_no_dependencies
179-
docker push ${DOCKERHUB_REPO}:latest_calver_no_dependencies
180-
docker push ${DOCKERHUB_REPO}:latest_stable_no_dependencies
181-
docker push ${DOCKERHUB_REPO}:${release_version}
182-
docker push ${DOCKERHUB_REPO}:latest-stable
183-
docker push ${DOCKERHUB_REPO}:latest-calver
184-
185-
push.self-hosted-rolling:
186-
docker push ${DOCKERHUB_REPO}:rolling_no_dependencies
187-
docker push ${DOCKERHUB_REPO}:rolling
188-
189-
test_env.up:
190-
env | grep GITHUB > .testenv; true
191-
TIMESERIES_ENABLED=${TIMESERIES_ENABLED} docker-compose up -d
192-
193-
test_env.prepare:
194-
docker-compose exec api make test_env.container_prepare
195-
196-
test_env.check_db:
197-
docker-compose exec umbrella make test_env.container_check_db
198-
make test_env.check-for-migration-conflicts
199-
200-
test_env.install_cli:
201-
pip install codecov-cli==$(CODECOV_CLI_VERSION)
202-
203-
test_env.container_prepare:
204-
apt-get -y install git build-essential netcat-traditional
205-
make test_env.install_cli
206-
git config --global --add safe.directory /app
207-
208-
test_env.container_check_db:
209-
while ! nc -vz postgres 5432; do sleep 1; echo "waiting for postgres"; done
210-
while ! nc -vz timescale 5432; do sleep 1; echo "waiting for timescale"; done
211-
212-
test_env.run_unit:
213-
docker-compose exec umbrella make test.unit
214-
215-
test_env.run_integration:
216-
#docker-compose exec umbrella make test.integration
217-
echo "Skipping. No Tests"
218-
219-
test_env.check-for-migration-conflicts:
220-
docker-compose exec umbrella python manage.py check_for_migration_conflicts
221-
222-
test_env.upload:
223-
docker-compose exec umbrella make test_env.container_upload CODECOV_UPLOAD_TOKEN=${CODECOV_UPLOAD_TOKEN} CODECOV_URL=${CODECOV_URL}
224-
docker-compose exec umbrella make test_env.container_upload_test_results CODECOV_UPLOAD_TOKEN=${CODECOV_UPLOAD_TOKEN} CODECOV_URL=${CODECOV_URL}
225-
226-
test_env.container_upload:
227-
codecovcli -u ${CODECOV_URL} upload-process --flag unit-latest-uploader --flag unit \
228-
--coverage-files-search-exclude-folder=graphql_api/types/** \
229-
--coverage-files-search-exclude-folder=api/internal/tests/unit/views/cassetes/**
230-
231-
test_env.container_upload_test_results:
232-
codecovcli -u ${CODECOV_URL} do-upload --report-type "test_results" \
233-
--files-search-exclude-folder=graphql_api/types/** \
234-
--files-search-exclude-folder=api/internal/tests/unit/views/cassetes/** || true
235-
236-
test_env:
237-
make test_env.up
238-
make test_env.prepare
239-
make test_env.check_db
240-
make test_env.run_unit
241-
make test_env.check-for-migration-conflicts
242-
243-
244-
### START Proxy Commands
245-
.PHONY: proxy.build
246-
proxy.build: # Used to build the proxy
247-
proxy.build:
248-
docker build -f docker/Dockerfile-proxy . -t ${API_DOCKER_REPO}/proxy:latest -t ${API_DOCKER_REPO}/proxy:${release_version}-${sha} \
249-
--label "org.label-schema.build-date"="$(build_date)" \
250-
--label "org.label-schema.name"="API Proxy" \
251-
--label "org.label-schema.vendor"="api" \
252-
--label "org.label-schema.version"="${release_version}"
253-
254-
.PHONY: proxy.run
255-
proxy.run: # Used to run the proxy
256-
proxy.run:
257-
make proxy.build
258-
make proxy.down
259-
docker run --rm --network ${PROXY_NETWORK} -e FRP_TOKEN=${FRP_TOKEN} -e DOMAIN=${API_DOMAIN} --name api-proxy ${API_DOCKER_REPO}/proxy:latest
260-
sleep 3
261-
make proxy.logs
262-
# You should see "[api] start proxy success"
263-
# If no logs then proxy failed to start. Check if you are on VPN. If you get a 404, check if you are on VPN
264-
265-
.PHONY: proxy.logs
266-
proxy.logs: # Used to logs the proxy
267-
proxy.logs:
268-
docker logs api-proxy
269-
270-
.PHONY: proxy.shell
271-
proxy.shell: # Used to shell the proxy
272-
proxy.shell:
273-
docker exec -it api-proxy sh
274-
275-
.PHONY: proxy.down
276-
proxy.down: # Used to down the proxy
277-
proxy.down:
278-
docker kill api-proxy || true
279-
280-
### END PROXY Commands
19+
-f docker/Dockerfile.requirements . \
20+
--build-arg APP_DIR=${APP_DIR} \
21+
-t ${AR_REPO}:${REQUIREMENTS_TAG} \
22+
-t ${CI_REQS_REPO}:${REQUIREMENTS_TAG}
23+
24+
######
25+
# codecov-api targets
26+
######
27+
API_UV_LOCK_SHA := $(shell sha1sum apps/codecov-api/uv.lock | head -c 40)
28+
API_REQS_TAG := reqs-${API_UV_LOCK_SHA}-${DOCKER_REQS_SHA}-${SHARED_SHA}
29+
30+
define api_rule_prefix
31+
.PHONY: $(1)
32+
$(1): export APP_DIR := apps/codecov-api
33+
$(1): export REQUIREMENTS_TAG := ${API_REQS_TAG}
34+
$(1): export AR_REPO ?= codecov/api-umbrella
35+
$(1): export DOCKERHUB_REPO ?= codecov/self-hosted-api-umbrella
36+
$(1): export CI_REQS_REPO ?= codecov/api-ci-requirements
37+
endef
38+
39+
# umbrella builds a special requirements image for api that installs shared properly.
40+
$(eval $(call api_rule_prefix,api.build.requirements))
41+
api.build.requirements:
42+
$(MAKE) _build.requirements
43+
44+
# This target calls `make build.requirements` for api so we have to make sure it calls our
45+
# custom `build.requirements` instead.
46+
$(eval $(call api_rule_prefix,api.build))
47+
api.build:
48+
$(MAKE) api.build.requirements
49+
$(MAKE) -C apps/codecov-api build.local
50+
51+
# Any other target starting with `api.` should be forwarded to `apps/codecov-api`.
52+
# The `$*` variable is the string caught by the `%` in the rule pattern.
53+
$(eval $(call api_rule_prefix,api.%))
54+
api.%:
55+
$(MAKE) -C apps/codecov-api $*
56+
57+
######
58+
# worker targets
59+
######
60+
WORKER_UV_LOCK_SHA := $(shell sha1sum apps/worker/uv.lock | head -c 40)
61+
WORKER_REQS_TAG := reqs-${WORKER_UV_LOCK_SHA}-${DOCKER_REQS_SHA}-${SHARED_SHA}
62+
63+
define worker_rule_prefix
64+
.PHONY: $(1)
65+
$(1): export APP_DIR := apps/worker
66+
$(1): export REQUIREMENTS_TAG := ${WORKER_REQS_TAG}
67+
$(1): export AR_REPO ?= codecov/worker-umbrella
68+
$(1): export DOCKERHUB_REPO ?= codecov/self-hosted-worker-umbrella
69+
$(1): export CI_REQS_REPO ?= codecov/worker-ci-requirements
70+
endef
71+
72+
# umbrella builds a special requirements image for worker that installs shared properly.
73+
$(eval $(call worker_rule_prefix,worker.build.requirements))
74+
worker.build.requirements:
75+
$(MAKE) _build.requirements
76+
77+
# This target calls `make build.requirements` for worker so we have to make sure it calls our
78+
# custom `build.requirements` instead.
79+
$(eval $(call worker_rule_prefix,worker.build))
80+
worker.build:
81+
$(MAKE) worker.build.requirements
82+
$(MAKE) -C apps/worker build.local
83+
84+
# Any other target starting with `worker.` should be forwarded to `apps/worker`.
85+
# The `$*` variable is the string caught by the `%` in the rule pattern.
86+
$(eval $(call worker_rule_prefix,worker.%))
87+
worker.%:
88+
$(MAKE) -C apps/worker $*
89+
90+
######
91+
# shared targets
92+
######
93+
94+
# No need to override any of shared's targets. Just run make in `libs/shared`.
95+
.PHONY: shared.%
96+
shared.%:
97+
$(MAKE) -C libs/shared $*
98+
99+
######
100+
# Development environment targets
101+
######
102+
include tools/devenv/Makefile.devenv

apps/codecov-api

Submodule codecov-api updated 55 files

apps/worker

Submodule worker updated 43 files

0 commit comments

Comments
 (0)