Merge branch 'master' of github.com:FNNDSC/pfms #19
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
# Automatically build container images for every push to master, | |
# and also every version tag in the form X.X.X[.*]. | |
# Built images are pushed to both docker.io and ghcr.io | |
name: Build | |
on: | |
push: | |
branches: [ master ] | |
tags: | |
- "[0-9]+.[0-9]+.[0-9]+*" | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Decide image tags | |
id: info | |
shell: python | |
run: | | |
import os | |
import itertools | |
def join_tag(t): | |
registry, repo, tag = t | |
return f'{registry}/{repo}:{tag}'.lower() | |
registries = ['docker.io', 'ghcr.io'] | |
repos = ['${{ github.repository }}'] | |
if '${{ github.ref_type }}' == 'branch': | |
tags = ['latest'] | |
elif '${{ github.ref_type }}' == 'tag': | |
tag = '${{ github.ref_name }}' | |
version = tag[1:] if tag.startswith('v') else tag | |
tags = ['latest', version] | |
else: | |
tags = [] | |
product = itertools.product(registries, repos, tags) | |
tags_csv = ','.join(map(join_tag, product)) | |
outputs = { | |
'tags_csv' : tags_csv, | |
'push' : 'true' if tags_csv else 'false', | |
} | |
with open(os.environ['GITHUB_OUTPUT'], 'a') as out: | |
for k, v in outputs.items(): | |
out.write(f'{k}={v}\n') | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: network=host | |
- name: Login to DockerHub | |
if: (github.event_name == 'push' || github.event_name == 'release') && contains(steps.info.outputs.tags_csv, 'docker.io') | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
if: (github.event_name == 'push' || github.event_name == 'release') && contains(steps.info.outputs.tags_csv, 'ghcr.io') | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@v4 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
if: (github.event_name == 'push' || github.event_name == 'release') | |
with: | |
context: . | |
file: ./Dockerfile | |
tags: ${{ steps.info.outputs.tags_csv }} | |
platforms: linux/amd64 | |
push: ${{ steps.info.outputs.push }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Update DockerHub description | |
uses: peter-evans/dockerhub-description@v4 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
short-description: 'A bridge between clinical services and pflink' | |
readme-filepath: ./README.md |