Skip to content

Commit 80ce1e4

Browse files
committed
Merge branch 'release/samedec-0.4.2'
2 parents 923d6c2 + ca080aa commit 80ce1e4

37 files changed

Lines changed: 1438 additions & 484 deletions

File tree

.github/container/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,29 @@ Instead of using cross-rs, we create our own environment that includes all of th
2323

2424
to build it. The build instructions are heavily influenced by the cross-rs project but do not depend on it.
2525

26-
You can use any of these containers offline to build samedec. Define the following volumes:
26+
You can use any of these containers offline to build samedec. See the [`local-ci.sh`](../local-ci.sh) script for a working demonstration that includes:
27+
28+
* A single `cargo vendor` download for all dependencies for all platforms
29+
* Source code linting
30+
* Documentation completeness checks
31+
* Multi-platform cross-compiling
32+
* Multi-platform testing in qemu
33+
* Artifact generation
34+
35+
Or you can run it yourself. The containers require the following volumes:
2736

2837
* `/src`: the repository root of a Rust project
29-
* `/install`: destination for binaries installed with `cargo install`
30-
* `/src/target` (**optional**): a build directory.
31-
* `/cargohome` (**optional**): a persistent `$CARGO_HOME` directory
38+
* `/install` (**optional**): destination for binaries installed with `cargo install`
39+
* `/src/target` (**optional**): a reusable build directory
40+
* `/cargo` (**optional**): a persistent `$CARGO_HOME`
3241

3342
Example:
3443

3544
```bash
3645
mkdir -p out/aarch64-unknown-linux-gnu
3746

3847
podman run \
39-
--security-opt label=disable \
48+
--security-opt=label=disable \
4049
--userns=keep-id:uid=1001,gid=1001 \
4150
--rm -it \
4251
--volume .:/src:ro \

.github/container/aarch64-unknown-linux-gnu/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ ENV CARGO_BUILD_TARGET="$RUST_TARGET" \
3232

3333
USER builder
3434

35+
ARG SOURCE_REV=nogit
36+
3537
LABEL org.opencontainers.image.description="A Debian-based Rust cross-compiling environment."
38+
LABEL org.opencontainers.image.revision="$SOURCE_REV"

.github/container/armv7-unknown-linux-gnueabihf/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ ENV CARGO_BUILD_TARGET="$RUST_TARGET" \
3232

3333
USER builder
3434

35+
ARG SOURCE_REV=nogit
36+
3537
LABEL org.opencontainers.image.description="A Debian-based Rust cross-compiling environment."
38+
LABEL org.opencontainers.image.revision="$SOURCE_REV"

.github/container/build.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ usage() {
1818
Usage: $0 [--push]
1919
2020
Build container images for the CI environment. To select
21-
a particular container platform tool like podman, set
21+
a particular container platform tool like buildah, set
2222
23-
BUILDER=podman
23+
BUILDER=buildah
2424
2525
Prior to pushing, make sure to
2626
27-
podman login "$CONTAINER_PREFIX"
27+
buildah login "$CONTAINER_PREFIX"
2828
2929
or equivalent.
3030
EOF
@@ -45,7 +45,7 @@ container_builder() {
4545
command -v "${BUILDER}"
4646
else
4747
{
48-
command -v podman || \
48+
command -v buildah || \
4949
command -v docker
5050
} 2>/dev/null || {
5151
echo >&2 "FATAL: container platform tools not found"
@@ -67,16 +67,17 @@ buildcontainer() {
6767
# Run the $BUILDER to build a container image. Some standardized
6868
# arguments are passed to every build.
6969

70-
if [[ $BUILDER =~ podman$ ]]; then
70+
if [[ $BUILDER =~ buildah$ ]]; then
7171
run "$BUILDER" build \
72-
--build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
72+
--identity-label=false \
73+
--build-arg=SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
7374
--timestamp "$SOURCE_DATE_EPOCH" \
7475
${NO_CACHE:+--no-cache} \
7576
"$@"
7677
else
7778
# docker mode; 100% untested
7879
run "$BUILDER" buildx build \
79-
--build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
80+
--build-arg=SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
8081
--output type=docker,rewrite-timestamp=true \
8182
${NO_CACHE:+--no-cache} \
8283
"$@"
@@ -109,7 +110,8 @@ pushall() {
109110

110111
local tag
111112
for tag in "$@"; do
112-
run "$BUILDER" push "${prefix}:${tag}"
113+
run "$BUILDER" push --retry 3 "${prefix}:${tag}"
114+
sleep 2
113115
done
114116
}
115117

@@ -144,14 +146,18 @@ selfdir="$(dirname "$(realpath -e "${0?}")")"
144146
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git log -1 --pretty=%ct -- "$selfdir" || date +%s)}"
145147
export SOURCE_DATE_EPOCH
146148

149+
# set git revision
150+
SOURCE_REV="$(git log -1 --format='%H' -- "$selfdir" || echo "nogit")"
151+
147152
# tag with "latest" and SOURCE_DATE_EPOCH
148153
CONTAINER_TAGS=("latest" "$(date --date '@'"$SOURCE_DATE_EPOCH" +'%Y-%m-%d')")
149154

150155
# build the base image
151156
base_tag="$(container_name base):${CONTAINER_TAGS[0]}"
152157

153158
buildcontainer \
154-
--build-arg DEBIAN_TAG="$DEBIAN_TAG" \
159+
--build-arg=DEBIAN_TAG="$DEBIAN_TAG" \
160+
--pull=missing \
155161
--tag "$base_tag" \
156162
"${selfdir?}/base"
157163

@@ -160,7 +166,8 @@ rust_tag="$(container_name rust):${CONTAINER_TAGS[0]}"
160166

161167
buildcontainer \
162168
--from "$base_tag" \
163-
--build-arg RUST_VERSIONS="${RUST_VERSIONS[*]}" \
169+
--pull=false \
170+
--build-arg=RUST_VERSIONS="${RUST_VERSIONS[*]}" \
164171
--tag "$rust_tag" \
165172
"${selfdir?}/rust"
166173

@@ -173,6 +180,8 @@ for containerdir in "${selfdir?}/"*-*-*; do
173180

174181
buildcontainer \
175182
--from "$rust_tag" \
183+
--pull=false \
184+
--build-arg=SOURCE_REV="$SOURCE_REV" \
176185
--tag "${cur_tag}" \
177186
"${containerdir}"
178187
done

.github/container/i686-unknown-linux-gnu/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ ENV CARGO_BUILD_TARGET="$RUST_TARGET" \
3232

3333
USER builder
3434

35+
ARG SOURCE_REV=nogit
36+
3537
LABEL org.opencontainers.image.description="A Debian-based Rust cross-compiling environment."
38+
LABEL org.opencontainers.image.revision="$SOURCE_REV"

.github/container/rust/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ ENV PATH=/install/bin:/usr/local/cargo/bin:$PATH \
3737

3838
# Instructions adapted from official Docker image
3939
# <https://github.com/rust-lang/docker-rust/blob/master/Dockerfile-slim.template>
40-
RUN set -eux; \
40+
RUN --mount=type=bind,src=./rootfiles,dst=/rootfiles,ro \
41+
set -eux; \
42+
install --mode=0755 -t /usr/local/bin /rootfiles/qemu-run-maybe; \
4143
export CARGO_HOME=/usr/local/cargo; \
4244
[ -n "${RUSTUP_URL:-}" ] || RUSTUP_URL="https://static.rust-lang.org/rustup/archive/${RUSTUP_VERSION}/${RUSTUP_ARCH}/rustup-init"; \
4345
curl -O -sSf "$RUSTUP_URL"; \
@@ -51,9 +53,7 @@ RUN set -eux; \
5153
rustc --version; \
5254
rustup set auto-self-update disable; \
5355
echo "$RUST_VERSIONS" | xargs rustup toolchain add --profile minimal; \
56+
rustup component add --toolchain "$default_rust" rustfmt; \
5457
(umask 022 && echo "$RUSTUP_ARCH" >/etc/rust-native-arch)
5558

56-
# Install scripts
57-
COPY rootfiles /
58-
5959
LABEL org.opencontainers.image.description="A pinned Rust toolchain with rustup."

.github/container/rust/rootfiles/usr/local/bin/qemu-run-maybe renamed to .github/container/rust/rootfiles/qemu-run-maybe

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ if [ ! -x "$program" ]; then
1414
program="$(command -v "$program")"
1515
fi
1616

17+
# determine platform-native triple by reading a file we
18+
# wrote at install time
19+
NATIVE_ARCH="$(cat /etc/rust-native-arch)"
20+
1721
case "${CARGO_BUILD_TARGET:-}" in
18-
("$(cat /etc/rust-native-arch)")
22+
("${NATIVE_ARCH?no native architecture saved in /etc/rust-native-arch}")
1923
# the build target is the native architecture
2024
exec "$program" "$@"
2125
;;
@@ -26,7 +30,15 @@ case "${CARGO_BUILD_TARGET:-}" in
2630
exec qemu-arm -- "$program" "$@"
2731
;;
2832
(i686-unknown-linux-*)
29-
exec qemu-i386 -- "$program" "$@"
33+
case "$NATIVE_ARCH" in
34+
(x86_64-unknown-linux-*)
35+
# x86_64 can run i686 without emulation
36+
exec "$program" "$@"
37+
;;
38+
(*)
39+
exec qemu-i386 -- "$program" "$@"
40+
;;
41+
esac
3042
;;
3143
(x86_64-unknown-linux-*)
3244
exec qemu-x86_64 -- "$program" "$@"

.github/container/x86_64-unknown-linux-gnu/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ ENV CARGO_BUILD_TARGET="$RUST_TARGET" \
3232

3333
USER builder
3434

35+
ARG SOURCE_REV=nogit
36+
3537
LABEL org.opencontainers.image.description="A Debian-based Rust cross-compiling environment."
38+
LABEL org.opencontainers.image.revision="$SOURCE_REV"

.github/workflows/container.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See ./.github/container/README.md
2+
3+
name: Rebuild CI containers
4+
5+
on: workflow_dispatch
6+
7+
jobs:
8+
build:
9+
name: Build container images
10+
runs-on: ubuntu-latest
11+
permissions:
12+
packages: write
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Log in to Github Container Registry
20+
run: buildah login ghcr.io/cbs228 --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Build all containers
23+
run: ./.github/container/build.sh --push

0 commit comments

Comments
 (0)