diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7f6f341f5..c90078798 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,14 +15,6 @@ jobs: docker: # Don't change this name - it is used by the merge protection rules name: Build ${{ matrix.platform }} docker image - strategy: - fail-fast: true - matrix: - include: - - platform: linux/amd64 - file: Dockerfile - - platform: linux/arm64 - file: arm64.Dockerfile runs-on: ubuntu-latest steps: @@ -47,22 +39,20 @@ jobs: uses: docker/setup-buildx-action@v2.5.0 with: install: true - platforms: ${{ matrix.platform }} + platforms: linux/arm64,linux/amd64 - name: Build the Docker image id: docker_build uses: docker/build-push-action@v4 with: - file: ${{ matrix.file }} push: false load: true tags: ${{ steps.docker_meta.outputs.tags }} labels: ${{ steps.docker_meta.outputs.labels }} - platforms: ${{ matrix.platform }} + platforms: linux/arm64,linux/amd64 - name: Start postgres # arm64 cannot be tested just yet - if: matrix.platform == 'linux/amd64' uses: nyurik/action-setup-postgis@v1 id: pg with: @@ -73,7 +63,6 @@ jobs: - name: Init database # arm64 cannot be tested just yet - if: matrix.platform == 'linux/amd64' shell: bash run: tests/fixtures/initdb.sh env: @@ -81,7 +70,6 @@ jobs: - name: Test Docker image # arm64 cannot be tested just yet - if: matrix.platform == 'linux/amd64' run: | TAG=$(echo '${{ steps.docker_meta.outputs.json }}' | jq -r '.tags[0]') export MARTIN_BUILD=- @@ -103,9 +91,8 @@ jobs: if: ${{ github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' }} uses: docker/build-push-action@v4 with: - file: ${{ matrix.file }} push: true load: false tags: ${{ steps.docker_meta.outputs.tags }} labels: ${{ steps.docker_meta.outputs.labels }} - platforms: ${{ matrix.platform }} + platforms: linux/arm64,linux/amd64 diff --git a/Dockerfile b/Dockerfile index 71ffdf5e8..267904e5f 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ -FROM rust:alpine as builder +# syntax=docker/dockerfile:1 + +# This dockerfile must be ran with docker buildx build + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +FROM --platform=$BUILDPLATFORM rust:alpine as builder +ARG TARGETPLATFORM +ARG BUILDPLATFORM WORKDIR /usr/src/martin @@ -6,14 +15,23 @@ RUN apk update \ && apk add --no-cache openssl-dev musl-dev perl build-base COPY . . -RUN CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse cargo build --release --features=vendored-openssl - +RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + echo "Building on '$BUILDPLATFORM' for ARM64"; \ + export CFLAGS=-mno-outline-atomics; \ + else \ + echo "Building on '$BUILDPLATFORM' for unrecognized target platform '$TARGETPLATFORM'"; \ + fi \ + && export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse \ + && env | sort | tee /build_log \ + && cargo build --release --features=vendored-openssl FROM alpine:latest LABEL org.opencontainers.image.description="Blazing fast and lightweight tile server with PostGIS, MBTiles, and PMTiles support" -RUN apk add --no-cache libc6-compat +COPY --from=builder /build_log /build_log +RUN env | sort | tee /build_log2 \ + && apk add --no-cache libc6-compat COPY --from=builder \ /usr/src/martin/target/release/martin \ diff --git a/arm64.Dockerfile b/arm64.Dockerfile deleted file mode 100644 index 4912078d2..000000000 --- a/arm64.Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM rust:1.68-bullseye as builder - -WORKDIR /usr/src/martin - -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - libssl-dev \ - perl \ - && rm -rf /var/lib/apt/lists/* - -COPY . . -RUN CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse cargo build --release --features=vendored-openssl - - -FROM debian:bullseye-slim - -LABEL org.opencontainers.image.description="Blazing fast and lightweight tile server with PostGIS, MBTiles, and PMTiles support" - -COPY --from=builder \ - /usr/src/martin/target/release/martin \ - /usr/local/bin/ - -EXPOSE 3000 -ENTRYPOINT ["/usr/local/bin/martin"] diff --git a/justfile b/justfile index 267a7ae01..e5bae8f29 100644 --- a/justfile +++ b/justfile @@ -145,9 +145,9 @@ coverage FORMAT='html': open "$OUTPUT_RESULTS_DIR/index.html" fi -# Build martin docker image +# Build martin docker image (amd64) docker-build: - docker build -t ghcr.io/maplibre/martin . + docker build --build-arg BUILDPLATFORM=linux/amd64 -t ghcr.io/maplibre/martin . # Build and run martin docker image docker-run *ARGS: