Skip to content

Commit

Permalink
docker: Build docker images on every push to main
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Feb 29, 2024
1 parent 552a15a commit 8c2c8c1
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,50 @@ on:
release:
types:
- created
push:
branches:
- main
jobs:
push:
strategy:
matrix:
package: [web, workers]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image
run: |
OWNER=$(echo ${{github.repository_owner}} | tr '[A-Z]' '[a-z]')
TAG="${{github.event.release.name}}"
docker build . --target workers --tag ghcr.io/$OWNER/hoarder-workers:$TAG -f docker/Dockerfile
docker build . --target web --tag ghcr.io/$OWNER/hoarder-web:$TAG -f docker/Dockerfile
- name: Login to Github Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build ${{ matrix.package }}
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: ${{ matrix.package }}
push: true
tags: ghcr.io/mohamedbassem/hoarder-${{ matrix.package }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Push image
run: |
OWNER=$(echo ${{github.repository_owner}} | tr '[A-Z]' '[a-z]')
TAG="${{github.event.release.name}}"
docker tag ghcr.io/$OWNER/hoarder-workers:$TAG ghcr.io/$OWNER/hoarder-workers:latest
docker tag ghcr.io/$OWNER/hoarder-web:$TAG ghcr.io/$OWNER/hoarder-web:latest
docker push ghcr.io/$OWNER/hoarder-workers:$TAG
docker push ghcr.io/$OWNER/hoarder-web:$TAG
docker push ghcr.io/$OWNER/hoarder-workers:latest
docker push ghcr.io/$OWNER/hoarder-web:latest
- name: Build ${{ matrix.package }} (release)
uses: docker/build-push-action@v5
if: github.event_name == 'release'
with:
context: .
file: docker/Dockerfile
target: ${{ matrix.package }}
push: true
tags: ghcr.io/mohamedbassem/hoarder-${{ matrix.package }}:${{github.event.release.name}}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 8c2c8c1

Please sign in to comment.