From c8a077574e81ffc2b37962efc075931895a16b4d Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 10 Apr 2023 11:44:43 +0200 Subject: [PATCH] CI: Update push_image workflow --- .github/workflows/push_image.yml | 52 +++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index 3898a85..114c222 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -3,23 +3,41 @@ on: push: branches: - main +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: - build: + build-and-push-image: runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: - - uses: actions/checkout@master - - name: Get release version - id: get_release_tag - run: | - echo RELEASE_VERSION=$(echo $(date '+%Y%m%d')) >> $GITHUB_ENV - 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: - name: ${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }} - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - snapshot: true - cache: true - tags: "latest, ${{ env.RELEASE_VERSION }}" \ No newline at end of file + - name: Checkout repository + uses: actions/checkout@v3 + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value={{date 'YYYYMMDD'}}-{{sha}} + type=raw,value={{date 'YYYYMMDD'}} + type=raw,value=latest + + - 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 \ No newline at end of file