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 fb682c1
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
release:
types:
- created
push:
branches:
- main
jobs:
push:
runs-on: ubuntu-latest
Expand All @@ -12,25 +15,58 @@ jobs:

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

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

- name: Build web
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: web
push: true
tags: ghcr.io/mohamedbassem/hoarder-web:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- 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: Build workers
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: workers
push: true
tags: ghcr.io/mohamedbassem/hoarder-workers:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- 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 web (release)
uses: docker/build-push-action@v5
if: github.event_name == 'release'
with:
context: .
file: docker/Dockerfile
target: web
push: true
tags: ghcr.io/mohamedbassem/hoarder-web:${{github.event.release.name}}
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 workers (release)
uses: docker/build-push-action@v5
if: github.event_name == 'release'
with:
context: .
file: docker/Dockerfile
target: workers
push: true
tags: ghcr.io/mohamedbassem/hoarder-workers:${{github.event.release.name}}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit fb682c1

Please sign in to comment.