|
| 1 | +name: Reusable workflow to build and push docker container to github container registry |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + GIT_AUTH_TOKEN: |
| 7 | + required: false |
| 8 | + description: 'PAT to publish image' |
| 9 | + inputs: |
| 10 | + container-name: |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + context: |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + default: '.' |
| 17 | + file: |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: 'Dockerfile' |
| 21 | + branch: |
| 22 | + type: string |
| 23 | + default: 'main' |
| 24 | + |
| 25 | +env: |
| 26 | + REGISTRY: ghcr.io/clubcedille |
| 27 | + |
| 28 | +jobs: |
| 29 | + build-and-push: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Check Out Repo |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v3 |
| 37 | + |
| 38 | + - name: Log in to the Container registry |
| 39 | + uses: docker/login-action@v3 |
| 40 | + with: |
| 41 | + registry: ${{ env.REGISTRY }} |
| 42 | + username: ${{ github.actor }} |
| 43 | + password: ${{ secrets.GIT_AUTH_TOKEN }} |
| 44 | + |
| 45 | + - name: Extract Docker metadata |
| 46 | + id: meta |
| 47 | + uses: docker/metadata-action@v5 |
| 48 | + with: |
| 49 | + images: ${{ env.REGISTRY }}/${{ inputs.container-name }} |
| 50 | + tags: | |
| 51 | + type=ref,event=branch |
| 52 | + type=sha |
| 53 | + type=raw,value=${{ inputs.branch }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 54 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} |
| 55 | +
|
| 56 | + - name: Build and push Docker image |
| 57 | + uses: docker/build-push-action@v6 |
| 58 | + with: |
| 59 | + context: ${{ inputs.context }} |
| 60 | + file: ${{ inputs.file }} |
| 61 | + push: true |
| 62 | + platforms: linux/amd64,linux/arm64 |
| 63 | + tags: ${{ steps.meta.outputs.tags }} |
| 64 | + cache-from: type=gha |
| 65 | + cache-to: type=gha,mode=max |
| 66 | + secrets: | |
| 67 | + GIT_AUTH_TOKEN = ${{ secrets.GIT_AUTH_TOKEN }} |
| 68 | + continue-on-error: true |
0 commit comments