Skip to content

Commit 4d38fe5

Browse files
committed
AG-53807: Add docker build to ecsstree
Squashed commit of the following: commit 3bf566e Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Wed May 27 15:56:04 2026 +0300 chore: re-enable vcs tagging task commit 9ab0cf9 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Wed May 27 15:44:45 2026 +0300 chore: disable vcs tagging task for manual testing commit 9800c71 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Wed May 27 15:40:57 2026 +0300 fix: align .dockerignore with other repos, restore dockerNode variable in increment.yaml commit ca83313 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Wed May 27 15:21:41 2026 +0300 fix: add .dockerignore to prevent .git and node_modules from polluting build context commit e92dfc2 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Wed May 27 15:06:51 2026 +0300 AG-53807: Add docker build to ecsstree
1 parent 36bbb39 commit 4d38fe5

6 files changed

Lines changed: 257 additions & 78 deletions

File tree

.dockerignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Version control
2+
.git
3+
4+
# IDE and editor files
5+
.idea
6+
.vscode
7+
.DS_Store
8+
9+
# Build caches
10+
.eslintcache
11+
*.tsbuildinfo
12+
13+
# Build outputs
14+
build/
15+
output/
16+
17+
# Dependencies
18+
node_modules/
19+
20+
# Docker files
21+
Dockerfile*
22+
23+
# Logs
24+
*.log
25+
26+
# Test coverage
27+
coverage/
28+
29+
# Built output (rebuilt inside Docker)
30+
dist/

Dockerfile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
FROM adguard/node-ssh:22.22--0 AS base
2+
SHELL ["/bin/bash", "-lc"]
3+
4+
RUN npm install -g pnpm@10.7.1
5+
6+
WORKDIR /ecsstree
7+
8+
ENV npm_config_store_dir=/pnpm-store
9+
10+
# ============================================================================
11+
# Stage: deps
12+
# Cached until package.json/pnpm-lock.yaml changes
13+
# ============================================================================
14+
FROM base AS deps
15+
16+
COPY package.json pnpm-lock.yaml ./
17+
18+
# --ignore-scripts: package.json has "prepare": "node .husky/install.js" which
19+
# must not run in CI (requires git hooks setup).
20+
RUN --mount=type=cache,target=/pnpm-store,id=ecsstree-pnpm \
21+
pnpm install --frozen-lockfile --ignore-scripts
22+
23+
# ============================================================================
24+
# Stage: source
25+
# Full source copy — parent for all lint/test/build stages
26+
# ============================================================================
27+
FROM deps AS source
28+
29+
COPY . /ecsstree
30+
31+
# ============================================================================
32+
# Stage: lint
33+
# Runs ESLint and markdownlint
34+
# ============================================================================
35+
FROM source AS lint
36+
37+
ARG BUILD_RUN_ID=""
38+
39+
RUN --mount=type=cache,target=/pnpm-store,id=ecsstree-pnpm \
40+
echo "${BUILD_RUN_ID}" > /tmp/.build-run-id && \
41+
mkdir -p /out && \
42+
touch /out/lint.txt && \
43+
pnpm lint
44+
45+
FROM scratch AS lint-output
46+
COPY --from=lint /out/ /
47+
48+
# ============================================================================
49+
# Stage: test
50+
# Runs vitest
51+
# Always exits 0 — exit code stored in /out/exit-code.txt for Bamboo to check
52+
# ============================================================================
53+
FROM source AS test
54+
55+
ARG BUILD_RUN_ID=""
56+
57+
RUN --mount=type=cache,target=/pnpm-store,id=ecsstree-pnpm \
58+
echo "${BUILD_RUN_ID}" > /tmp/.build-run-id && \
59+
mkdir -p /out && \
60+
pnpm test; echo $? > /out/exit-code.txt
61+
62+
FROM scratch AS test-output
63+
COPY --from=test /out/ /
64+
65+
# ============================================================================
66+
# Stage: build
67+
# Creates the library build, runs smoke tests, packs .tgz for npm publish,
68+
# and exports build.txt for Bamboo variable injection
69+
# ============================================================================
70+
FROM source AS build
71+
72+
ARG BUILD_RUN_ID=""
73+
74+
RUN --mount=type=cache,target=/pnpm-store,id=ecsstree-pnpm \
75+
echo "${BUILD_RUN_ID}" > /tmp/.build-run-id && \
76+
pnpm build && \
77+
pnpm test:smoke && \
78+
pnpm pack --out ecsstree.tgz && \
79+
mkdir -p /out/artifacts && \
80+
mv ecsstree.tgz /out/artifacts/ && \
81+
cp build.txt /out/artifacts/
82+
83+
FROM scratch AS build-output
84+
COPY --from=build /out/ /

bamboo-specs/build.yaml

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ plan:
44
project-key: AJL
55
key: ECSSTREEBUILD
66
name: ECSSTree - build release
7-
variables:
8-
dockerNode: adguard/node-ssh:22.14--0
97

108
stages:
119
- Build:
@@ -18,49 +16,29 @@ Build:
1816
key: BUILD
1917
other:
2018
clean-working-dir: true
21-
docker:
22-
image: ${bamboo.dockerNode}
23-
volumes:
24-
${system.PNPM_DIR}: "${bamboo.cachePnpm}"
2519
tasks:
2620
- checkout:
2721
force-clean-build: true
2822
- script:
2923
interpreter: SHELL
3024
scripts:
3125
- |-
32-
set -e
33-
set -x
26+
set -ex
3427
3528
# Fix mixed logs
3629
exec 2>&1
3730
38-
ls -laht
31+
export DOCKER_BUILDKIT=1
3932
40-
# Set cache directory
41-
pnpm config set store-dir ${bamboo.cachePnpm}
42-
43-
# Install dependencies
44-
pnpm install
45-
46-
# Lint code
47-
pnpm lint
48-
49-
# Run tests
50-
pnpm test
51-
52-
# Create build, this will also create build.txt file with build number
53-
pnpm build
54-
55-
# Run smoke tests
56-
pnpm test:smoke
57-
58-
# Pack build into tarball
59-
pnpm pack --out ecsstree.tgz
60-
61-
ls -laht
33+
docker build \
34+
--file Dockerfile \
35+
--progress plain \
36+
--build-arg BUILD_RUN_ID=${bamboo.buildNumber} \
37+
--target build-output \
38+
--output type=local,dest=output \
39+
.
6240
- inject-variables:
63-
file: build.txt
41+
file: output/artifacts/build.txt
6442
scope: RESULT
6543
namespace: inject
6644
- any-task:
@@ -72,20 +50,10 @@ Build:
7250
- script:
7351
interpreter: SHELL
7452
scripts:
75-
- |-
76-
set -x
77-
set -e
78-
79-
# Fix mixed logs
80-
exec 2>&1
81-
82-
ls -la
83-
84-
echo "Size before cleanup:" && du -h | tail -n 1
85-
rm -rf node_modules dist
86-
echo "Size after cleanup:" && du -h | tail -n 1
53+
- "./bamboo-specs/scripts/cleanup.sh output/artifacts/ecsstree.tgz"
8754
artifacts:
8855
- name: ecsstree.tgz
56+
location: output/artifacts
8957
pattern: ecsstree.tgz
9058
shared: true
9159
required: true

bamboo-specs/increment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plan:
55
key: ECSSTREEINCR
66
name: ECSSTree - increment
77
variables:
8-
dockerNode: adguard/node-ssh:22.14--0
8+
dockerNode: adguard/node-ssh:22.22--0
99

1010
stages:
1111
- Increment:

bamboo-specs/scripts/cleanup.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# Cleanup script that preserves specified artifacts
4+
# Usage: ./cleanup.sh "artifact1,artifact2,artifact3"
5+
6+
# 'set' should be added to the beginning of each script to ensure that it runs with the correct options.
7+
# Please do not move it to some common file, like `setup-tests.sh`, because sourcing A script from B script
8+
# cannot change the options of B script.
9+
# -e: Exit immediately if any command exits with a non-zero status (i.e., if a command fails).
10+
# -x: Print each command to the terminal as it is executed, which is useful for debugging.
11+
set -ex
12+
13+
# Fix mixed logs
14+
exec 2>&1
15+
16+
echo "Size before cleanup:" && du -h | tail -n 1
17+
echo "Top 5 files:" && du -h | sort -hr | head -n 5
18+
19+
# Parse artifacts from command line argument
20+
ARTIFACTS_ARG="${1:-}"
21+
if [ -z "$ARTIFACTS_ARG" ]; then
22+
echo "No artifacts specified, cleaning entire workspace"
23+
ARTIFACTS=()
24+
else
25+
IFS=',' read -ra ARTIFACTS <<< "$ARTIFACTS_ARG"
26+
echo "Preserving artifacts: ${ARTIFACTS[*]}"
27+
fi
28+
29+
TMP="$(mktemp -d)"
30+
trap 'rm -rf "$TMP"' EXIT
31+
32+
# Stash artifacts to /tmp
33+
for f in "${ARTIFACTS[@]}"; do
34+
[ -e "$f" ] || continue
35+
echo "Stashing artifact: $f"
36+
mkdir -p "$TMP/$(dirname "$f")"
37+
mv "$f" "$TMP/$f"
38+
done
39+
40+
# Clean entire workspace (including dotfiles and .git)
41+
find . -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +
42+
43+
# Restore artifacts
44+
for f in "${ARTIFACTS[@]}"; do
45+
[ -e "$TMP/$f" ] || continue
46+
echo "Restoring artifact: $f"
47+
mkdir -p "$(dirname "$f")"
48+
mv "$TMP/$f" "$f"
49+
done
50+
51+
echo "Size after cleanup:" && du -h | tail -n 1
52+
echo "Top 5 files:" && du -h | sort -hr | head -n 5
53+
54+
echo "Cleanup completed successfully"

0 commit comments

Comments
 (0)