60 lines
2.0 KiB
YAML
60 lines
2.0 KiB
YAML
name: Build and Push Docker Image
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
DEFAULT_BRANCH: main
|
|
REGISTRY_ORG: allucanget
|
|
REGISTRY_IMAGE_NAME: calminer
|
|
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Collect workflow metadata
|
|
id: meta
|
|
shell: bash
|
|
run: |
|
|
ref_name="${GITHUB_REF_NAME:-${GITHUB_REF##*/}}"
|
|
event_name="${GITHUB_EVENT_NAME:-}"
|
|
sha="${GITHUB_SHA:-}"
|
|
|
|
if [ "$ref_name" = "${DEFAULT_BRANCH:-main}" ]; then
|
|
echo "on_default=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "on_default=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
echo "ref_name=$ref_name" >> "$GITHUB_OUTPUT"
|
|
echo "event_name=$event_name" >> "$GITHUB_OUTPUT"
|
|
echo "sha=$sha" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Set up QEMU and Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea registry
|
|
if: ${{ steps.meta.outputs.on_default == 'true' }}
|
|
uses: docker/login-action@v3
|
|
continue-on-error: true
|
|
with:
|
|
registry: ${{ env.REGISTRY_URL }}
|
|
username: ${{ env.REGISTRY_USERNAME }}
|
|
password: ${{ env.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: ${{ steps.meta.outputs.on_default == 'true' && steps.meta.outputs.event_name != 'pull_request' && (env.REGISTRY_URL != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '') }}
|
|
tags: |
|
|
${{ env.REGISTRY_URL }}/${{ env.REGISTRY_ORG }}/${{ env.REGISTRY_IMAGE_NAME }}:latest
|
|
${{ env.REGISTRY_URL }}/${{ env.REGISTRY_ORG }}/${{ env.REGISTRY_IMAGE_NAME }}:${{ steps.meta.outputs.sha }}
|