68 lines
2.1 KiB
YAML
68 lines
2.1 KiB
YAML
name: Build and Publish Docker Images
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: ${{ secrets.REGISTRY_URL }}
|
|
NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'zebra-power' }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
service: [backend, frontend]
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Docker Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Ensure repository exists
|
|
run: |
|
|
curl -f -X POST \
|
|
-H "Authorization: token ${{ secrets.REGISTRY_PASSWORD }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"name":"zebra-power","private":false,"description":"Zebra Power Docker Images"}' \
|
|
${{ env.REGISTRY }}/api/v1/user/repos || echo "Repository may already exist"
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/zebra-${{ matrix.service }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=ref,event=tag
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=sha,prefix={{branch}}-,suffix=-{{date 'YYYYMMDD-HHmmss'}},enable={{is_default_branch}}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./${{ matrix.service }}
|
|
file: ./${{ matrix.service }}/Dockerfile
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
- name: Image digest
|
|
run: echo "Image pushed with digest ${{ steps.build.outputs.digest }}" |