Skip to content

Commit 85d63c1

Browse files
authored
Merge pull request #321 from docker/update-go-workflow
ci: update-go workflow to keep go version in sync
2 parents fb4bcbd + f82a333 commit 85d63c1

File tree

4 files changed

+175
-30
lines changed

4 files changed

+175
-30
lines changed

.github/workflows/.pkgs.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# reusable workflow
2+
name: .pkgs
3+
4+
on:
5+
workflow_call:
6+
outputs:
7+
list:
8+
description: List of packages as JSON array
9+
value: ${{ jobs.run.outputs.pkgs }}
10+
11+
jobs:
12+
run:
13+
runs-on: ubuntu-24.04
14+
outputs:
15+
pkgs: ${{ steps.set.outputs.pkgs }}
16+
steps:
17+
-
18+
name: Checkout
19+
uses: actions/checkout@v6
20+
-
21+
name: Set pkgs output
22+
id: set
23+
uses: actions/github-script@v8
24+
with:
25+
script: |
26+
const fs = require('fs');
27+
const path = require('path');
28+
const disabledPkgs = (process.env.DISABLED_PACKAGES || '').split(',').map(s => s.trim()).filter(Boolean);
29+
const pkgs = fs.readdirSync('./pkg', { withFileTypes: true }).filter(d => d.isDirectory()).map(d => d.name).filter(name => !disabledPkgs.includes(name));
30+
core.info(JSON.stringify(pkgs, null, 2));
31+
core.setOutput('pkgs', JSON.stringify(pkgs));

.github/workflows/nightly.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,17 @@ on:
1111
- cron: '0 1 * * 0'
1212

1313
jobs:
14-
prepare:
15-
runs-on: ubuntu-24.04
16-
outputs:
17-
pkgs: ${{ steps.matrix.outputs.pkgs }}
18-
steps:
19-
-
20-
name: Checkout
21-
uses: actions/checkout@v6
22-
-
23-
name: Matrix
24-
id: matrix
25-
uses: actions/github-script@v8
26-
with:
27-
script: |
28-
const fs = require('fs');
29-
const path = require('path');
30-
const disabledPkgs = (process.env.DISABLED_PACKAGES || '').split(',').map(s => s.trim()).filter(Boolean);
31-
const pkgs = fs.readdirSync('./pkg', { withFileTypes: true }).filter(d => d.isDirectory()).map(d => d.name).filter(name => !disabledPkgs.includes(name));
32-
core.info(JSON.stringify(pkgs, null, 2));
33-
core.setOutput('pkgs', JSON.stringify(pkgs));
14+
pkgs:
15+
uses: ./.github/workflows/.pkgs.yml
3416

3517
build:
3618
uses: ./.github/workflows/.build.yml
3719
needs:
38-
- prepare
20+
- pkgs
3921
strategy:
4022
fail-fast: false
4123
matrix:
42-
pkg: ${{ fromJson(needs.prepare.outputs.pkgs) }}
24+
pkg: ${{ fromJson(needs.pkgs.outputs.list) }}
4325
with:
4426
name: ${{ matrix.pkg }}
4527
release: pushonly

.github/workflows/update-go.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: update-go
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
schedule:
10+
- cron: '0 */6 * * *'
11+
12+
jobs:
13+
pkgs:
14+
uses: ./.github/workflows/.pkgs.yml
15+
16+
build:
17+
runs-on: ubuntu-24.04
18+
needs:
19+
- pkgs
20+
steps:
21+
-
22+
name: Checkout
23+
uses: actions/checkout@v6
24+
-
25+
name: Get GO_VERSION from upstream repositories
26+
id: get-go-versions
27+
uses: actions/github-script@v8
28+
env:
29+
INPUT_PKGS: ${{ needs.pkgs.outputs.list }}
30+
with:
31+
script: |
32+
const inpPkgs = JSON.parse(core.getInput('pkgs'));
33+
34+
const goVersions = [];
35+
for (const pkg of inpPkgs) {
36+
await core.group(`Getting go version for ${pkg} package`, async () => {
37+
let pkgRepo = '';
38+
let pkgRef = '';
39+
let pkgDockerfile = '';
40+
await exec.getExecOutput('docker', ['buildx', 'bake', `metadata-${pkg}`, '--print'], {
41+
ignoreReturnCode: true,
42+
silent: true
43+
}).then(res => {
44+
if (res.stderr.length > 0 && res.exitCode != 0) {
45+
throw new Error(res.stderr);
46+
}
47+
const dt = JSON.parse(res.stdout.trim());
48+
pkgRepo = dt.target[`metadata-${pkg}`].args.PKG_REPO;
49+
pkgRef = dt.target[`metadata-${pkg}`].args.PKG_REF;
50+
pkgDockerfile = dt.target[`metadata-${pkg}`].args.PKG_REMOTE_DOCKERFILE;
51+
});
52+
53+
let goVersion = '';
54+
core.info(`Fetching GO_VERSION from ${pkgRepo}#${pkgRef}`);
55+
await exec.getExecOutput('docker', ['buildx', 'build', '--call', 'outline,format=json', '-f', pkgDockerfile, `${pkgRepo}#${pkgRef}`], {
56+
ignoreReturnCode: true,
57+
silent: true
58+
}).then(res => {
59+
if (res.stderr.length > 0 && res.exitCode != 0) {
60+
throw new Error(res.stderr);
61+
}
62+
const outline = JSON.parse(res.stdout.trim());
63+
goVersion = outline.args.find(arg => arg.name === 'GO_VERSION')?.value;
64+
if (!goVersion) {
65+
core.info(JSON.stringify(outline, null, 2));
66+
throw new Error(`GO_VERSION not found in outline args`);
67+
}
68+
core.info(`Found GO_VERSION: ${goVersion}`);
69+
});
70+
goVersions.push({ pkg: pkg, go_version: goVersion });
71+
});
72+
}
73+
74+
core.setOutput('list', JSON.stringify(goVersions));
75+
-
76+
name: Set GO_VERSION in docker-bake.hcl and Dockerfiles
77+
uses: actions/github-script@v8
78+
env:
79+
INPUT_GO_VERSIONS: ${{ steps.get-go-versions.outputs.list }}
80+
with:
81+
script: |
82+
const fs = require('fs');
83+
const path = require('path');
84+
85+
const inpGoVersions = JSON.parse(core.getInput('go_versions'));
86+
87+
for (const item of inpGoVersions) {
88+
const bakefilePath = 'docker-bake.hcl';
89+
core.info(`Updating GO_VERSION to ${item.go_version} in ${bakefilePath} for _pkg-${item.pkg} target`);
90+
let bakeContent = fs.readFileSync(bakefilePath, 'utf8');
91+
const bakeRegex = new RegExp(
92+
`target "_pkg-${item.pkg}" \\{[\\s\\S]*?GO_VERSION = GO_VERSION != null && GO_VERSION != "" \\? GO_VERSION : "([^"]+)"`,
93+
'm'
94+
);
95+
bakeContent = bakeContent.replace(bakeRegex, (match, p1) => {
96+
return match.replace(p1, item.go_version);
97+
});
98+
fs.writeFileSync(bakefilePath, bakeContent);
99+
100+
const dockerfilePath = path.join('pkg', item.pkg, 'Dockerfile');
101+
core.info(`Updating GO_VERSION to ${item.go_version} in ${dockerfilePath}`);
102+
let dockerfileContent = fs.readFileSync(dockerfilePath, 'utf8');
103+
const dockerfileRegex = /^ARG GO_VERSION=.*$/m;
104+
dockerfileContent = dockerfileContent.replace(dockerfileRegex, `ARG GO_VERSION="${item.go_version}"`);
105+
fs.writeFileSync(dockerfilePath, dockerfileContent);
106+
}
107+
108+
await exec.exec(`git diff --color=always`);
109+
-
110+
name: Commit changes
111+
run: |
112+
git add -A .
113+
-
114+
name: Create PR
115+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
116+
with:
117+
base: main
118+
branch: bot/update-go
119+
signoff: true
120+
delete-branch: true
121+
title: "chore: align go version from upstream repositories"
122+
body: |
123+
Keep Go versions in sync with upstream repositories.
124+
draft: false

docker-bake.hcl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,10 @@ target "_pkg-buildx" {
522522
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-buildx-plugin"
523523
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/buildx.git"
524524
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
525-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/buildx/blob/854a58a65d5ada26ddc8b6ebd60ddb89fa5616a3/Dockerfile#L3
525+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/buildx/blob/master/Dockerfile
526526
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
527527
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
528+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
528529
}
529530
}
530531

@@ -533,9 +534,10 @@ target "_pkg-compose" {
533534
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-compose-plugin"
534535
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/compose.git"
535536
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
536-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/compose/blob/fa081274567ac350f0e5f16abbe51701b320626e/Dockerfile#L18
537+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/compose/blob/main/Dockerfile
537538
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
538539
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
540+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
539541
}
540542
}
541543

@@ -544,10 +546,11 @@ target "_pkg-containerd" {
544546
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "containerd.io"
545547
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/containerd/containerd.git"
546548
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
547-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/containerd/containerd/blob/2d28d98490f53d78c98faecfc91f9fd54cdbc16e/.github/workflows/release.yml#L16
549+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/containerd/containerd/blob/main/.github/workflows/release/Dockerfile
548550
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
549551
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
550552
RUNC_REF = RUNC_REF != null && RUNC_REF != "" ? RUNC_REF : null
553+
PKG_REMOTE_DOCKERFILE = ".github/workflows/release/Dockerfile"
551554
}
552555
}
553556

@@ -556,9 +559,10 @@ target "_pkg-credential-helpers" {
556559
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-credential-helpers"
557560
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/docker-credential-helpers.git"
558561
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
559-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/docker-credential-helpers/blob/b7a754b9ffdf0e99e63ca384435bdacf4bc83e6b/Dockerfile#L3
562+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/docker-credential-helpers/blob/master/Dockerfile
560563
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
561564
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
565+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
562566
}
563567
}
564568

@@ -567,9 +571,10 @@ target "_pkg-docker-cli" {
567571
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-ce-cli"
568572
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/cli.git"
569573
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
570-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/cli/blob/d16defd9e237a02e4e8b8710d9ce4a15472e60c8/Dockerfile#L11
574+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/cli/blob/master/Dockerfile
571575
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
572576
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : "5"
577+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
573578
}
574579
}
575580

@@ -578,9 +583,10 @@ target "_pkg-docker-engine" {
578583
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-ce"
579584
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/docker.git"
580585
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
581-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/moby/moby/blob/4b978319922166bab9116b3e60e716a62b9cf130/Dockerfile#L3
586+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/moby/moby/blob/master/Dockerfile
582587
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
583588
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : "5"
589+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
584590
}
585591
}
586592

@@ -589,9 +595,10 @@ target "_pkg-model" {
589595
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-model-plugin"
590596
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/model-runner.git"
591597
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
592-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/model-runner/blob/039f7a31c0365f9161c9b9b6bb3888161d16e388/cmd/cli/Dockerfile#L3
598+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/model-runner/blob/main/cmd/cli/Dockerfile
593599
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
594600
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
601+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
595602
}
596603
}
597604

@@ -600,9 +607,10 @@ target "_pkg-cagent" {
600607
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "cagent"
601608
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/cagent.git"
602609
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
603-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.4" # https://github.com/docker/cagent/blob/259774ed55b2b51c4b602d9636d68a6bb23117ec/Dockerfile#L6
610+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.4" # https://github.com/docker/cagent/blob/main/Dockerfile
604611
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
605612
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
613+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
606614
}
607615
}
608616

0 commit comments

Comments
 (0)