Skip to content

Commit

Permalink
Merge amd64 and arm64 docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Mar 30, 2023
1 parent eae422a commit 53dfa94
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 46 deletions.
19 changes: 3 additions & 16 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -47,22 +39,20 @@ jobs:
uses: docker/[email protected]
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:
Expand All @@ -73,15 +63,13 @@ jobs:

- name: Init database
# arm64 cannot be tested just yet
if: matrix.platform == 'linux/amd64'
shell: bash
run: tests/fixtures/initdb.sh
env:
DATABASE_URL: ${{ steps.pg.outputs.connection-uri }}

- 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=-
Expand All @@ -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
26 changes: 22 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
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

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 \
Expand Down
24 changes: 0 additions & 24 deletions arm64.Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 53dfa94

Please sign in to comment.