Skip to content

Commit

Permalink
docker build only on merge to main
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelesko committed Aug 13, 2024
1 parent 3d5b5ad commit c85559c
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,36 @@ on:
branches: [ main ]

jobs:
build:
if: github.event_name == 'pull_request'
docker:
runs-on: [self-hosted, Linux, X64]
steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
- name: Login to DockerHub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/DockerfileLatest
push: false
tags: pveleskopglc/chipstar:${{ github.head_ref }}
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
tags: pveleskopglc/chipstar:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

push:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: [self-hosted, Linux, X64]
steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Tag and push Docker image
run: |
docker tag pveleskopglc/chipstar:${{ github.head_ref }} pveleskopglc/chipstar:latest
docker push pveleskopglc/chipstar:latest
cleanup:
needs: [push]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [docker]
runs-on: [self-hosted, Linux, X64]
steps:
- name: Clean up old Docker images
run: |
docker rmi $(docker images -q pveleskopglc/chipstar:${{ github.head_ref }})
docker image prune -af

0 comments on commit c85559c

Please sign in to comment.