sandbox/.gitea/workflows/docker.yaml
2025-09-01 18:58:58 +02:00

71 lines
2.1 KiB
YAML

name: Build and push docker image
run-name: Building docker image and push them to git.dacremont.xyz
on:
workflow_dispatch: {}
push:
branches: [ "main" ]
paths:
- 'Dockerfile'
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: git.dacremont.xyz
# gitea.repository as <account>/<repo>
IMAGE_NAME: ${{ gitea.repository }}
jobs:
Build-and-push-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: check docker
run: which docker; echo $$PATH; ls /usr/bin
# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://`.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0`
- name: Restore Docker cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ gitea.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Login against a Docker registry except on PR
# https://`.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.username }}
password: ${{ secrets.TOKEN }}
- name: Build and push docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache