Skip to content

Build and Push Docker image #101

Build and Push Docker image

Build and Push Docker image #101

name: Build and Push Docker image
on:
push:
branches: [ master ]
repository_dispatch:
types:
- dispatch-build
workflow_dispatch:
jobs:
make-date-tag:
runs-on: ubuntu-latest
outputs:
dtag: ${{ steps.mkdatetag.outputs.dtag }}
steps:
- name: make date tag
id: mkdatetag
run: echo "dtag=$(date +%Y%m%d-%H%M)" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [make-date-tag]
strategy:
fail-fast: False
matrix:
dver: ['8', '9']
repo: ['devel', 'testing', 'release']
series: ['23']
steps:
- uses: actions/checkout@v3
- name: Generate tag list
id: generate-tag-list
env:
EL_VER: ${{ matrix.dver }}
BASE_YUM_REPO: ${{ matrix.repo }}
OSG_RELEASE: ${{ matrix.series }}
TIMESTAMP: ${{ needs.make-date-tag.outputs.dtag }}
run: |
docker_repo=${GITHUB_REPOSITORY/opensciencegrid\/docker-/opensciencegrid/}
tags=()
for registry in hub.opensciencegrid.org docker.io; do
tags+=( $registry/$docker_repo:$OSG_RELEASE-$BASE_YUM_REPO-el$EL_VER )
if [[ $EL_VER == '9' ]]; then
tags+=( $registry/$docker_repo:$OSG_RELEASE-$BASE_YUM_REPO )
if [[ $BASE_YUM_REPO == 'release' ]]; then
tags+=( $registry/$docker_repo:$OSG_RELEASE )
[[ $OSG_RELEASE == '23' ]] && tags+=( $registry/$docker_repo:latest )
else
[[ $OSG_RELEASE == '23' ]] && tags+=( $registry/$docker_repo:$BASE_YUM_REPO )
fi
fi
if [[ $BASE_YUM_REPO == 'release' ]]; then
tags+=( $registry/$docker_repo:$OSG_RELEASE-el$EL_VER )
fi
done
tag_list=$(IFS=,; echo "${tags[*]}")
echo "taglist=$tag_list" >> $GITHUB_OUTPUT
- id: generate-image-base
env:
DVER: ${{ matrix.dver }}
run: |
case "$DVER" in
9) image_base="quay.io/centos/centos:stream9";;
8) image_base="docker.io/library/almalinux:8";;
*) echo "Unknown distro version: $DVER"; exit 1;;
esac
echo "imagebase=${image_base}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to OSG Harbor
uses: docker/[email protected]
with:
registry: hub.opensciencegrid.org
username: ${{ secrets.OSG_HARBOR_ROBOT_USER }}
password: ${{ secrets.OSG_HARBOR_ROBOT_PASSWORD }}
- name: Build and push Docker images
uses: docker/build-push-action@v4
with:
push: true
build-args: |
EL_VER=${{ matrix.dver }}
IMAGE_BASE=${{ steps.generate-image-base.outputs.imagebase }}
BASE_YUM_REPO=${{ matrix.repo }}
OSG_RELEASE=${{ matrix.series }}
BUILDDATE=${{ needs.make-date-tag.outputs.dtag }}
tags: "${{ steps.generate-tag-list.outputs.taglist }}"