Skip to content

Commit

Permalink
Merge pull request #68 from palfrey/multiarch
Browse files Browse the repository at this point in the history
Add arm64 build
  • Loading branch information
palfrey authored Dec 31, 2023
2 parents 0a0d177 + d43bf57 commit 980ff98
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
38 changes: 30 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,30 +39,52 @@ 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@v4
- 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
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 --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
if: ${{ matrix.build_arch == 'amd64'}}
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
18 changes: 6 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 980ff98

Please sign in to comment.