From e18ccb598dc6632be2b040f53d4cb1caad0d2abf Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Tue, 21 Dec 2021 07:11:55 -0300 Subject: [PATCH 1/2] ci: Add manual multi-arch build PoC --- .github/workflows/docker.yml | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..baf1b4dc --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,72 @@ +name: Docker + +on: + workflow_dispatch: {} + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + container_arch_build: + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + tag: amd64 + + - target: armv7-unknown-linux-gnueabihf + tag: arm64 + + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + build-args: TARGET=${{ matrix.target }} + tags: ${{ matrix.tag }} + + manifest_release: + name: Create Manifest Release + needs: [container_arch_build] + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup | Release notes + run: | + docker manifest create "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" \ + --amend "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64" \ + --amend "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64" + + docker manifest annotate "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64" --os linux --arch amd64 + docker manifest annotate "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64" --os linux --arch arm64 + docker manifest push --purge "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" From 75f708d43219df8fe1c3e89d8e4e41c5f5609a32 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Tue, 21 Dec 2021 21:22:55 -0300 Subject: [PATCH 2/2] feat: Go back to common mutli-arch builds --- .github/workflows/docker.yml | 47 ++++++++---------------------------- Dockerfile | 34 ++++++++++++++++---------- 2 files changed, 31 insertions(+), 50 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index baf1b4dc..105794b5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,16 +8,7 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - container_arch_build: - strategy: - matrix: - include: - - target: x86_64-unknown-linux-gnu - tag: amd64 - - - target: armv7-unknown-linux-gnueabihf - tag: arm64 - + build: runs-on: ubuntu-latest permissions: @@ -31,6 +22,12 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Login to DockerHub uses: docker/login-action@v1 with: @@ -42,31 +39,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . + platforms: linux/arm64,linux/amd64 push: true - build-args: TARGET=${{ matrix.target }} - tags: ${{ matrix.tag }} - - manifest_release: - name: Create Manifest Release - needs: [container_arch_build] - runs-on: ubuntu-latest - steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup | Release notes - run: | - docker manifest create "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" \ - --amend "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64" \ - --amend "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64" - - docker manifest annotate "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64" --os linux --arch amd64 - docker manifest annotate "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64" --os linux --arch arm64 - docker manifest push --purge "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index b3c7b3a9..6f7d345b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,39 @@ -# fetch the vendor with the builder platform to avoid qemu issues -FROM --platform=$BUILDPLATFORM rust:1 AS vendors +FROM --platform=linux/amd64 rust:1 as builder-arm64 -WORKDIR /code +RUN apt update && apt upgrade -y +RUN apt install -y g++-arm-linux-gnueabihf libc6-dev-armhf-cross + +ENV RUST_TARGET=armv7-unknown-linux-gnueabihf + +RUN rustup target add armv7-unknown-linux-gnueabihf +RUN rustup toolchain install stable-armv7-unknown-linux-gnueabihf + +ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ + CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ -RUN cargo init -COPY Cargo.toml Cargo.toml -COPY Cargo.lock Cargo.lock -RUN mkdir -p ./.cargo \ - && cargo vendor > ./.cargo/config +FROM --platform=linux/amd64 rust:1 as builder-amd64 -FROM rust:1 as builder +ENV RUST_TARGET=x86_64-unknown-linux-gnu -COPY --from=vendors /code/.cargo /code/.cargo -COPY --from=vendors /code/vendor /code/vendor + + +FROM --platform=linux/amd64 builder-${TARGETARCH} as builder WORKDIR /code COPY . . -RUN cargo install --path . --offline --all-features +RUN cargo build --release --target ${RUST_TARGET} --all-features + +RUN cp /code/target/${RUST_TARGET}/release/oura /oura FROM debian:buster-slim #RUN apt-get update && apt-get install -y extra-runtime-dependencies && rm -rf /var/lib/apt/lists/* -COPY --from=builder /usr/local/cargo/bin/oura /usr/local/bin/oura +COPY --from=builder /oura /usr/local/bin/oura ENTRYPOINT [ "oura" ]