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
|
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:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 3 * * *'
|
- cron: '0 3 * * *'
|
||||||
|
|
@ -17,18 +12,10 @@ on:
|
||||||
tags: [ 'v*.*.*' ]
|
tags: [ 'v*.*.*' ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
workflow_dispatch:
|
||||||
env:
|
|
||||||
# Use docker.io for Docker Hub if empty
|
|
||||||
REGISTRY: ghcr.io
|
|
||||||
# github.repository as <account>/<repo>
|
|
||||||
IMAGE_NAME: ${{ github.repository }}/containerdesk-ubuntu-mate
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build_mate:
|
build_mate:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -38,43 +25,82 @@ jobs:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
steps:
|
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
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Workaround: https://github.com/docker/build-push-action/issues/461
|
- name: Log in to the Container registry
|
||||||
- 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 }}
|
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ env.CONTAINER_TOKEN }}
|
||||||
|
|
||||||
# Extract metadata (tags, labels) for Docker
|
- name: Extract branch name
|
||||||
# https://github.com/docker/metadata-action
|
shell: bash
|
||||||
- name: Extract Docker metadata
|
run: |
|
||||||
id: meta
|
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
|
||||||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
|
BRANCH_NAME_CLEAN=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g')
|
||||||
with:
|
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
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)
|
# Build and push Docker image with Buildx (don't push on PR)
|
||||||
# https://github.com/docker/build-push-action
|
# https://github.com/docker/build-push-action
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
id: build-and-push
|
id: build-and-push
|
||||||
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ./ubuntu-mate
|
context: ./ubuntu-mate
|
||||||
file: ./ubuntu-mate/Dockerfile
|
file: ./ubuntu-mate/Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ env.DOCKER_TAGS }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue