misc: refactor build workflow using GitHub Actions

pull/7734/head
Carl Richter 4 years ago
parent 9082a54c43
commit 4e28d821a5

@ -1,4 +1,4 @@
name: Docker name: docker-build
on: on:
push: push:
@ -6,56 +6,87 @@ on:
- tyclipso - tyclipso
tags: tags:
- "*.*.*.*" - v*
# Run tests for any PRs. # Run tests for any PRs.
pull_request: pull_request:
env: env:
IMAGE_NAME: wiki REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
# Test building the docker image on pull requests
test-build:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Build image
uses: docker/build-push-action@v2
with:
push: false
context: .
file: { context }/dev/build/Dockerfile
# Build image and push image to GitHub Packages. # Build image and push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/ # See also https://docs.docker.com/docker-hub/builds/
push: build-and-push-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event_name == 'push' if: ${{ github.event_name == 'push' }}
permissions: permissions:
contents: read contents: read
packages: write packages: write
steps: steps:
- uses: actions/checkout@v2 - name: Checkout repository
uses: actions/checkout@v2
- name: Build image - name: Log in to the Container registry
run: docker build . --file dev/build/Dockerfile --tag $IMAGE_NAME uses: docker/login-action@v1
with:
- name: Log into GitHub Container Registry registry: ${{ env.REGISTRY }}
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to GitHub Container Registry
run: | - name: Extract metadata for Docker (tag)
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME id: meta_tag
IMAGE_ID_LONG=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME/$IMAGE_NAME if: startsWith(github.ref, 'refs/tags/v')
# Change all uppercase to lowercase uses: docker/metadata-action@v3
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') with:
IMAGE_ID_LONG=$(echo $IMAGE_ID_LONG | tr '[A-Z]' '[a-z]') images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Strip git ref prefix from version tags: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') type=ref,event=tag
# Set Docker rolling tags bleeding/latest
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_ROLLING=latest - name: Extract metadata for Docker (bleeding)
[ "$VERSION" == "tyclipso" ] && VERSION_ROLLING=bleeding id: meta_bleeding
# Set Commit Short SHA (first seven char) as VERSION for bleeding builds if: false == startsWith(github.ref, 'refs/tags/v')
[ "$VERSION" == "tyclipso" ] && VERSION=${GITHUB_SHA:0:7} uses: docker/metadata-action@v3
echo IMAGE_ID=$IMAGE_ID with:
echo VERSION=$VERSION images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
echo VERSION_ROLLING=$VERSION_ROLLING tags: |
docker tag $IMAGE_NAME $IMAGE_ID_LONG:$VERSION type=sha
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID_LONG:$VERSION_ROLLING - name: Build and push Docker image (tag)
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_ROLLING if: startsWith(github.ref, 'refs/tags/v')
docker push $IMAGE_ID_LONG:$VERSION uses: docker/build-push-action@v2
docker push $IMAGE_ID:$VERSION with:
docker push $IMAGE_ID_LONG:$VERSION_ROLLING push: true
docker push $IMAGE_ID:$VERSION_ROLLING context: .
file: {context}/dev/build/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
- name: Build and push Docker image (bleeding)
if: false == startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v2
with:
push: true
context: .
file: { context }/dev/build/Dockerfile
tags: bleeding,${{ steps.meta.outputs.tags }}

Loading…
Cancel
Save