Skip to content

Merge docker images with extra build-arg #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ jobs:
platform: [linux/amd64, linux/arm64]
include:
- platform: linux/amd64
dockerfile: Dockerfile.x86_64
dockerfile: Dockerfile
arch: amd64
aarch: x86_64
target_dir: x86_64-unknown-linux-musl
- platform: linux/arm64
dockerfile: Dockerfile.arm64
dockerfile: Dockerfile
arch: arm64
aarch: aarch64
target_dir: aarch64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -73,6 +75,7 @@ jobs:
tags: rustmusl-temp
build-args: |
CHANNEL=nightly
AARCH=${{ matrix.aarch }}

- name: Run tests
shell: bash
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ jobs:
platform: [linux/amd64, linux/arm64]
include:
- platform: linux/amd64
dockerfile: Dockerfile.x86_64
dockerfile: Dockerfile
arch: amd64
aarch: x86_64
target_dir: x86_64-unknown-linux-musl
- platform: linux/arm64
dockerfile: Dockerfile.arm64
dockerfile: Dockerfile
arch: arm64
aarch: aarch64
target_dir: aarch64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -85,6 +87,7 @@ jobs:
tags: rustmusl-temp
build-args: |
CHANNEL=stable
AARCH=${{ matrix.aarch }}
if: ${{ steps.stablecheck.outputs.BUILD }}

- name: Run tests
Expand Down
24 changes: 17 additions & 7 deletions Dockerfile.arm64 → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# syntax=docker/dockerfile:1
FROM ubuntu:noble
LABEL maintainer="Eirik Albrigtsen <sszynrae@gmail.com>"
LABEL org.opencontainers.image.create="$(date --utc --iso-8601=seconds)"
LABEL org.opencontainers.image.documentation="https://github.com/clux/muslrust"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.url="https://github.com/clux/muslrust"
LABEL org.opencontainers.image.description="Docker environment for building musl based static rust binaries"

# Required packages:
# - musl-dev, musl-tools - the musl toolchain
Expand Down Expand Up @@ -30,17 +35,19 @@ RUN apt-get update && apt-get install -y \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*

# Common arg for arch used in urls and triples
ARG AARCH
# Install rust using rustup
ARG CHANNEL
ENV RUSTUP_VER="1.27.1" \
RUST_ARCH="aarch64-unknown-linux-gnu" \
RUST_ARCH="${AARCH}-unknown-linux-gnu" \
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

RUN curl "https://static.rust-lang.org/rustup/archive/${RUSTUP_VER}/${RUST_ARCH}/rustup-init" -o rustup-init && \
chmod +x rustup-init && \
./rustup-init -y --default-toolchain ${CHANNEL} --profile minimal --no-modify-path && \
rm rustup-init && \
~/.cargo/bin/rustup target add aarch64-unknown-linux-musl
~/.cargo/bin/rustup target add ${AARCH}-unknown-linux-musl

# Allow non-root access to cargo
RUN chmod a+X /root
Expand All @@ -49,7 +56,7 @@ RUN chmod a+X /root
# This helps continuing manually if anything breaks.
ENV ZLIB_VER="1.3.1" \
SQLITE_VER="3490100" \
PROTOBUF_VER="29.2" \
PROTOBUF_VER="31.0" \
SCCACHE_VER="0.9.1" \
CC=musl-gcc \
PREFIX=/musl \
Expand All @@ -59,18 +66,18 @@ ENV ZLIB_VER="1.3.1" \

# Install a more recent release of protoc (protobuf-compiler in jammy is 4 years old and misses some features)
RUN cd /tmp && \
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-aarch_64.zip -o protoc.zip && \
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-$([ "$AARCH" = "aarch64" ] && echo "aarch_64" || echo "$AARCH").zip -o protoc.zip && \
unzip protoc.zip && \
cp bin/protoc /usr/bin/protoc && \
rm -rf *

# Install prebuilt sccache based on platform
RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VER}/sccache-v${SCCACHE_VER}-aarch64-unknown-linux-musl.tar.gz | tar xz && \
RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VER}/sccache-v${SCCACHE_VER}-${AARCH}-unknown-linux-musl.tar.gz | tar xz && \
mv sccache-v${SCCACHE_VER}-*-unknown-linux-musl/sccache /usr/local/bin/ && \
chmod +x /usr/local/bin/sccache && \
rm -rf sccache-v${SCCACHE_VER}-*-unknown-linux-musl

# Build zlib (used in pq)
# Build zlib
RUN curl -sSL https://zlib.net/zlib-$ZLIB_VER.tar.gz | tar xz && \
cd zlib-$ZLIB_VER && \
CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure --static --prefix=$PREFIX && \
Expand All @@ -88,13 +95,16 @@ RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | t

ENV PATH=/root/.cargo/bin:$PREFIX/bin:$PATH \
RUSTUP_HOME=/root/.rustup \
CARGO_BUILD_TARGET=aarch64-unknown-linux-musl \
CARGO_BUILD_TARGET=${AARCH}-unknown-linux-musl \
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld -Ctarget-feature=+crt-static" \
PKG_CONFIG_ALLOW_CROSS=true \
PKG_CONFIG_ALL_STATIC=true \
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
PG_CONFIG_AARCH64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
# Rust libz-sys support
LIBZ_SYS_STATIC=1 \
ZLIB_STATIC=1 \
DEBIAN_FRONTEND=noninteractive \
TZ=Etc/UTC

Expand Down
101 changes: 0 additions & 101 deletions Dockerfile.x86_64

This file was deleted.

14 changes: 6 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
default:
@just --list --unsorted --color=always

_build channel ar platform ext:
docker build --build-arg CHANNEL="{{channel}}" --build-arg AR="{{ar}}" --platform="{{platform}}" -t rustmusl-temp . -f Dockerfile.{{ext}}
_build channel platform aarch:
docker build --build-arg CHANNEL="{{channel}}" --build-arg AARCH="{{aarch}}" --platform="{{platform}}" -t rustmusl-temp . -f Dockerfile --debug
# Build the stable x86 container
build-stable-amd: (_build "stable" "amd64" "linux/amd64" "x86_64")
build-stable-amd: (_build "stable" "linux/amd64" "x86_64")
# Build the nightly x86 container
build-nightly-amd: (_build "nightly" "amd64" "linux/amd64" "x86_64")
build-nightly-amd: (_build "nightly" "linux/amd64" "x86_64")
# Build the stable arm container
build-stable-arm: (_build "stable" "arm64" "linux/arm64" "arm64")
build-stable-arm: (_build "stable" "linux/arm64" "aarch64")
# Build the nightly arm container
build-nightly-arm: (_build "nightly" "arm64" "linux/arm64" "arm64")
build-nightly-arm: (_build "nightly" "linux/arm64" "aarch64")

# Shell into the built container
run:
Expand All @@ -36,13 +36,11 @@ _t_linux_x86_64 crate:
#!/bin/bash
export PLATFORM="linux/amd64"
export TARGET_DIR="x86_64-unknown-linux-musl"
export AR="amd64"
./test.sh {{crate}}
_t_macos_aarch64 crate:
#!/bin/bash
export PLATFORM="linux/arm64"
export TARGET_DIR="aarch64-unknown-linux-musl"
export AR="arm64"
./test.sh {{crate}}

# Test all crates against built container locally
Expand Down
1 change: 0 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ docker_build() {
-v "$PWD/test/${crate}:/volume" \
-v cargo-cache:/root/.cargo/registry \
-e RUST_BACKTRACE=1 \
-e AR=ar \
--platform "${PLATFORM}" \
rustmusl-temp \
cargo build
Expand Down