Build and push Ubuntu image #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push Ubuntu image | |
on: | |
push: | |
tags: | |
- 'v*.*.*' | |
paths: | |
- ubuntu/** | |
schedule: | |
- cron: "0 0 * * 1" # Every Monday at 00:00 | |
workflow_dispatch: | |
env: | |
REGISTRY: docker.io | |
IMAGE_OWNER: glitchcrab | |
IMAGE_NAME: ubuntu-debug | |
jobs: | |
debug_info: | |
name: Debug info | |
runs-on: self-hosted | |
steps: | |
- name: Print github context JSON | |
run: | | |
cat <<EOF | |
${{ toJson(github) }} | |
EOF | |
build-on-push-trigger: | |
runs-on: self-hosted | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ env.IMAGE_OWNER }} | |
password: ${{ secrets.DOCKERHUB_TOKEN_UBUNTU }} | |
- name: Set current date as env variable | |
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern={{raw}} | |
type=raw,value=latest | |
type=raw,value=${{ env.DATE }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: "./ubuntu" | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-on-any-other-trigger: | |
runs-on: self-hosted | |
if: github.event_name != 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ env.IMAGE_OWNER }} | |
password: ${{ secrets.DOCKERHUB_TOKEN_UBUNTU }} | |
- name: Set current date as env variable | |
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=latest | |
type=raw,value=${{ env.DATE }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: "./ubuntu" | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |