diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dc5e360b..9ffc08bc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -297,6 +297,122 @@ jobs: env: DATABASE_URL: postgres://${{ env.PGUSER }}:${{ env.PGUSER }}@${{ env.PGHOST }}:${{ job.services.postgres.ports[5432] }}/${{ env.PGDATABASE }}?sslmode=${{ matrix.sslmode }} + docker: + name: Build docker images + runs-on: ubuntu-latest + needs: [ build ] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + # https://github.com/docker/setup-qemu-action + with: + platforms: linux/amd64,linux/arm64 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + # https://github.com/docker/setup-buildx-action + with: + install: true + platforms: linux/amd64,linux/arm64 + + - run: rm -rf target_releases + - uses: actions/download-artifact@v3 + with: + name: build-aarch64-unknown-linux-gnu + path: target_releases/linux/arm64 + - uses: actions/download-artifact@v3 + with: + name: build-x86_64-unknown-linux-gnu + path: target_releases/linux/amd64 + - name: Reset permissions + run: chmod -R +x target_releases/ + + - name: Start postgres + uses: nyurik/action-setup-postgis@v1 + id: pg + with: + username: test + password: test + database: test + rights: --superuser + - name: Init database + shell: bash + run: tests/fixtures/initdb.sh + env: + DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} + + - name: Build linux/arm64 Docker image + id: docker_aarch64-unknown-linux-gnu + uses: docker/build-push-action@v5 + # https://github.com/docker/build-push-action + with: + context: . + file: multi-platform.Dockerfile + load: true + tags: ${{ github.repository }}:linux-arm64 + platforms: linux/arm64 + - name: Test linux/arm64 Docker image + run: | + PLATFORM=linux/arm64 + TAG=${{ github.repository }}:linux-arm64 + export MBTILES_BUILD=- + export MBTILES_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests --entrypoint /usr/local/bin/mbtiles $TAG" + export MARTIN_BUILD=- + export MARTIN_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests $TAG" + tests/test.sh + env: + DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} + + - name: Build linux/amd64 Docker image + id: docker_x86_64-unknown-linux-gnu + uses: docker/build-push-action@v5 + # https://github.com/docker/build-push-action + with: + context: . + file: multi-platform.Dockerfile + load: true + tags: ${{ github.repository }}:linux-amd64 + platforms: linux/amd64 + - name: Test linux/amd64 Docker image + run: | + PLATFORM=linux/amd64 + TAG=${{ github.repository }}:linux-amd64 + export MBTILES_BUILD=- + export MBTILES_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests --entrypoint /usr/local/bin/mbtiles $TAG" + export MARTIN_BUILD=- + export MARTIN_BIN="docker run --rm --net host --platform $PLATFORM -e DATABASE_URL -v $PWD/tests:/tests $TAG" + tests/test.sh + env: + DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} + + - name: Login to GitHub Docker registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + # https://github.com/docker/login-action + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5 + # https://github.com/docker/metadata-action + with: + images: ghcr.io/${{ github.repository }} + - name: Push the Docker image + if: github.event_name != 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + file: multi-platform.Dockerfile + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + package: name: Package ${{ matrix.target }} runs-on: ${{ matrix.os }} @@ -372,7 +488,7 @@ jobs: done: name: CI Finished runs-on: ubuntu-latest - needs: [ package ] + needs: [ docker, package ] steps: - name: Finished run: echo "CI finished successfully" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index ec158c3c5..000000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,122 +0,0 @@ -name: Docker - -on: - push: - branches: [ main ] - paths-ignore: - - '**.md' - - 'demo/**' - - 'docs/**' - - 'homebrew-formula/**' - pull_request: - branches: [ main ] - paths-ignore: - - '**.md' - - 'demo/**' - - 'docs/**' - - 'homebrew-formula/**' - release: - types: [ published ] - workflow_dispatch: - -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 - # Arm64 does not publish properly, see #655 - # - platform: linux/arm64 - # file: arm64.Dockerfile - - runs-on: ubuntu-latest - steps: - - - name: Checkout sources - uses: actions/checkout@v4 - - # https://github.com/docker/metadata-action - - name: Docker meta - id: docker_meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/maplibre/martin - - # # https://github.com/docker/setup-qemu-action - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v2.1.0 - # with: - # platforms: linux/arm64,linux/amd64 - - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.0.0 - with: - install: true - # platforms: ${{ matrix.platform }} - - - name: Build the Docker image - id: docker_build - uses: docker/build-push-action@v5 - with: - file: ${{ matrix.file }} - push: false - load: true - tags: ${{ steps.docker_meta.outputs.tags }} - labels: ${{ steps.docker_meta.outputs.labels }} - # platforms: ${{ matrix.platform }} - - - name: Start postgres - # arm64 testing cannot be tested in a cross-platform env - if: matrix.platform == 'linux/amd64' - uses: nyurik/action-setup-postgis@v1 - id: pg - with: - username: test - password: test - database: test - rights: --superuser - - - name: Init database - # arm64 testing cannot be tested in a cross-platform env - 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 testing cannot be tested in a cross-platform env - if: matrix.platform == 'linux/amd64' - run: | - TAG=$(echo '${{ steps.docker_meta.outputs.json }}' | jq -r '.tags[0]') - export MBTILES_BUILD=- - export MBTILES_BIN=- - export MARTIN_BUILD=- - export MARTIN_BIN="docker run --rm --net host -e DATABASE_URL -v $PWD/tests:/tests $TAG" - echo "MARTIN_BIN=$MARTIN_BIN" - tests/test.sh - env: - DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} - - - name: Login to GitHub Docker registry - uses: docker/login-action@v3 - if: ${{ github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork }} - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push the Docker image - if: ${{ github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' }} - uses: docker/build-push-action@v5 - with: - file: ${{ matrix.file }} - push: true - tags: ${{ steps.docker_meta.outputs.tags }} - labels: ${{ steps.docker_meta.outputs.labels }} - # platforms: ${{ matrix.platform }} diff --git a/multi-platform.Dockerfile b/multi-platform.Dockerfile new file mode 100644 index 000000000..e1fe2f4ee --- /dev/null +++ b/multi-platform.Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:latest +ARG TARGETPLATFORM + +LABEL org.opencontainers.image.description="Blazing fast and lightweight tile server with PostGIS, MBTiles, and PMTiles support" +COPY target_releases/$TARGETPLATFORM/* /usr/local/bin + +ENTRYPOINT ["/usr/local/bin/martin"]