Skip to content

build

build #651

Workflow file for this run

name: build
on:
schedule:
- cron: "30 00 * * *"
push:
branches:
- main
paths-ignore:
- "**.md"
workflow_dispatch:
env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs:
fcos_version:
name: Get Fedora CoreOS Version
runs-on: ubuntu-latest
outputs:
stable_linux: ${{ steps.stable.outputs.linux }}
stable_version: ${{ steps.stable.outputs.version }}
steps:
- name: Fetch CoreOS stable versions
id: stable
run: |
skopeo inspect docker://quay.io/fedora/fedora-coreos:stable > inspect.json
linux=$(jq -r '.["Labels"]["ostree.linux"]' inspect.json)
echo "linux=$linux" >> $GITHUB_OUTPUT
version=$(jq -r '.["Labels"]["org.opencontainers.image.version"]' inspect.json)
echo "version=$version" >> $GITHUB_OUTPUT
- name: Echo outputs
run: |
echo "${{ toJSON(steps.stable.outputs) }}"
json_files:
name: Generate Build Environments
runs-on: ubuntu-latest
outputs:
files: ${{ steps.json.outputs.files }}
steps:
- uses: actions/checkout@v4
- name: Find JSON files
id: json
run: |
pushd .config
echo "files=$(ls | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
popd
- run: |
echo "${{ steps.json.outputs.files }}"
build:
name: Build and push image
runs-on: ubuntu-22.04
if: always() && !cancelled()
needs: [fcos_version, json_files]
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false
matrix:
image_name:
- automatos-server
environment: ${{ fromJSON(needs.json_files.outputs.files) }}
include:
- image_version: ${{ needs.fcos_version.outputs.stable_version }}
steps:
- name: Checkout Push to Registry action
uses: actions/checkout@v4
- name: Generate image tags
id: generate-image-tags
shell: bash
run: |
TIMESTAMP="$(date +%Y%m%d-%H%M%S)"
DATE="$(echo ${TIMESTAMP} | cut -d '-' -f 1)"
echo "DATE=$DATE" >> $GITHUB_ENV
MAJOR_VERSION="$(echo ${{ matrix.image_version }} | cut -d '.' -f 1)"
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_ENV
BUILD_TAGS=( "latest" "${TIMESTAMP}" "${MAJOR_VERSION}.${DATE}")
echo "alias_tags=${BUILD_TAGS[*]}" >> $GITHUB_OUTPUT
- name: Define Image Metadata
id: define-image-metadata
uses: docker/metadata-action@v5
with:
images: |
${{ matrix.image_name }}-${{ matrix.environment }}
labels: |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/cubt85iz/automatos-server/main/README.md
org.opencontainers.image.description=A ucore-derived image with ZFS and container quadlets
org.opencontainers.image.title=${{ matrix.image_name }}-${{ matrix.environment }}
org.opencontainers.image.version=${{ env.MAJOR_VERSION }}.${{ env.DATE }}
- name: Build Image
id: build_image
uses: redhat-actions/buildah-build@v2
with:
containerfiles: |
./Containerfile
context: ./
image: ${{ matrix.image_name }}-${{ matrix.environment }}
tags: |
${{ steps.generate-image-tags.outputs.alias_tags }}
extra-args: |
--build-arg=CONFIG=${{ matrix.environment }}
labels: ${{ steps.define-image-metadata.outputs.labels }}
oci: false
# Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR.
# https://github.com/macbre/push-to-ghcr/issues/12
- name: Lowercase Registry
id: registry_case
uses: ASzc/change-string-case-action@v6
with:
string: ${{ env.IMAGE_REGISTRY }}
# Push the image to GHCR (Image Registry)
- name: Push To GHCR
uses: redhat-actions/push-to-registry@v2
id: push
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ steps.registry_case.outputs.lowercase }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Sign container
- uses: sigstore/[email protected]
if: github.event_name != 'pull_request'
- name: Sign container image
if: github.event_name != 'pull_request'
run: |
cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ steps.build_image.outputs.image }}@${TAGS}
env:
TAGS: ${{ steps.push.outputs.digest }}
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
- name: Echo outputs
#if: github.event_name != 'pull_request'
run: |
echo "${{ toJSON(steps.push.outputs) }}"