94 lines
2.9 KiB
YAML
94 lines
2.9 KiB
YAML
name: Docker Build
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: docker-build-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
statuses: write
|
|
|
|
env:
|
|
IMAGE_REGISTRY: git.izebra.net/izebra_projects/musicfetch
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.GITEA_USERNAME }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
registry: git.izebra.net
|
|
|
|
- name: Extract metadata (tags, labels)
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.IMAGE_REGISTRY }}
|
|
tags: |
|
|
type=raw,value=latest
|
|
type=sha
|
|
type=sha,format=short
|
|
type=ref,event=branch
|
|
labels: |
|
|
org.opencontainers.image.source=${{ github.repositoryUrl }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
|
|
org.opencontainers.image.title=musicfetch
|
|
org.opencontainers.image.description=Automated build from commit ${{ github.sha }}
|
|
|
|
- name: Build and push Docker image
|
|
id: build_push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: server/Dockerfile
|
|
push: true
|
|
provenance: false
|
|
sbom: false
|
|
cache-from: type=registry,ref=${{ env.IMAGE_REGISTRY }}:buildcache
|
|
cache-to: type=registry,ref=${{ env.IMAGE_REGISTRY }}:buildcache,mode=max
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
- name: Set commit status (image pushed)
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const sha = context.sha;
|
|
const tags = `${process.env.IMAGE_REGISTRY}:latest`;
|
|
await github.rest.repos.createCommitStatus({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
sha,
|
|
state: 'success',
|
|
context: 'docker-image',
|
|
description: `Image pushed with tags: latest, sha`,
|
|
target_url: `https://${process.env.IMAGE_REGISTRY}`
|
|
});
|
|
|
|
- name: Post build summary
|
|
run: |
|
|
echo "### Docker Image Build" >> $GITHUB_STEP_SUMMARY
|
|
echo "Registry: $IMAGE_REGISTRY" >> $GITHUB_STEP_SUMMARY
|
|
echo "Commit: $GITHUB_SHA" >> $GITHUB_STEP_SUMMARY
|
|
echo "Tags applied:" >> $GITHUB_STEP_SUMMARY
|
|
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
|