From 4e1a7bbe94a7f0b7cb168646bc735e2586c4adba Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 11:52:00 +0000 Subject: [PATCH 1/7] Add arm64 build --- .github/workflows/linux.yml | 27 +++++++++++++++++++++------ Dockerfile | 14 ++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 94247d8..9649663 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -39,30 +39,45 @@ jobs: POSTGRES_PASSWORD: postgres RUST_BACKTRACE: 1 run: cargo test -- --nocapture + + docker: + runs-on: ubuntu-20.04 + #needs: [build_and_test] + strategy: + matrix: + include: + - build_platform: linux/amd64 + build_host: x86_64-unknown-linux-musl + build_arch: amd64 + - build_platform: linux/arm64 + build_host: aarch64-unknown-linux-musl + build_arch: arm64 + steps: + - uses: actions/checkout@v3 - uses: actions/cache@v3 with: path: | /tmp/.buildx-cache key: - buildx-${{ runner.os }}-${{hashFiles('Dockerfile')}} + buildx-${{ matrix.build_host }}-${{hashFiles('Dockerfile')}} - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v2 - name: Docker build run: | - docker buildx build --tag wait_for_db:latest --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max --output=type=docker . + docker buildx build --platform ${{ matrix.build_platform }} --build-arg HOST=${{ matrix.build_host }} --tag wait_for_db:latest --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max --output=type=docker . - name: Docker help test run: | - docker run --name wait_for_db wait_for_db --help + docker run --platform ${{ matrix.build_platform }} --name wait_for_db wait_for_db --help - name: Docker copy run: | - docker cp wait_for_db:/wait_for_db wait-for-db-linux-x86 + docker cp wait_for_db:/wait_for_db wait-for-db-linux-${{ matrix.build_arch}} - name: ldd check run: | - ldd wait-for-db-linux-x86 | grep "statically linked" + ldd wait-for-db-linux-${{ matrix.build_arch}} | grep "statically linked" retVal=$? if [ $retVal -ne 0 ]; then - ldd wait-for-db-linux-x86 + ldd wait-for-db-linux-${{ matrix.build_arch}} echo Found local non-static refs! exit 1 fi diff --git a/Dockerfile b/Dockerfile index 4cd3b52..54d80a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,17 @@ -FROM alpine:3.13 as builder +FROM alpine:3.19 as builder +ARG HOST=x86_64-unknown-linux-musl RUN apk add --no-cache rustup gcc file unixodbc-dev unixodbc-static libltdl-static musl-dev -RUN rustup-init -y --default-host x86_64-unknown-linux-musl --profile minimal +RUN rustup-init -y --default-host $HOST --profile minimal ENV PATH=$PATH:/root/.cargo/bin WORKDIR /app ADD . ./ -RUN cargo build --release --target=x86_64-unknown-linux-musl -RUN file ./target/x86_64-unknown-linux-musl/release/wait_for_db -RUN ls -lh ./target/x86_64-unknown-linux-musl/release/wait_for_db +RUN cargo build --release --target=$HOST +RUN file ./target/$HOST/release/wait_for_db +RUN ls -lh ./target/$HOST/release/wait_for_db FROM scratch -COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/wait_for_db /wait_for_db +ARG HOST=x86_64-unknown-linux-musl +COPY --from=builder /app/target/$HOST/release/wait_for_db /wait_for_db ENTRYPOINT ["/wait_for_db"] From c25450aa8c6e1be055660229c43998d4745ca0c5 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 12:00:29 +0000 Subject: [PATCH 2/7] Update getrandom for musl open64 fix --- Cargo.lock | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e19e8d..9ce0636 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,13 +329,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -412,9 +412,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "linux-raw-sys" @@ -469,7 +469,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys", ] @@ -1117,12 +1117,6 @@ dependencies = [ "url", ] -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" From 77e47bafb3cf8ec64b718a2250e04c8c9df436e7 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 12:02:08 +0000 Subject: [PATCH 3/7] Upgrade to newer build actions --- .github/workflows/linux.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 9649663..4802402 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -19,7 +19,7 @@ jobs: sudo pg_ctlcluster 14 main start || true sudo pg_lsclusters sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy @@ -53,7 +53,7 @@ jobs: build_host: aarch64-unknown-linux-musl build_arch: arm64 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/cache@v3 with: path: | @@ -62,7 +62,9 @@ jobs: buildx-${{ matrix.build_host }}-${{hashFiles('Dockerfile')}} - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 + with: + platforms: ${{ matrix.build_platform }} - name: Docker build run: | docker buildx build --platform ${{ matrix.build_platform }} --build-arg HOST=${{ matrix.build_host }} --tag wait_for_db:latest --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max --output=type=docker . From d73cea8f747985ede4501480273ece20d06cd000 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 15:33:19 +0000 Subject: [PATCH 4/7] Only run the checks on amd64 --- .github/workflows/linux.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 4802402..05dfdbb 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -69,17 +69,20 @@ jobs: run: | docker buildx build --platform ${{ matrix.build_platform }} --build-arg HOST=${{ matrix.build_host }} --tag wait_for_db:latest --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max --output=type=docker . - name: Docker help test + if: ${{ matrix.build_arch == 'amd64'}} run: | docker run --platform ${{ matrix.build_platform }} --name wait_for_db wait_for_db --help - name: Docker copy + if: ${{ matrix.build_arch == 'amd64'}} run: | - docker cp wait_for_db:/wait_for_db wait-for-db-linux-${{ matrix.build_arch}} + docker cp wait_for_db:/wait_for_db wait-for-db-linux-${{ matrix.build_arch }} - name: ldd check + if: ${{ matrix.build_arch == 'amd64'}} run: | - ldd wait-for-db-linux-${{ matrix.build_arch}} | grep "statically linked" + ldd wait-for-db-linux-${{ matrix.build_arch }} | grep "statically linked" retVal=$? if [ $retVal -ne 0 ]; then - ldd wait-for-db-linux-${{ matrix.build_arch}} + ldd wait-for-db-linux-${{ matrix.build_arch }} echo Found local non-static refs! exit 1 fi From 4cc397f2cfdd2b3e4bd2d82d48644bf9e34a5d1d Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 16:18:51 +0000 Subject: [PATCH 5/7] Setup Qemu for multi-arch run --- .github/workflows/linux.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 05dfdbb..3f0264b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -65,19 +65,20 @@ jobs: uses: docker/setup-buildx-action@v3 with: platforms: ${{ matrix.build_platform }} + - name: Setup Qemu + if: ${{ matrix.build_arch != 'amd64'}} + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - name: Docker build run: | docker buildx build --platform ${{ matrix.build_platform }} --build-arg HOST=${{ matrix.build_host }} --tag wait_for_db:latest --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max --output=type=docker . - name: Docker help test - if: ${{ matrix.build_arch == 'amd64'}} run: | docker run --platform ${{ matrix.build_platform }} --name wait_for_db wait_for_db --help - name: Docker copy - if: ${{ matrix.build_arch == 'amd64'}} run: | docker cp wait_for_db:/wait_for_db wait-for-db-linux-${{ matrix.build_arch }} - name: ldd check - if: ${{ matrix.build_arch == 'amd64'}} run: | ldd wait-for-db-linux-${{ matrix.build_arch }} | grep "statically linked" retVal=$? From 23adbcba3123109d49f8e327b6ee9708a2b8cca1 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 16:50:04 +0000 Subject: [PATCH 6/7] Skip static check for arm64 build --- .github/workflows/linux.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 3f0264b..1d4fb2a 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -79,6 +79,7 @@ jobs: run: | docker cp wait_for_db:/wait_for_db wait-for-db-linux-${{ matrix.build_arch }} - name: ldd check + if: ${{ matrix.build_arch == 'amd64'}} run: | ldd wait-for-db-linux-${{ matrix.build_arch }} | grep "statically linked" retVal=$? From d43bf57e16b07611ee8d1d1f4893bf2c68fcc813 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 31 Dec 2023 17:02:30 +0000 Subject: [PATCH 7/7] build/test first, then Docker --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 1d4fb2a..7b76b27 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -42,7 +42,7 @@ jobs: docker: runs-on: ubuntu-20.04 - #needs: [build_and_test] + needs: [build_and_test] strategy: matrix: include: