Skip to content

Commit 175cfe3

Browse files
committed
chore: split up dockerfiles
1 parent a0266f4 commit 175cfe3

File tree

8 files changed

+208
-155
lines changed

8 files changed

+208
-155
lines changed

.github/workflows/devel.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
with:
7878
context: .
7979
platforms: linux/amd64
80-
file: docker/amd64/Dockerfile
80+
file: docker/amd64/base/Dockerfile
8181
load: true
8282
tags: ${{ steps.meta.outputs.tags }}
8383
labels: ${{ steps.meta.outputs.labels }}
@@ -107,8 +107,8 @@ jobs:
107107
cat /etc/debian_version
108108
uname -a
109109
make test-app
110-
make test-zlib
111-
make test-openssl
110+
# make test-zlib
111+
# make test-openssl
112112
-
113113
# Temp fix
114114
# https://github.com/docker/build-push-action/issues/252
@@ -178,7 +178,7 @@ jobs:
178178
with:
179179
context: .
180180
platforms: linux/arm64
181-
file: docker/arm64/Dockerfile
181+
file: docker/arm64/base/Dockerfile
182182
load: true
183183
tags: ${{ steps.meta.outputs.tags }}
184184
labels: ${{ steps.meta.outputs.labels }}
@@ -208,8 +208,8 @@ jobs:
208208
cat /etc/debian_version
209209
uname -a
210210
make test-app
211-
make test-zlib
212-
make test-openssl
211+
# make test-zlib
212+
# make test-openssl
213213
-
214214
# Temp fix
215215
# https://github.com/docker/build-push-action/issues/252

Makefile

Lines changed: 94 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,104 @@
1-
REPOSITORY ?= joseluisq
2-
TAG ?= latest
1+
REPOSITORY ?= joseluisq/rust-linux-darwin-builder
2+
TAG ?= devel
33

4-
build-amd64:
5-
docker build \
6-
-t $(REPOSITORY)/rust-linux-darwin-builder:$(TAG)-amd64 \
4+
# AMD64 Tasks
5+
6+
amd64-build:
7+
docker buildx build \
8+
-t $(REPOSITORY):$(TAG)-amd64 \
79
--network=host \
8-
-f docker/amd64/Dockerfile .
9-
.PHONY: build-amd64
10+
--platform linux/amd64 \
11+
-f docker/amd64/base/Dockerfile .
12+
.PHONY: amd64-build
1013

11-
run-amd64:
14+
amd64-run:
1215
@docker run --rm -it \
1316
-v $(PWD):/root/src \
14-
-v $(PWD)/docker/amd64/cargo.toml:/root/.cargo/config.toml \
17+
-v $(PWD)/docker/amd64/base/cargo.toml:/root/.cargo/config.toml \
1518
-w /root/src \
16-
$(REPOSITORY)/rust-linux-darwin-builder:$(TAG)-amd64 \
19+
$(REPOSITORY):$(TAG)-amd64 \
1720
bash
18-
.PHONY: run-amd64
21+
.PHONY: amd64-run
22+
23+
amd64-test:
24+
@docker run --rm \
25+
-v $(PWD):/root/src \
26+
-w /root/src \
27+
$(REPOSITORY):$(TAG)-amd64 \
28+
bash -c 'set -eu; test-app'
29+
.PHONY: amd64-test
1930

20-
build-arm64:
31+
amd64-build-libs:
2132
docker buildx build \
22-
-t $(REPOSITORY)/rust-linux-darwin-builder:$(TAG)-arm64 \
33+
-t $(REPOSITORY):$(TAG)-amd64-libs \
2334
--network=host \
24-
--platform linux/arm64 \
25-
-f docker/arm64/Dockerfile .
26-
.PHONY: build-arm64
35+
--platform linux/amd64 \
36+
-f docker/amd64/libs/Dockerfile .
37+
.PHONY: amd64-build-libs
2738

28-
run-arm64:
39+
amd64-run-libs:
2940
@docker run --rm -it \
3041
-v $(PWD):/root/src \
31-
-v $(PWD)/docker/arm64/cargo.toml:/root/.cargo/config.toml \
42+
-v $(PWD)/docker/amd64/libs/cargo.toml:/root/.cargo/config.toml \
3243
-w /root/src \
33-
$(REPOSITORY)/rust-linux-darwin-builder:$(TAG)-arm64 \
44+
$(REPOSITORY):$(TAG)-amd64-libs \
3445
bash
35-
.PHONY: run-arm64
46+
.PHONY: amd64-run-libs
3647

37-
# Use to build both arm64 and amd64 images at the same time.
38-
# WARNING! Will automatically push, since multi-platform images are not available locally.
39-
# Use `REPOSITORY` arg to specify which container repository to push the images to.
40-
buildx:
41-
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64,linux/arm64
42-
docker buildx create --name darwin-builder --driver docker-container --bootstrap
43-
docker buildx use darwin-builder
48+
amd64-test-libs:
49+
@docker run --rm \
50+
-v $(PWD):/root/src \
51+
-w /root/src \
52+
$(REPOSITORY):$(TAG)-amd64-libs \
53+
bash -c 'set -eu; test-all'
54+
.PHONY: amd64-test-libs
55+
56+
57+
# ARM64 Tasks
58+
59+
arm64-build:
4460
docker buildx build \
45-
--platform linux/amd64,linux/arm64 \
46-
--push \
47-
-t $(REPOSITORY)/rust-linux-darwin-builder:$(TAG) \
48-
-f Dockerfile .
61+
-t $(REPOSITORY):$(TAG)-arm64 \
62+
--network=host \
63+
--platform linux/arm64 \
64+
-f docker/arm64/base/Dockerfile .
65+
.PHONY: arm64-build
4966

50-
.PHONY: buildx
67+
arm64-test:
68+
@docker run --rm \
69+
-v $(PWD):/root/src \
70+
-w /root/src \
71+
$(REPOSITORY):$(TAG)-arm64 \
72+
bash -c 'set -eu; test-app'
73+
.PHONY: arm64-test
5174

52-
test:
75+
arm64-build-libs:
76+
docker buildx build \
77+
-t $(REPOSITORY):$(TAG)-arm64-libs \
78+
--network=host \
79+
--platform linux/arm64 \
80+
-f docker/arm64/libs/Dockerfile .
81+
.PHONY: arm64-build-libs
82+
83+
arm64-run-libs:
84+
@docker run --rm -it \
85+
-v $(PWD):/root/src \
86+
-v $(PWD)/docker/arm64/libs/cargo.toml:/root/.cargo/config.toml \
87+
-w /root/src \
88+
$(REPOSITORY):$(TAG)-arm64-libs \
89+
bash
90+
.PHONY: arm64-run-libs
91+
92+
arm64-test-libs:
5393
@docker run --rm \
5494
-v $(PWD):/root/src \
5595
-w /root/src \
56-
$(REPOSITORY)/rust-linux-darwin-builder:$(TAG) \
57-
bash -c 'set -eu; make test-app; make test-zlib; make test-openssl'
58-
.PHONY: test
96+
$(REPOSITORY):$(TAG)-arm64-libs \
97+
bash -c 'set -eu; test-all'
98+
.PHONY: arm64-test-libs
99+
100+
101+
# Testing Tasks (inside the container)
59102

60103
test-all: test-app test-zlib test-openssl
61104
.PHONY: test-all
@@ -176,8 +219,7 @@ test-zlib:
176219
cargo build -v --release --target aarch64-apple-darwin \
177220
&& du -sh target/aarch64-apple-darwin/release/zlib-test \
178221
&& file target/aarch64-apple-darwin/release/zlib-test \
179-
&& echo \
180-
222+
&& echo
181223
.ONESHELL: test-zlib
182224

183225
test-openssl:
@@ -243,5 +285,18 @@ test-openssl:
243285
&& du -sh target/aarch64-apple-darwin/release/openssl-test \
244286
&& file target/aarch64-apple-darwin/release/openssl-test \
245287
&& echo
246-
247288
.ONESHELL: test-openssl
289+
290+
# Use to build both arm64 and amd64 images at the same time.
291+
# WARNING! Will automatically push, since multi-platform images are not available locally.
292+
# Use `REPOSITORY` arg to specify which container repository to push the images to.
293+
buildx:
294+
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64,linux/arm64
295+
docker buildx create --name darwin-builder --driver docker-container --bootstrap
296+
docker buildx use darwin-builder
297+
docker buildx build \
298+
--platform linux/amd64,linux/arm64 \
299+
--push \
300+
-t $(REPOSITORY):$(TAG) \
301+
-f Dockerfile .
302+
.PHONY: buildx

docker/amd64/base/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM joseluisq/docker-osxcross:1.0.0-beta.2
2+
3+
ARG VERSION=0.0.0
4+
ENV VERSION=${VERSION}
5+
6+
# Rust stable toolchain
7+
ARG TOOLCHAIN=1.87.0
8+
9+
LABEL version="${VERSION}" \
10+
description="Use same Docker image for compiling Rust programs for Linux (musl libc) & macOS (osxcross)." \
11+
maintainer="Jose Quintana <joseluisq.net>"
12+
13+
# Static linking for C++ code
14+
RUN set -eux \
15+
&& ln -s "/usr/bin/g++" "/usr/bin/musl-g++" \
16+
# Create appropriate directories for current user
17+
&& mkdir -p /root/libs /root/src \
18+
&& true
19+
20+
ENV PATH=/root/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
21+
22+
##### Rust toolchains
23+
24+
# Rust/Cargo related environment variables
25+
ENV TARGET=musl
26+
27+
# pkg-config related environment variables
28+
ENV PKG_CONFIG_ALLOW_CROSS=1
29+
ENV PKG_CONFIG_ALL_STATIC=1
30+
31+
RUN set -eux \
32+
&& curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TOOLCHAIN \
33+
&& rustup target add \
34+
aarch64-apple-darwin \
35+
aarch64-unknown-linux-gnu \
36+
aarch64-unknown-linux-musl \
37+
x86_64-apple-darwin \
38+
x86_64-unknown-linux-musl \
39+
x86_64-unknown-linux-gnu \
40+
&& true
41+
42+
COPY docker/amd64/base/cargo.toml /root/.cargo/config.toml
43+
44+
RUN set -eux \
45+
&& rustc -vV \
46+
&& cargo -vV \
47+
&& true
48+
49+
WORKDIR /root/src
50+
51+
CMD ["bash"]
File renamed without changes.

docker/amd64/Dockerfile renamed to docker/amd64/libs/Dockerfile

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,4 @@
1-
FROM joseluisq/docker-osxcross:1.0.0-beta.2
2-
3-
ARG VERSION=0.0.0
4-
ENV VERSION=${VERSION}
5-
6-
LABEL version="${VERSION}" \
7-
description="Use same Docker image for compiling Rust programs for Linux (musl libc) & macOS (osxcross)." \
8-
maintainer="Jose Quintana <joseluisq.net>"
9-
10-
# Static linking for C++ code
11-
RUN set -eux \
12-
&& ln -s "/usr/bin/g++" "/usr/bin/musl-g++" \
13-
# Create appropriate directories for current user
14-
&& mkdir -p /root/libs /root/src \
15-
&& true
16-
17-
ENV PATH=/root/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
18-
19-
##### Rust toolchains
20-
21-
# Rust/Cargo related environment variables
22-
ENV TARGET=musl
23-
# Crate-related environment variables
24-
ENV LIBZ_SYS_STATIC=1
25-
26-
# Rust stable toolchain
27-
ARG TOOLCHAIN=1.87.0
28-
29-
RUN set -eux \
30-
&& curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TOOLCHAIN \
31-
&& rustup target add \
32-
aarch64-apple-darwin \
33-
aarch64-unknown-linux-gnu \
34-
aarch64-unknown-linux-musl \
35-
x86_64-apple-darwin \
36-
x86_64-unknown-linux-musl \
37-
x86_64-unknown-linux-gnu \
38-
&& true
39-
40-
COPY docker/amd64/cargo.toml /root/.cargo/config.toml
41-
42-
RUN set -eux \
43-
&& rustc -vV \
44-
&& cargo -vV \
45-
&& true
46-
47-
##### Libraries
1+
FROM joseluisq/rust-linux-darwin-builder:v2.0.0-beta.1
482

493
RUN set -eux \
504
&& dpkg --add-architecture arm64 \
@@ -61,6 +15,8 @@ RUN set -eux \
6115

6216
# zlib - http://zlib.net/
6317
ARG ZLIB_VERSION=1.3.1
18+
# Crate-related environment variables
19+
ENV LIBZ_SYS_STATIC=1
6420

6521
WORKDIR /tmp
6622

@@ -250,12 +206,6 @@ RUN set -eux \
250206
&& rm -rf /tmp/* \
251207
&& true
252208

253-
WORKDIR /root
254-
255-
# pkg-config related environment variables
256-
ENV PKG_CONFIG_ALLOW_CROSS=true
257-
ENV PKG_CONFIG_ALL_STATIC=true
258-
259209
# OpenSSL related environment variables
260210
ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_STATIC=1
261211
ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR=/usr/local/x86_64-linux-musl
@@ -268,5 +218,3 @@ ENV AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_DIR=/usr/local/aarch64-linux-gnu
268218
ENV AARCH64_APPLE_DARWIN_OPENSSL_DIR=/usr/local/aarch64-apple-darwin
269219

270220
WORKDIR /root/src
271-
272-
CMD ["bash"]

docker/arm64/base/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM joseluisq/docker-osxcross:1.0.0-beta.1
2+
3+
ARG VERSION=0.0.0
4+
ENV VERSION=${VERSION}
5+
6+
# Rust stable toolchain
7+
ARG TOOLCHAIN=1.87.0
8+
9+
LABEL version="${VERSION}" \
10+
description="Use same Docker image for compiling Rust programs for Linux (musl libc) & macOS (osxcross)." \
11+
maintainer="Jose Quintana <joseluisq.net>"
12+
13+
# Static linking for C++ code
14+
RUN set -eux \
15+
&& ln -s "/usr/bin/g++" "/usr/bin/musl-g++" \
16+
# Create appropriate directories for current user
17+
&& mkdir -p /root/libs /root/src \
18+
&& true
19+
20+
ENV PATH=/root/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
21+
22+
##### Rust toolchains
23+
24+
# Rust/Cargo related environment variables
25+
ENV TARGET=musl
26+
27+
# pkg-config related environment variables
28+
ENV PKG_CONFIG_ALLOW_CROSS=1
29+
ENV PKG_CONFIG_ALL_STATIC=1
30+
31+
RUN set -eux \
32+
&& curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TOOLCHAIN \
33+
&& rustup target add \
34+
aarch64-apple-darwin \
35+
aarch64-unknown-linux-gnu \
36+
aarch64-unknown-linux-musl \
37+
x86_64-apple-darwin \
38+
x86_64-unknown-linux-musl \
39+
x86_64-unknown-linux-gnu \
40+
&& true
41+
42+
COPY docker/arm64/base/cargo.toml /root/.cargo/config.toml
43+
44+
RUN set -eux \
45+
&& rustc -vV \
46+
&& cargo -vV \
47+
&& true
48+
49+
WORKDIR /root/src
50+
51+
CMD ["bash"]
File renamed without changes.

0 commit comments

Comments
 (0)