Skip to content

Commit 8f31632

Browse files
committed
Pull request: ADG-11407-add-docker-ci
Merge in GO/dnsproxy from ADG-11407-add-docker-ci to master Squashed commit of the following: commit 790aa19 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Feb 3 10:27:51 2026 +0700 all: imp ci scripts commit 3c7c067 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Feb 3 10:18:17 2026 +0700 all: imp ci scripts commit 69f1a72 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Feb 3 09:48:30 2026 +0700 all: imp ci scripts commit d069cb8 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Feb 2 13:19:47 2026 +0700 docker: fix commit b887754 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Feb 2 13:17:53 2026 +0700 docker: imp commit 579fcdb Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Feb 2 13:09:50 2026 +0700 docker: imp commit 733ad0a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Feb 2 13:02:04 2026 +0700 docker: imp commit 11bb703 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Feb 2 11:03:07 2026 +0700 docker: imp commit 171cfce Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Jan 30 11:59:25 2026 +0700 all: add docker ci commit 8697e0a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Jan 30 11:56:50 2026 +0700 all: add docker ci
1 parent 52b04fa commit 8f31632

File tree

8 files changed

+238
-86
lines changed

8 files changed

+238
-86
lines changed

.github/workflows/docker.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
'key': "${{ runner.os }}-go-${{ hashFiles('go.sum') }}"
3131
'restore-keys': '${{ runner.os }}-go-'
3232
- 'name': 'Set up QEMU'
33-
'uses': 'docker/setup-qemu-action@v1'
33+
'uses': 'docker/setup-qemu-action@v3'
3434
- 'name': 'Set up Docker Buildx'
35-
'uses': 'docker/setup-buildx-action@v1'
35+
'uses': 'docker/setup-buildx-action@v3'
36+
'with':
37+
'install': true'
3638
- 'name': 'Publish to Docker Hub'
3739
'env':
3840
'DOCKER_USER': ${{ secrets.DOCKER_USER }}
@@ -51,7 +53,7 @@
5153
make \
5254
VERSION="${RELEASE_VERSION}" \
5355
DOCKER_IMAGE_NAME="adguard/dnsproxy" \
54-
DOCKER_OUTPUT="type=image,name=adguard/dnsproxy,push=true" \
56+
DOCKER_PUSH="1" \
5557
VERBOSE="1" \
5658
docker
5759

bamboo-specs/bamboo.yaml

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
'key': 'DNSPROXY'
66
'name': 'dnsproxy - Build and run tests'
77
'variables':
8+
# This variable is used to override Docker caching, for example to rerun a
9+
# flaky test suite.
10+
'cacheBuster': '0'
811
'dockerFpm': 'alanfranz/fpm-within-docker:ubuntu-bionic'
912
# When there is a patch release of Go available, set this property to an
1013
# exact patch version as opposed to a minor one to make sure that this exact
@@ -15,48 +18,13 @@
1518
'name': 'dnsproxy'
1619

1720
'stages':
18-
# TODO(e.burkov): Add separate lint stage for texts.
19-
- 'Lint':
20-
'manual': false
21-
'final': false
22-
'jobs':
23-
- 'Lint'
2421
- 'Test':
2522
'manual': false
2623
'final': false
2724
'jobs':
2825
- 'Test'
2926

30-
'Lint':
31-
'docker':
32-
'image': '${bamboo.dockerGo}'
33-
'volumes':
34-
'${system.GO_CACHE_DIR}': '${bamboo.cacheGo}'
35-
'${system.GO_PKG_CACHE_DIR}': '${bamboo.cacheGoPkg}'
36-
'key': 'LINT'
37-
'other':
38-
'clean-working-dir': true
39-
'requirements':
40-
- 'adg-docker': true
41-
'tasks':
42-
- 'checkout':
43-
'force-clean-build': true
44-
- 'script':
45-
'interpreter': 'SHELL'
46-
'scripts':
47-
- |
48-
#!/bin/sh
49-
50-
set -e -f -u -x
51-
52-
make VERBOSE=1 GOMAXPROCS=1 go-tools go-lint
53-
5427
'Test':
55-
'docker':
56-
'image': '${bamboo.dockerGo}'
57-
'volumes':
58-
'${system.GO_CACHE_DIR}': '${bamboo.cacheGo}'
59-
'${system.GO_PKG_CACHE_DIR}': '${bamboo.cacheGoPkg}'
6028
'final-tasks':
6129
- 'test-parser':
6230
# The default pattern, '**/test-reports/*.xml', works, so don't set
@@ -67,8 +35,6 @@
6735
'key': 'TEST'
6836
'other':
6937
'clean-working-dir': true
70-
'requirements':
71-
- 'adg-docker': true
7238
'tasks':
7339
- 'checkout':
7440
'force-clean-build': true
@@ -82,18 +48,21 @@
8248
8349
set -e -f -u -x
8450
85-
make \
86-
GOMAXPROCS=1 \
87-
VERBOSE=1 \
88-
go-deps go-tools
51+
docker info
52+
53+
docker build \
54+
--build-arg "BASE_IMAGE=${bamboo_dockerGo}" \
55+
--build-arg "CACHE_BUSTER=${bamboo_cacheBuster}" \
56+
--output '.' \
57+
--progress 'plain' \
58+
--target 'tester-exporter' \
59+
-f ./docker/ci.Dockerfile \
60+
.
8961
90-
make \
91-
TEST_REPORTS_DIR="./test-reports/" \
92-
VERBOSE=1 \
93-
go-test \
94-
;
62+
exit_code="$(cat ./test-reports/test-exit-code.txt)"
63+
readonly exit_code
9564
96-
exit "$(cat ./test-reports/test-exit-code.txt)"
65+
exit "$exit_code"
9766
9867
'branches':
9968
'create': 'for-pull-request'
File renamed without changes.

docker/ci.Dockerfile

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# This comment is used to simplify checking local copies of the Dockerfile.
4+
# Bump this number every time a significant change is made to this Dockerfile.
5+
#
6+
# AdGuard-Project-Version: 10
7+
8+
# Dockerfile guidelines:
9+
#
10+
# 1. Make sure that Docker correctly caches layers, on a second build attempt it
11+
# must not run lint / test second time when it's not required.
12+
#
13+
# 2. Use BuildKit to improve the build performance (--mount=type=cache, etc).
14+
#
15+
# 3. Prefer using ARG instead of ENV when appropriate, as ARG does not create a
16+
# layer in the final image. However, be careful with what you use ARG for.
17+
# Also, prefer to give ARGs sensible default values.
18+
#
19+
# 4. Use --output and the export stage if you need to get any output on the host
20+
# machine.
21+
#
22+
# NOTE: Only use --output with FROM scratch.
23+
#
24+
# 5. Use .dockerignore to prevent unnecessary files from being sent to the
25+
# Docker daemon, which can invalidate the cache.
26+
#
27+
# 6. Add a CACHE_BUSTER argument to stages to be able to rerun the stages if
28+
# needed. Keep it in sync with bamboo-specs/bamboo.yaml.
29+
30+
# NOTE: Keep in sync with bamboo-specs/bamboo.yaml.
31+
ARG BASE_IMAGE=adguard/go-builder:1.25.5--1
32+
33+
# The dependencies stage is needed to install packages and tool dependencies.
34+
# This is also where binaries like osslsigncode, which may be required for tests
35+
# in some projects, must be installed.
36+
#
37+
# Use fake BRANCH and REVISION values to both prevent git calls and also not
38+
# ruin the caching with ARGs.
39+
#
40+
# NOTE: Only ADD the files required to install the dependencies.
41+
FROM "$BASE_IMAGE" AS dependencies
42+
RUN ls -la .
43+
ADD Makefile go.mod go.sum /app/
44+
ADD scripts /app/scripts
45+
WORKDIR /app
46+
RUN \
47+
--mount=type=cache,id=gocache,target=/root/.cache/go-build \
48+
--mount=type=cache,id=gopath,target=/go \
49+
<<-'EOF'
50+
set -e -f -u -x
51+
make \
52+
BRANCH='master' \
53+
REVISION='0000000000000000000000000000000000000000' \
54+
VERBOSE=1 \
55+
go-env \
56+
go-deps \
57+
go-tools \
58+
;
59+
EOF
60+
61+
# The linter stage is separated from the tester stage to make catching test
62+
# failures easier.
63+
#
64+
# Use fake BRANCH and REVISION values to both prevent git calls and also not
65+
# ruin the caching with ARGs. IGNORE_NON_REPRODUCIBLE is set to 1 to make this
66+
# stage reproducible even when linters that query external sources fail.
67+
FROM dependencies AS linter
68+
ADD . /app
69+
WORKDIR /app
70+
RUN \
71+
--mount=type=cache,id=gocache,target=/root/.cache/go-build \
72+
--mount=type=cache,id=gopath,target=/go \
73+
<<-'EOF'
74+
set -e -f -u -x
75+
export GOMAXPROCS=2
76+
make \
77+
BRANCH='master' \
78+
IGNORE_NON_REPRODUCIBLE='1' \
79+
REVISION='0000000000000000000000000000000000000000' \
80+
VERBOSE=1 \
81+
go-lint \
82+
md-lint \
83+
sh-lint \
84+
txt-lint \
85+
;
86+
EOF
87+
88+
# The test stage. TEST_REPORTS_DIR is set to create JUnit reports for the
89+
# tester-exporter stage; run with --build-arg TEST_REPORTS_DIR='' if you don't
90+
# need them on your machine.
91+
#
92+
# Use fake BRANCH and REVISION values to both prevent git calls and also not
93+
# ruin the caching with ARGs.
94+
#
95+
# To run the tests:
96+
#
97+
# docker build --target tester -t 'app' .
98+
#
99+
# Projects that have go-bench and/or go-fuzz targets should add them here as
100+
# well.
101+
FROM linter AS tester
102+
ARG CACHE_BUSTER=0
103+
ARG TEST_REPORTS_DIR=/test-reports
104+
RUN \
105+
--mount=type=cache,id=gocache,target=/root/.cache/go-build \
106+
--mount=type=cache,id=gopath,target=/go \
107+
<<-'EOF'
108+
set -e -f -u -x
109+
export GOMAXPROCS=1
110+
111+
make \
112+
BRANCH='master' \
113+
REVISION='0000000000000000000000000000000000000000' \
114+
TEST_REPORTS_DIR="$TEST_REPORTS_DIR" \
115+
VERBOSE=1 \
116+
go-test \
117+
;
118+
119+
exit_code="$(cat "${TEST_REPORTS_DIR}/test-exit-code.txt")"
120+
readonly exit_code
121+
122+
# TODO(d.kolyshev): Run go-fuzz and go-bench.
123+
124+
exit "$exit_code"
125+
EOF
126+
127+
# tester-exporter exports the test result to the host machine so that it could
128+
# parse and analyze it. This stage should only used in a CI.
129+
#
130+
# It the file test-report.xml, which contains test results in the JUnit format.
131+
#
132+
# Run the following command to export the test result:
133+
#
134+
# docker build \
135+
# --output . \
136+
# --progress plain \
137+
# --target tester-exporter \
138+
# .
139+
FROM scratch AS tester-exporter
140+
ARG CACHE_BUSTER=0
141+
ARG TEST_REPORTS_DIR=/test-reports
142+
COPY --from=tester "$TEST_REPORTS_DIR" "$TEST_REPORTS_DIR"

docker/ci.Dockerfile.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This comment is used to simplify checking local copies of the file. Bump this
2+
# number every time a significant change is made to this file.
3+
#
4+
# AdGuard-Project-Version: 2
5+
.git
6+
/bin/
7+
/tmp/

scripts/make/build-docker.sh

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/bin/sh
22

3+
# TODO(a.garipov): Improve arguments handling.
4+
35
verbose="${VERBOSE:-0}"
46

57
if [ "$verbose" -gt '0' ]; then
68
set -x
7-
debug_flags='--debug=1'
89
else
910
set +x
10-
debug_flags='--debug=0'
1111
fi
12-
readonly debug_flags
1312

1413
set -e -f -u
1514

@@ -40,15 +39,9 @@ readonly build_date
4039
docker_image_name="${DOCKER_IMAGE_NAME:-dnsproxy-dev}"
4140
readonly docker_image_name
4241

43-
# Set DOCKER_OUTPUT to 'type=image,name=adguard/dnsproxy,push=true' if you
44-
# want (and are allowed) to push to DockerHub.
45-
#
46-
# If you want to inspect the resulting image using commands like "docker image
47-
# ls", change type to docker and also set docker_platforms to a single platform.
48-
#
49-
# See https://github.com/docker/buildx/issues/166.
50-
docker_output="${DOCKER_OUTPUT:-type=image,name=${docker_image_name},push=false}"
51-
readonly docker_output
42+
# Set DOCKER_PUSH to '1' if you want (and are allowed) to push to DockerHub.
43+
docker_push="${DOCKER_PUSH:-0}"
44+
readonly docker_push
5245

5346
docker_version_tag="--tag=${docker_image_name}:${version}"
5447
docker_channel_tag="--tag=${docker_image_name}:latest"
@@ -63,7 +56,7 @@ readonly docker_version_tag docker_channel_tag
6356

6457
# Copy the binaries into a new directory under new names, so that it's easier to
6558
# COPY them later. DO NOT remove the trailing underscores. See file
66-
# docker/Dockerfile.
59+
# docker/build.Dockerfile.
6760
dist_docker="${dist_dir}/docker"
6861
readonly dist_docker
6962

@@ -84,24 +77,50 @@ cp "${dist_dir}/linux-ppc64le/dnsproxy" \
8477
# Prepare the default configuration for the Docker image.
8578
cp ./config.yaml.dist "${dist_docker}/config.yaml"
8679

87-
# Don't use quotes with $docker_version_tag and $docker_channel_tag, because we
88-
# want word splitting and or an empty space if tags are empty.
89-
#
90-
# TODO(a.garipov): Once flag --tag of docker buildx build supports commas, use
91-
# them instead.
92-
#
93-
# shellcheck disable=SC2086
94-
$sudo_cmd docker \
95-
"$debug_flags" \
96-
buildx build \
97-
--build-arg BUILD_DATE="$build_date" \
98-
--build-arg DIST_DIR="$dist_dir" \
99-
--build-arg VCS_REF="$commit" \
100-
--build-arg VERSION="$version" \
101-
--output "$docker_output" \
102-
--platform "$docker_platforms" \
103-
$docker_version_tag \
104-
$docker_channel_tag \
105-
-f ./docker/Dockerfile \
106-
. \
107-
;
80+
# docker_build_opt_tag is a function that wraps the call of docker build command
81+
# with optionally --tag flags.
82+
docker_build_opt_tag() {
83+
if [ "$sudo_cmd" != '' ]; then
84+
set -- "$sudo_cmd"
85+
fi
86+
87+
# Set the initial parameters.
88+
set -- \
89+
"$@" \
90+
docker \
91+
buildx \
92+
build \
93+
--build-arg BUILD_DATE="$build_date" \
94+
--build-arg DIST_DIR="$dist_dir" \
95+
--build-arg VCS_REF="$commit" \
96+
--build-arg VERSION="$version" \
97+
--platform "$docker_platforms" \
98+
--progress 'plain' \
99+
;
100+
101+
# Append the channel tag, if any.
102+
if [ "$docker_channel_tag" != '' ]; then
103+
set -- "$@" "$docker_channel_tag"
104+
fi
105+
106+
# Append the version tag.
107+
set -- "$@" "$docker_version_tag"
108+
109+
# Push to DockerHub, if requested.
110+
if [ "$docker_push" -eq 1 ]; then
111+
set -- "$@" '--push'
112+
fi
113+
114+
# Append the rest.
115+
set -- \
116+
"$@" \
117+
-f \
118+
./docker/build.Dockerfile \
119+
. \
120+
;
121+
122+
# Call the command with the assembled parameters.
123+
"$@"
124+
}
125+
126+
docker_build_opt_tag

0 commit comments

Comments
 (0)