Skip to content

Commit 657a2ee

Browse files
authored
Merge pull request #7107 from BitGo/VL-3498-remove-hardcoded-docker-labels
fix(express): remove hardcoded dockerfile labels
2 parents 8cb0f2a + 69e6314 commit 657a2ee

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,9 @@ jobs:
270270
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
271271
with:
272272
ref: ${{ github.event.pull_request.head.sha }}
273+
274+
- name: Setup Docker compatibility with Podman
275+
run: sudo ln -sf /usr/bin/podman /usr/local/bin/docker
276+
273277
- name: Build BitGoJS Express Docker Image
274-
run: podman build .
278+
run: ./scripts/build-docker-express.sh

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,13 @@ RUN cd /var/bitgo-express && \
333333
yarn link @bitgo/sdk-coin-zec
334334
#LINK_END
335335

336-
#LABEL_START
337-
LABEL created="Thu, 04 Sep 2025 18:59:30 GMT"
338-
LABEL version=15.0.0
339-
LABEL git_hash=bbdf6e60b720b25e3212f3a4c5bdc81732a505e8
340-
#LABEL_END
336+
ARG BUILD_DATE
337+
ARG VERSION
338+
ARG GIT_HASH
339+
340+
LABEL created=${BUILD_DATE}
341+
LABEL version=${VERSION}
342+
LABEL git_hash=${GIT_HASH}
341343

342344
USER node
343345
ENV NODE_ENV=production

modules/express/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"upload-artifacts": "node scripts/upload-test-reports.js",
3131
"start": "node bin/bitgo-express",
3232
"update-bitgo": "bash ./scripts/update-bitgo.sh",
33-
"build-docker": "podman build -f ../../Dockerfile --platform=linux/amd64 -t bitgo/express:latest -t bitgo/express:$(jq -r .version < package.json) ../..",
34-
"push-docker": "podman push bitgo/express:latest bitgo/express:$(jq -r .version < package.json)",
33+
"build-docker": "cd ../../ && yarn update-dockerfile && ./scripts/build-docker-express.sh",
3534
"check-fmt": "yarn prettier --check '{src,test}/**/*.{ts,js,json}'",
3635
"unprettied": "grep -R -L --include '*.ts' --include '*.js' --include '*.json' '@prettier' src test",
3736
"fmt": "yarn prettier --write '{src,test}/**/*.{ts,js,json}'"

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@
130130
"dev": "tsc -b ./tsconfig.packages.json -w",
131131
"prepare": "husky install",
132132
"sdk-coin:new": "yo ./scripts/sdk-coin-generator",
133-
"build-docker-express": "yarn update-dockerfile && podman build --platform=linux/amd64 -t bitgo/express:latest -t bitgo/express:$(jq -r .version < modules/express/package.json) .",
134-
"push-docker-express": "podman push bitgo/express:latest && podman push bitgo/express:$(jq -r .version < modules/express/package.json)",
133+
"build-docker-express": "yarn update-dockerfile && ./scripts/build-docker-express.sh",
135134
"update-dockerfile": "tsx scripts/update-dockerfile.ts",
136135
"precommit": "lint-staged",
137136
"lint-fix": "lerna run lint --parallel -- --fix",

scripts/build-docker-express.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Get dynamic build arguments
6+
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
7+
VERSION=$(jq -r .version < modules/express/package.json)
8+
GIT_HASH=$(git rev-parse HEAD)
9+
10+
echo "Building Docker image with:"
11+
echo " BUILD_DATE: $BUILD_DATE"
12+
echo " VERSION: $VERSION"
13+
echo " GIT_HASH: $GIT_HASH"
14+
15+
# Build the Docker image
16+
docker build \
17+
--platform=linux/amd64 \
18+
--build-arg BUILD_DATE="$BUILD_DATE" \
19+
--build-arg VERSION="$VERSION" \
20+
--build-arg GIT_HASH="$GIT_HASH" \
21+
-t bitgo/express:latest \
22+
-t bitgo/express:"$VERSION" \
23+
.
24+
25+
echo "Docker build completed successfully!"

scripts/update-dockerfile.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,9 @@ async function updateDockerFile(lerna) {
7272
.join(' && \\\n');
7373
const linkContent = `RUN cd /var/bitgo-express && \\\n${linkers}\n`;
7474

75-
// add metadata about the build to docker labels
76-
let labelContent = `LABEL created="${new Date().toUTCString()}"\n`; // add created timestamp;
77-
labelContent += `LABEL version=${require('../modules/express/package.json').version}\n`; // set current image version from express
78-
labelContent += `LABEL git_hash=${require('child_process').execSync(`git rev-parse HEAD`).toString().trim()}\n`; // set to latest git HEAD hash
79-
8075
dockerContents = dockerContents
8176
.replace(/#COPY_START((.|\n)*)#COPY_END/, `#COPY_START\n${copyContent}#COPY_END`)
82-
.replace(/#LINK_START((.|\n)*)#LINK_END/, `#LINK_START\n${linkContent}#LINK_END`)
83-
.replace(/#LABEL_START((.|\n)*)#LABEL_END/, `#LABEL_START\n${labelContent}#LABEL_END`);
77+
.replace(/#LINK_START((.|\n)*)#LINK_END/, `#LINK_START\n${linkContent}#LINK_END`);
8478

8579
fs.writeFileSync('Dockerfile', dockerContents);
8680
}

0 commit comments

Comments
 (0)