Skip to content

Publish Docker image #45

Publish Docker image

Publish Docker image #45

name: Publish Docker image
# To MaastrichtU-IDS GitHub Container Registry
# https://github.com/orgs/MaastrichtU-IDS/packages
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'Dockerfile'
- '.github/workflows/publish-docker.yml'
schedule:
- cron: '0 3 * * 1'
# Monday at 3:00 GMT+1
env:
IMAGE_NAME: ubuntu
permissions:
contents: write
packages: write
actions: write
jobs:
# Build and push image to ghcr.io
build-and-publish-latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
#- name: Build image
# run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
#- name: Log into GitHub Container Registry
# TODO: Create a token with `read:packages` and `write:packages` scopes
# And save it as an Actions secret CONTAINER_REGISTRY_GITHUB_TOKEN
# run: echo "${{ secrets.CONTAINER_REGISTRY_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Login to the GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
logout: false
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/ubuntu
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
#VERSION=latest
#echo IMAGE_ID=$IMAGE_ID
#echo VERSION=$VERSION
[ "$VERSION" == "main" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and publish main latest Docker image
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
pull: true
push: true
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
#docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
#docker push $IMAGE_ID:$VERSION