Skip to content

Build and push docker image for branch or tag #25

Build and push docker image for branch or tag

Build and push docker image for branch or tag #25

Workflow file for this run

name: Build and push docker image for branch or tag
on:
release:
types: [ released ]
push:
branches: [ '**' ]
jobs:
build-brandr-api-container:
name: Build brandr-api container
runs-on: ubuntu-latest
if: github.repository == 'ScientaNL/brandr-api'
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v4
- name: Set Github environment variables
uses: ScientaNL/[email protected]
- name: DockerHub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_PUBLIC_USERNAME }}
password: ${{ secrets.DOCKERHUB_PUBLIC_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build & push Docker image for branch
uses: docker/build-push-action@v5
with:
file: ./docker/Dockerfile
context: .
build-args: |
- API_VERSION=${{env.GITHUB_REF_NAME_SLUG}}-${{env.GITHUB_SHA_SHORT}}
push: true
tags: scienta/brandr-api:branch-${{env.GITHUB_REF_NAME_SLUG}}
cache-from: |
type=registry,ref=scienta/brandr-api:cache-branch-${{env.GITHUB_REF_NAME_SLUG}}
type=registry,ref=scienta/brandr-api:cache-branch-master
cache-to: type=registry,ref=scienta/brandr-api:cache-branch-${{env.GITHUB_REF_NAME_SLUG}}
- name: Build & push Docker image for release
if: github.event_name == 'release'
uses: docker/build-push-action@v2
with:
file: ./docker/Dockerfile
context: .
push: true
tags: scienta/brandr-api:${{env.GITHUB_REF_NAME_SLUG}}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
- API_VERSION=${{env.GITHUB_REF_NAME_SLUG}}