2025-01-03 22:50:25 +00:00
|
|
|
name: "Build and Push Image"
|
2024-11-03 20:28:20 +00:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
2025-01-03 06:19:43 +00:00
|
|
|
inputs:
|
2025-01-03 13:06:07 +00:00
|
|
|
app:
|
2025-01-03 06:22:29 +00:00
|
|
|
type: string
|
2025-01-03 13:52:14 +00:00
|
|
|
description: "App to build, e.g. 'home-assistant'"
|
|
|
|
required: true
|
2025-01-05 11:17:26 +00:00
|
|
|
push:
|
|
|
|
paths:
|
|
|
|
- "apps/**"
|
2024-12-30 20:50:06 +00:00
|
|
|
|
2024-11-03 20:28:20 +00:00
|
|
|
jobs:
|
2025-01-03 22:50:25 +00:00
|
|
|
build-and-push:
|
2025-01-03 17:02:07 +00:00
|
|
|
runs-on: ci-os
|
2025-01-03 15:30:52 +00:00
|
|
|
steps:
|
2025-01-03 17:05:53 +00:00
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
2025-01-03 17:00:31 +00:00
|
|
|
|
2025-01-05 11:17:26 +00:00
|
|
|
- id: set-app-name
|
|
|
|
name: Derive app name
|
|
|
|
run: |
|
|
|
|
if [[ "${{ github.event_name }}" == "push" ]]; then
|
|
|
|
changed_file=$(echo "${{ github.event.head_commit.modified[0] }}")
|
|
|
|
app_name=$(echo "$changed_file" | awk -F'/' '{print $2}')
|
|
|
|
echo "Derived app name: $app_name"
|
|
|
|
echo "app=$app_name" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "app=${{ github.event.inputs.app }}" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
- id: set-context
|
|
|
|
name: Determine build context
|
2025-01-03 17:05:53 +00:00
|
|
|
run: |
|
2025-01-05 11:17:26 +00:00
|
|
|
context_dir="/workspace/pub/containers/apps/${{ env.app }}"
|
2025-01-03 22:50:25 +00:00
|
|
|
echo "context_dir=$context_dir" >> $GITHUB_OUTPUT
|
2025-01-03 17:07:00 +00:00
|
|
|
|
2025-01-05 11:17:26 +00:00
|
|
|
- id: check-dockerfile
|
|
|
|
name: Ensure only one Dockerfile
|
|
|
|
run: |
|
|
|
|
dockerfile_count=$(find "${{ steps.set-context.outputs.context_dir }}" -type f -name "Dockerfile" | wc -l)
|
|
|
|
|
|
|
|
echo "Found $dockerfile_count Dockerfile(s)."
|
|
|
|
|
|
|
|
if [ "$dockerfile_count" -ne 1 ]; then
|
|
|
|
echo "Error: Found $dockerfile_count Dockerfile(s). Only one Dockerfile is allowed."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
- id: parse-channel-platform
|
|
|
|
name: Read channel + platform from metadata.yaml
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
metadata_file="${{ steps.set-context.outputs.context_dir }}/metadata.yaml"
|
2025-01-03 15:30:52 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
echo "Looking for ${metadata_file}..."
|
2025-01-03 17:05:53 +00:00
|
|
|
if [ ! -f "$metadata_file" ]; then
|
|
|
|
echo "metadata.yaml not found at $metadata_file"
|
|
|
|
exit 1
|
|
|
|
fi
|
2025-01-03 15:30:52 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
# Grab the FIRST channel name:
|
|
|
|
channel=$(yq '.channels[0].name' "$metadata_file")
|
2025-01-03 17:05:53 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
# Grab the FIRST platform under that channel:
|
2025-01-04 09:59:22 +00:00
|
|
|
platform=$(yq '.channels[0].platforms[0]' "$metadata_file")
|
2025-01-03 15:30:52 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
echo "Using channel='$channel' and platform='$platform'"
|
2025-01-03 17:05:53 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
# Expose for later steps
|
2025-01-03 22:59:16 +00:00
|
|
|
echo channel=$channel >> $GITHUB_OUTPUT
|
|
|
|
echo platform=$platform >> $GITHUB_OUTPUT
|
2025-01-03 17:05:53 +00:00
|
|
|
|
|
|
|
- id: read-version
|
2025-01-03 22:50:25 +00:00
|
|
|
name: Read version from version.sh
|
|
|
|
shell: bash
|
2025-01-03 17:05:53 +00:00
|
|
|
run: |
|
2025-01-03 23:03:14 +00:00
|
|
|
version=$(bash "${{ steps.set-context.outputs.context_dir }}/ci/version.sh" || echo "" | sed 's/[^a-zA-Z0-9._-]//g')
|
2025-01-03 22:50:25 +00:00
|
|
|
echo "Discovered version: $version"
|
2025-01-03 22:59:16 +00:00
|
|
|
echo version=$version >> $GITHUB_OUTPUT
|
2025-01-03 17:05:53 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
- name: Log chosen channel/platform
|
|
|
|
run: |
|
|
|
|
echo "Channel: ${{ steps.parse-channel-platform.outputs.channel }}"
|
|
|
|
echo "Platform: ${{ steps.parse-channel-platform.outputs.platform }}"
|
|
|
|
echo "Version: ${{ steps.read-version.outputs.version }}"
|
2025-01-05 11:17:26 +00:00
|
|
|
echo "destinations: code.252.no/${{ github.repository }}/${{ env.app }}:${{ steps.read-version.outputs.version }}"
|
2025-01-03 23:13:21 +00:00
|
|
|
echo "context: ${{ steps.set-context.outputs.context_dir }}"
|
|
|
|
echo "TARGETPLATFORM=${{ steps.parse-channel-platform.outputs.platform }}"
|
|
|
|
echo "VERSION=${{ steps.read-version.outputs.version }}"
|
2025-01-03 17:07:00 +00:00
|
|
|
|
2025-01-03 17:05:53 +00:00
|
|
|
- name: Build and Push with Kaniko
|
|
|
|
uses: https://code.252.no/pub/kaniko-action@latest
|
|
|
|
with:
|
2025-01-03 22:50:25 +00:00
|
|
|
# Path that holds Dockerfile, metadata.yaml, etc.
|
2025-01-03 17:05:53 +00:00
|
|
|
context: ${{ steps.set-context.outputs.context_dir }}
|
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
# Build & push two tags: :<channel> and :<version>
|
2025-01-05 11:17:26 +00:00
|
|
|
destinations: code.252.no/${{ github.repository }}/${{ env.app }}:${{ steps.read-version.outputs.version }}
|
2025-01-03 17:05:53 +00:00
|
|
|
|
2025-01-03 22:50:25 +00:00
|
|
|
# Pass any build arguments the Dockerfile expects
|
2025-01-03 17:05:53 +00:00
|
|
|
build_args: |
|
2025-01-03 22:50:25 +00:00
|
|
|
TARGETPLATFORM=${{ steps.parse-channel-platform.outputs.platform }}
|
2025-01-03 17:05:53 +00:00
|
|
|
VERSION=${{ steps.read-version.outputs.version }}
|
|
|
|
|
|
|
|
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
|
|
|
push: "true"
|
|
|
|
cache: "false"
|