Skip to content

Commit

Permalink
docker: CI update and simplification (#3075)
Browse files Browse the repository at this point in the history
* simplify docker gh workflow (see PR for details)
  • Loading branch information
mmacata authored Aug 18, 2023
1 parent 0f13c4d commit 14d056a
Showing 1 changed file with 23 additions and 135 deletions.
158 changes: 23 additions & 135 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,37 @@ name: Docker
#
# Summary
#
# job docker-branch-os-matrix:
# * creates tags latest-alpine, latest-debian and latest-ubuntu for main branch
# * creates tags stable-alpine, stable-debian and stable-ubuntu for releasebranch_8_2
# * creates tags <branch_name>-alpine, <branch_name>-debian and <branch_name>-ubuntu for all triggered branches
#
# job docker-main-latest:
# * creates tag latest for main branch
#
# job docker-release-os-matrix:
# job docker-os-matrix:
# * creates tags <version>-alpine, <version>-debian and <version>-ubuntu for each release
# * creates tags <branch_name>-alpine, <branch_name>-debian and <branch_name>-ubuntu for all triggered branches
# * creates tags current-alpine, current-debian and current-ubuntu for releasebranch_8_3
# * creates tag latest for last stable release with ubuntu os

on:
push:
branches:
- main
- releasebranch_*
- '!releasebranch_7_*'
tags: ['*.*.*']
# tags: ['*.*.*']
paths-ignore: [doc/**]
release:
types: [published]

env:
# Additionally mentioned in docker-sha-release-latest
# as use of variable fails there
DOCKERHUB_REPOSITORY: osgeo/grass-gis

jobs:

# Only run for push to configured branches, do not run for releases.
# Take care of different os. For main branch, created tags are:
# latest-alpine, latest-debian, latest-ubuntu
# For releasebranch_8_2, created tags are:
# stable-alpine, stable-debian, stable-ubuntu
docker-branch-os-matrix:
name: build and push ${{ matrix.os }} for branch
if: startsWith(github.ref, 'refs/heads/') && github.repository_owner == 'OSGeo'
# Run for push to configured branches and all published releases.
# Take care of different os.
# For main branch, created tags are:
# main-alpine, main-debian, main-ubuntu
# For releasebranch_8_3, created tags are:
# current-alpine, current-debian, current-ubuntu,
# releasebranch_8_3-alpine, releasebranch_8_3-debian, releasebranch_8_3-ubuntu
# For a release, e.g. 8.3.0, created tags are:
# 8.3.0-alpine, 8.3.0-debian, 8.3.0-ubuntu and latest (with ubuntu)
docker-os-matrix:
name: build and push ${{ matrix.os }} for ${{ github.ref }}
if: github.repository_owner == 'OSGeo'
runs-on: ubuntu-latest

strategy:
Expand All @@ -58,125 +52,19 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- id: meta
name: Create tag name
run: |
if [ "$GITHUB_REF" == "refs/heads/main" ]
then
TAG_PREFIX=latest
elif [ "$GITHUB_REF" == "refs/heads/releasebranch_8_2" ]
then
TAG_PREFIX=stable
else
# use branch name as TAG_PREFIX
TAG_PREFIX=`echo $GITHUB_REF|cut -d '/' -f3`
fi
tag="${DOCKERHUB_REPOSITORY}:${TAG_PREFIX}-${{ matrix.os }}"
echo "tags=$tag" >> $GITHUB_OUTPUT
- name: Log
run: |
echo ${{ steps.meta.outputs.tags }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
push: true
pull: true
context: .
tags: ${{ steps.meta.outputs.tags }}
file: docker/${{ matrix.os }}/Dockerfile
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}


# Only run for push to main branch
# Take care of tag latest
# This job needs to build the configured image (ubuntu)
# again for main branch to create latest tag.
docker-main-latest:
name: build and push latest for main branch
if: github.ref == 'refs/heads/main' && github.repository_owner == 'OSGeo'
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- id: meta
name: Create tag name
run: |
tag=${DOCKERHUB_REPOSITORY}:latest
echo "tags=$tag" >> $GITHUB_OUTPUT
- name: Log
run: echo ${{ steps.meta.outputs.tags }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
push: true
pull: true
context: .
tags: ${{ steps.meta.outputs.tags }}
file: docker/ubuntu/Dockerfile
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}


# run for releases, take care of release tags
docker-release-os-matrix:
name: build and push release for ${{ matrix.os }}
if: startsWith(github.ref, 'refs/tags/') && github.repository_owner == 'OSGeo'
runs-on: ubuntu-latest
strategy:
matrix:
os:
- alpine
- debian
- ubuntu
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create image and tag name
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# images: ${DOCKERHUB_REPOSITORY}
images: osgeo/grass-gis
tags: |
type=ref,event=tag
type=ref,event=branch
type=raw,value=current,enable=${{ github.ref == format('refs/heads/{0}', 'releasebranch_8_3') }}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/8.3') && matrix.os == 'ubuntu' }},suffix=
flavor: |
latest=false
- id: meta2
name: Update tag name
run: |
tag="${{ steps.meta.outputs.tags }}-${{ matrix.os }}"
echo "tags=$tag" >> $GITHUB_OUTPUT
- name: Log
run: |
echo ${{ steps.meta2.outputs.tags }}
suffix=-${{ matrix.os }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand All @@ -193,7 +81,7 @@ jobs:
push: true
pull: true
context: .
tags: ${{ steps.meta2.outputs.tags }}
tags: ${{ steps.meta.outputs.tags }}
file: docker/${{ matrix.os }}/Dockerfile
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

0 comments on commit 14d056a

Please sign in to comment.