Skip to content

change workflow to workflows update build and publish latest #1

change workflow to workflows update build and publish latest

change workflow to workflows update build and publish latest #1

name: Publish Docker image
# To vemonet GitHub Container Registry
# https://github.com/orgs/vemonet/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_PULLED: cellprofiler/cellprofiler:4.2.8
IMAGE_PUSHED: ghcr.io/maastrichtu-library/dsri-nvidia-driver:latest
jobs:
build-and-publish-latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
## Use Actions local caching with buildx
# - name: Cache Docker layers
# uses: actions/cache@v2
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
- name: Login to the GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Generate image ID and version
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/dsri-nvidi-driver
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
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" == "main" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
## Cache: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
- name: Build and publish main latest Docker image
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
pull: true
push: true
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# builder: ${{ steps.buildx.outputs.name }}