Skip to content

Commit

Permalink
let GitHub Actions build & publish the Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Feb 21, 2025
1 parent c6ff432 commit c8aecf3
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build & publish Docker image

on:
push:
branches:
- main

jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4

- name: set up Docker buildx
uses: docker/setup-buildx-action@v3

- name: log into the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: build and push Docker image
uses: docker/build-push-action@v5
with:
load: true
tags: ghcr.io/${{ github.repository }}:ci
# todo: add linux/arm64 once it is supported by the upstream/base image
platforms: linux/amd64
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
cache-from: type=gha
cache-to: type=gha,mode=max

- name: compute Docker image tag
id: docker-tags
# We don't have upstream/base image's tag (or GeoServer version contained, which should be the same) available as a variables, so we must pull it from the image.
# todo: find a cleaner solution
run: |
set -e
set -x
# https://stackoverflow.com/questions/1682442/reading-java-properties-file-from-bash#comment59733051_22857672
# https://stackoverflow.com/a/12524345/1072129
geoserver_version="$(
docker run --rm \
'ghcr.io/${{ github.repository }}:ci' \
/bin/cat \
/usr/local/tomcat/webapps/geoserver/META-INF/maven/org.geoserver.web/gs-web-app/pom.properties \
| sed '/^version=/!d; s///' | tr -d '\n'
)"
echo "tag=$geoserver_version" >>$GITHUB_OUTPUT
- name: build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.docker-tags.outputs.tag }}
platforms: linux/amd64
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit c8aecf3

Please sign in to comment.