Skip to content

Commit da8f102

Browse files
committed
make dev.Dockerfile cross arch
1 parent 20d37c3 commit da8f102

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

.github/workflows/docker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ name: Release docker image
88
on: [push, pull_request]
99

1010
jobs:
11+
# TODO: we should merge job docker-amd and job docker-arm once the github actions fix their issue with cross-platform building.
1112
docker-amd:
1213
runs-on: ubuntu-22.04
1314

lib/docker/dev.Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
FROM ghcr.io/go-rod/rod
66

7-
ARG node="https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz"
8-
ARG golang="https://go.dev/dl/go1.18.linux-amd64.tar.gz"
7+
ARG nodejs
8+
ARG golang
99
ARG apt_sources="http://archive.ubuntu.com"
1010

1111
RUN sed -i "s|http://archive.ubuntu.com|$apt_sources|g" /etc/apt/sources.list && \
1212
apt-get update && apt-get install --no-install-recommends -y git curl xz-utils build-essential && \
1313
rm -rf /var/lib/apt/lists/*
1414

1515
# install nodejs
16-
RUN curl -L $node > node.tar.xz && \
16+
RUN curl -L $nodejs > node.tar.xz && \
1717
tar -xf node.tar.xz && \
1818
mv node-* /usr/local/lib/.node && \
1919
rm node.tar.xz

lib/docker/main.go

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,47 @@ func releaseLatest(at archType) {
4141
login()
4242
test(at)
4343

44-
utils.Exec("docker push", at.tag())
4544
utils.Exec("docker push", at.tagDev())
45+
utils.Exec("docker push", at.tag())
4646
}
4747

4848
func releaseWithVer(ver string, at archType) {
4949
login()
5050

51-
utils.Exec("docker manifest create", registry, archAmd.tag(), archArm.tag())
52-
utils.Exec("docker manifest push", registry)
53-
54-
registryDev := registry + ":dev"
55-
utils.Exec("docker manifest create", registryDev, archAmd.tagDev(), archArm.tagDev())
56-
utils.Exec("docker manifest push", registryDev)
57-
58-
verImage := registry + ":" + ver
5951
verImageDev := registry + ":" + ver + "-dev"
52+
utils.Exec("docker manifest create", verImageDev, archAmd.tagDev(), archArm.tagDev())
53+
utils.Exec("docker manifest push", verImageDev)
6054

55+
verImage := registry + ":" + ver
6156
utils.Exec("docker manifest create", verImage, archAmd.tag(), archArm.tag())
6257
utils.Exec("docker manifest push", verImage)
6358

64-
utils.Exec("docker manifest create", verImageDev, archAmd.tagDev(), archArm.tagDev())
65-
utils.Exec("docker manifest push", verImageDev)
59+
registryDev := registry + ":dev"
60+
utils.Exec("docker manifest create", registryDev, archAmd.tagDev(), archArm.tagDev())
61+
utils.Exec("docker manifest push", registryDev)
62+
63+
utils.Exec("docker manifest create", registry, archAmd.tag(), archArm.tag())
64+
utils.Exec("docker manifest push", registry)
6665
}
6766

6867
func test(at archType) {
6968
utils.Exec("docker build -f=lib/docker/Dockerfile", "--platform", at.platform(), "-t", at.tag(), description(false), ".")
70-
utils.Exec("docker build -f=lib/docker/dev.Dockerfile", "--platform", at.platform(), "-t", at.tagDev(), description(true), ".")
69+
utils.Exec("docker build -f=lib/docker/dev.Dockerfile",
70+
"--platform", at.platform(),
71+
"--build-arg", "golang="+at.golang(),
72+
"--build-arg", "nodejs="+at.nodejs(),
73+
"-t", at.tagDev(),
74+
description(true), ".",
75+
)
7176

7277
utils.Exec("docker run", at.tag(), "rod-manager", "-h")
7378

74-
wd, err := os.Getwd()
75-
utils.E(err)
76-
utils.Exec("docker run -w=/t -v", fmt.Sprintf("%s:/t", wd), at.tagDev(), "go", "test")
79+
// TODO: arm cross execution for chromium doesn't work well on github actions.
80+
if at != archArm {
81+
wd, err := os.Getwd()
82+
utils.E(err)
83+
utils.Exec("docker run -w=/t -v", fmt.Sprintf("%s:/t", wd), at.tagDev(), "go", "test")
84+
}
7785
}
7886

7987
func login() {
@@ -83,15 +91,16 @@ func login() {
8391
utils.E(os.Stdout.Write(out))
8492
}
8593

94+
var headSha = strings.TrimSpace(utils.ExecLine(false, "git", "rev-parse", "HEAD"))
95+
8696
func description(dev bool) string {
87-
sha := strings.TrimSpace(utils.ExecLine(false, "git", "rev-parse", "HEAD"))
8897

8998
f := "Dockerfile"
9099
if dev {
91100
f = "dev." + f
92101
}
93102

94-
return `--label=org.opencontainers.image.description=https://github.com/go-rod/rod/blob/` + sha + "/lib/docker/" + f
103+
return `--label=org.opencontainers.image.description=https://github.com/go-rod/rod/blob/` + headSha + "/lib/docker/" + f
95104
}
96105

97106
const registry = "ghcr.io/go-rod/rod"
@@ -139,3 +148,21 @@ func (at archType) tagDev() string {
139148
return registry + ":amd-dev"
140149
}
141150
}
151+
152+
func (at archType) golang() string {
153+
switch at {
154+
case archArm:
155+
return "https://go.dev/dl/go1.19.1.linux-arm64.tar.gz"
156+
default:
157+
return "https://go.dev/dl/go1.19.1.linux-amd64.tar.gz"
158+
}
159+
}
160+
161+
func (at archType) nodejs() string {
162+
switch at {
163+
case archArm:
164+
return "https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-arm64.tar.xz"
165+
default:
166+
return "https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz"
167+
}
168+
}

0 commit comments

Comments
 (0)