only amd64 images will be built we don't need arm64 builds i will make a dedicated repo for arm images
59 lines
1.6 KiB
YAML
59 lines
1.6 KiB
YAML
name: Build and Publish Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
|
|
env:
|
|
REGISTRY: git.home.db123.ir
|
|
NAMESPACE: db1234719
|
|
IMAGE_NAME: nginx-alpine
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-24.04
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
fetch-tags: true
|
|
|
|
- name: Determine version
|
|
id: version
|
|
shell: bash
|
|
run: |
|
|
if [[ "${GITHUB_REF}" =~ ^refs/tags/v(.+) ]]; then
|
|
VERSION="${BASH_REMATCH[1]}"
|
|
else
|
|
VERSION="latest"
|
|
fi
|
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ env.NAMESPACE }}
|
|
password: ${{ secrets.CICD_PASSWORD }}
|
|
|
|
- name: Build & push Docker image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
platforms: linux/amd64
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
|
|
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}
|
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:cache
|
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:cache,mode=max
|