refactor: simplify Ubuntu MATE build workflow and improve environment variable handling
This commit is contained in:
parent
b2f85a96d7
commit
306d4063d3
1 changed files with 60 additions and 34 deletions
94
.github/workflows/ubuntu-mate-build.yml
vendored
94
.github/workflows/ubuntu-mate-build.yml
vendored
|
|
@ -1,10 +1,5 @@
|
|||
name: Ubuntu MATE build
|
||||
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 3 * * *'
|
||||
|
|
@ -17,18 +12,10 @@ on:
|
|||
tags: [ 'v*.*.*' ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
env:
|
||||
# Use docker.io for Docker Hub if empty
|
||||
REGISTRY: ghcr.io
|
||||
# github.repository as <account>/<repo>
|
||||
IMAGE_NAME: ${{ github.repository }}/containerdesk-ubuntu-mate
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build_mate:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
|
@ -38,43 +25,82 @@ jobs:
|
|||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Set registry and token
|
||||
run: |
|
||||
if [[ "${{ github.server_url }}" == "https://github.com" ]]; then
|
||||
echo "REGISTRY=ghcr.io" >> $GITHUB_ENV
|
||||
echo "CONTAINER_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
|
||||
else
|
||||
# Forgejo/Gitea uses the instance domain as registry
|
||||
echo "REGISTRY=$(echo ${{ github.server_url }} | sed 's|https://||')" >> $GITHUB_ENV
|
||||
echo "CONTAINER_TOKEN=${{ secrets.FORGEJOTOKEN }}" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Set image name
|
||||
run: |
|
||||
echo "IMAGE_NAME=$(echo ${{ github.repository }}/containerdesk-ubuntu-mate | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Workaround: https://github.com/docker/build-push-action/issues/461
|
||||
- name: Setup Docker buildx
|
||||
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
|
||||
|
||||
# Login against a Docker registry except on PR
|
||||
# https://github.com/docker/login-action
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
- name: Log in to the Container registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
password: ${{ env.CONTAINER_TOKEN }}
|
||||
|
||||
# Extract metadata (tags, labels) for Docker
|
||||
# https://github.com/docker/metadata-action
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
- name: Extract branch name
|
||||
shell: bash
|
||||
run: |
|
||||
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
|
||||
BRANCH_NAME_CLEAN=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g')
|
||||
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
|
||||
echo "BRANCH_NAME_CLEAN=$BRANCH_NAME_CLEAN" >> $GITHUB_ENV
|
||||
|
||||
- name: Generate build version
|
||||
id: version
|
||||
run: |
|
||||
BUILD_DATE=$(date +'%Y%m%d')
|
||||
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||
echo "BUILD_VERSION=$BUILD_DATE-$SHORT_SHA" >> $GITHUB_ENV
|
||||
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
|
||||
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
|
||||
|
||||
- name: Generate Docker tags for main branch
|
||||
if: env.BRANCH_NAME == 'main'
|
||||
run: |
|
||||
echo "DOCKER_TAGS<<EOF" >> $GITHUB_ENV
|
||||
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV
|
||||
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_VERSION }}" >> $GITHUB_ENV
|
||||
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_DATE }}" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
|
||||
- name: Generate Docker tags for development branches
|
||||
if: env.BRANCH_NAME != 'main'
|
||||
run: |
|
||||
echo "DOCKER_TAGS<<EOF" >> $GITHUB_ENV
|
||||
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ env.BRANCH_NAME_CLEAN }}-${{ env.BUILD_VERSION }}" >> $GITHUB_ENV
|
||||
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ env.BRANCH_NAME_CLEAN }}-latest" >> $GITHUB_ENV
|
||||
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev-latest" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
|
||||
# Workaround: https://github.com/docker/build-push-action/issues/461
|
||||
- name: Setup Docker buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
# Build and push Docker image with Buildx (don't push on PR)
|
||||
# https://github.com/docker/build-push-action
|
||||
- name: Build and push Docker image
|
||||
id: build-and-push
|
||||
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./ubuntu-mate
|
||||
file: ./ubuntu-mate/Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
tags: ${{ env.DOCKER_TAGS }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue