Create and publish a Docker image #95
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
name: Create and publish a Docker image | |
on: | |
push: | |
branches: ['master'] | |
workflow_dispatch: | |
schedule: | |
# 6:05am Monday UTC; Sunday night local time | |
- cron: "5 6 * * 1" | |
env: | |
REGISTRY: ghcr.io | |
REPOSITORY: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3.1.0 | |
- name: Set Environmental Variables | |
run: | | |
echo Repository: $REPOSITORY | |
export IMAGE_NAME_2=${REPOSITORY//docker-/} | |
export IMAGE_NAME=${IMAGE_NAME_2,,} | |
echo Image Name: $IMAGE_NAME | |
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV | |
export VERSION=$(git describe --tags --always) | |
echo Version: $VERSION | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
echo Build Date: $BUILD_DATE | |
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV | |
export PYPICLOUD_VERSION_X_Y_Z=$(cat Dockerfile | grep -oP 'PYPICLOUD_VERSION=\K\d+(.\d+(.\d+\w*)?)?') | |
export PYPICLOUD_VERSION_X_Y=$(echo $PYPICLOUD_VERSION_X_Y_Z | cut -f 1-2 -d .) | |
export PYPICLOUD_VERSION_X=$(echo $PYPICLOUD_VERSION_X_Y_Z | cut -f 1 -d .) | |
echo PyPi Cloud Versions: ${PYPICLOUD_VERSION_X} ${PYPICLOUD_VERSION_X_Y} ${PYPICLOUD_VERSION_X_Y_Z} | |
echo "PYPICLOUD_VERSION_X_Y_Z=${PYPICLOUD_VERSION_X_Y_Z}" >> $GITHUB_ENV | |
echo "PYPICLOUD_VERSION_X_Y=${PYPICLOUD_VERSION_X_Y}" >> $GITHUB_ENV | |
echo "PYPICLOUD_VERSION_X=${PYPICLOUD_VERSION_X}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to the (GitHub) Container registry | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=sha | |
- name: Build and push Docker image | |
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
with: | |
context: . | |
build-args: | | |
VERSION=${{ env.VERSION }} | |
COMMIT=${{ github.sha }} | |
URL=${{ github.repositoryUrl }} | |
BRANCH=${{ github.ref_name }} | |
BUILD_DATE=${{ env.BUILD_DATE }} | |
push: true | |
tags: | | |
${{ steps.meta.outputs.tags }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYPICLOUD_VERSION_X_Y_Z }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYPICLOUD_VERSION_X_Y }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYPICLOUD_VERSION_X }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
labels: ${{ steps.meta.outputs.labels }} |