43 lines
1.3 KiB
YAML
43 lines
1.3 KiB
YAML
name: Build & push Docker image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '*' # Trigger on push to all branches
|
|
|
|
env:
|
|
IMAGE_NAME: "contact-api" # e.g wavyzz/hello-world
|
|
DOCKERFILE: "./Dockerfile"
|
|
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: https://github.com/actions/checkout@v5
|
|
|
|
- name: Extract branch name
|
|
shell: bash
|
|
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
|
|
id: extract_branch
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: https://github.com/docker/setup-buildx-action@v3
|
|
|
|
- name: Login to private registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: https://${{ secrets.DOCKER_REGISTRY_HOST }}
|
|
username: ${{ secrets.DOCKER_REGISTRY_USER }}
|
|
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: https://github.com/docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: "${{ env.DOCKERFILE }}"
|
|
push: true
|
|
tags: |
|
|
${{ secrets.DOCKER_REGISTRY_HOST }}/${{ env.IMAGE_NAME }}:${{ steps.extract_branch.outputs.branch }}-latest
|
|
${{ secrets.DOCKER_REGISTRY_HOST }}/${{ env.IMAGE_NAME }}:latest
|