CI: Update push_image workflow

This commit is contained in:
Maschell 2023-04-10 11:44:43 +02:00
parent 47cf34d090
commit c8a077574e

View File

@ -3,23 +3,41 @@ on:
push: push:
branches: branches:
- main - main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
build: build-and-push-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps: steps:
- uses: actions/checkout@master - name: Checkout repository
- name: Get release version uses: actions/checkout@v3
id: get_release_tag - name: Extract Docker metadata
run: | id: meta
echo RELEASE_VERSION=$(echo $(date '+%Y%m%d')) >> $GITHUB_ENV uses: docker/metadata-action@v4
echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//" | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
echo REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $1}' | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with: with:
name: ${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
username: ${{ secrets.DOCKER_USERNAME }} tags: |
password: ${{ secrets.DOCKER_PASSWORD }} type=raw,value={{date 'YYYYMMDD'}}-{{sha}}
snapshot: true type=raw,value={{date 'YYYYMMDD'}}
cache: true type=raw,value=latest
tags: "latest, ${{ env.RELEASE_VERSION }}"
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.CI_PAT_WRITE_PACKAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true