diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8dd4aa2d..3854f033 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,6 +3,9 @@ on: release: types: - created + push: + branches: + - main jobs: push: runs-on: ubuntu-latest @@ -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