name: "Build and Push Image" on: workflow_dispatch: inputs: app: type: string description: "App to build, e.g. 'home-assistant'" required: true push: paths: - "apps/**" jobs: build-and-push: runs-on: ci-os steps: - name: Checkout uses: actions/checkout@v4 - 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 - id: set-context name: Determine build context run: | context_dir="/workspace/pub/containers/apps/${{ env.app }}" echo "context_dir=$context_dir" >> $GITHUB_OUTPUT - 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 - id: parse-channel-platform name: Read channel + platform from metadata.yaml shell: bash run: | metadata_file="${{ steps.set-context.outputs.context_dir }}/metadata.yaml" echo "Looking for ${metadata_file}..." if [ ! -f "$metadata_file" ]; then echo "metadata.yaml not found at $metadata_file" exit 1 fi # Grab the FIRST channel name: channel=$(yq '.channels[0].name' "$metadata_file") # Grab the FIRST platform under that channel: platform=$(yq '.channels[0].platforms[0]' "$metadata_file") echo "Using channel='$channel' and platform='$platform'" # Expose for later steps echo channel=$channel >> $GITHUB_OUTPUT echo platform=$platform >> $GITHUB_OUTPUT - id: read-version name: Read version from version.sh shell: bash run: | version=$(bash "${{ steps.set-context.outputs.context_dir }}/ci/version.sh" || echo "" | sed 's/[^a-zA-Z0-9._-]//g') echo "Discovered version: $version" echo version=$version >> $GITHUB_OUTPUT - 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 }}" echo "destinations: code.252.no/${{ github.repository }}/${{ env.app }}:${{ steps.read-version.outputs.version }}" echo "context: ${{ steps.set-context.outputs.context_dir }}" echo "TARGETPLATFORM=${{ steps.parse-channel-platform.outputs.platform }}" echo "VERSION=${{ steps.read-version.outputs.version }}" - name: Build and Push with Kaniko uses: https://code.252.no/pub/kaniko-action@latest with: # Path that holds Dockerfile, metadata.yaml, etc. context: ${{ steps.set-context.outputs.context_dir }} # Build & push two tags: : and : destinations: code.252.no/${{ github.repository }}/${{ env.app }}:${{ steps.read-version.outputs.version }} # Pass any build arguments the Dockerfile expects build_args: | TARGETPLATFORM=${{ steps.parse-channel-platform.outputs.platform }} VERSION=${{ steps.read-version.outputs.version }} credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}" push: "true" cache: "false"