misc fixes & improvements #208
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: docker_images | |
on: | |
push: | |
pull_request: | |
schedule: [{cron: "14 14 * * TUE"}] # Every Tuesday at 14:14 | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha || github.ref }} # fix SHA | |
- name: List all images | |
id: metadata | |
run: | | |
echo "images=$( | |
find -name Dockerfile -print0 | xargs -0 -II dirname "I" | sed 's#./##g' | jq -Rsc 'split("\n")[:-1]' | |
)" >> $GITHUB_OUTPUT | |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
outputs: | |
images: ${{ steps.metadata.outputs.images }} | |
sha: ${{ steps.metadata.outputs.sha_short }} | |
build: | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
image: ${{ fromJson(needs.setup.outputs.images) }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-buildx-action@v2 | |
# Unused | |
# - name: Login to DockerHub | |
# uses: docker/login-action@v2 | |
# with: | |
# username: ${{ secrets.DOCKERHUB_USERNAME }} | |
# password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to Harbor | |
uses: docker/login-action@v2 | |
with: | |
registry: harbor.stfc.ac.uk | |
username: ${{ secrets.HARBOR_USERNAME }} | |
password: ${{ secrets.HARBOR_TOKEN }} | |
- name: Build & push to prod | |
if: ${{ github.ref == 'refs/heads/master' }} | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
context: "{{defaultContext}}:${{ matrix.image }}" | |
tags: "harbor.stfc.ac.uk/stfc-cloud/${{ matrix.image }}:latest" | |
- name: Build & push to staging | |
if: ${{ github.ref != 'refs/heads/master' }} | |
uses: docker/build-push-action@v3 | |
with: | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
push: true | |
context: "{{defaultContext}}:${{ matrix.image }}" | |
tags: "harbor.stfc.ac.uk/stfc-cloud-staging/${{ matrix.image }}:${{ needs.setup.outputs.sha }}" | |
- name: Inform of tagged name | |
if: ${{ github.ref != 'refs/heads/master' }} | |
run: echo "::notice title=published::harbor.stfc.ac.uk/stfc-cloud-staging/${{ matrix.image }}:${{ needs.setup.outputs.sha }}" |