Skip to content

Commit

Permalink
Update docker-publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoesbergen authored Apr 7, 2024
1 parent bf722ff commit c51bef5
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
- uses: actions/checkout@v4

- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: Dockerfile
context: .
push: true
tags: ghcr.io/djoamersfoort/djo-inventory/djo-inventory:latest

# 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" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Redeploy
run: |
curl https://portainer.djoamersfoort.nl/hooks/update-docker-image?stack=inventory_djoamersfoort_nl -H "X-Token: ${{ secrets.WEBHOOK_TOKEN }}"
- name: Clean up old images
uses: actions/delete-package-versions@v5
with:
package-name: 'djo-inventory/djo-inventory'
package-type: 'container'
min-versions-to-keep: 5
delete-only-untagged-versions: 'true'

0 comments on commit c51bef5

Please sign in to comment.