Build and Push Docker Image with new Tag #49
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: Build and Push Docker Image with new Tag | |
on: | |
push: | |
tags: | |
- v[0-9]+.[0-9]+.[0-9]+ # Production Tag | |
- v[0-9]+.[0-9]+.[0-9]+.[0-9]+ # Production Tag with Incremented Doc | |
- v[0-9]+.[0-9]+.[0-9]+.itb.[0-9]+ # Development Tag | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: startsWith(github.repository, 'osg-htc/') | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: 'recursive' | |
ref: ${{ github.ref }} | |
- name: Generate tag list | |
id: generate-tag-list | |
run: | | |
if [ -z "${{ inputs.tag }}" ] | |
then | |
GITHUB_TAG=${GITHUB_REF##*/} | |
else | |
GITHUB_TAG=${{ inputs.tag }} | |
fi | |
echo "Master SHA:" | |
echo $(git rev-parse $GITHUB_REF_NAME) | |
echo "Current SHA:" | |
echo $(git rev-parse HEAD) | |
echo $GITHUB_TAG | |
docker_repo=${GITHUB_REPOSITORY/osg-htc/opensciencegrid} | |
# If this is a itb release lets tag it as such | |
if [[ $GITHUB_TAG == *"itb"* ]]; | |
then | |
ITB_SUFFIX="-itb" | |
else | |
ITB_SUFFIX="" | |
fi | |
tag_list=() | |
for registry in hub.opensciencegrid.org; do | |
for image_tag in "latest${ITB_SUFFIX}" "${GITHUB_TAG}" "$(git rev-parse HEAD)"; do | |
tag_list+=("$registry/$docker_repo":"$image_tag-$(date +%s)") | |
done | |
done | |
# This causes the tag_list array to be comma-separated below, | |
# which is required for build-push-action | |
IFS=, | |
echo "taglist=${tag_list[*]}" >> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to OSG Harbor | |
uses: docker/login-action@v1 | |
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/[email protected] | |
with: | |
context: . | |
push: true | |
tags: "${{ steps.generate-tag-list.outputs.taglist }}" |