Skip to content

Commit 43d0841

Browse files
authored
Migrate builder workflow to new builder actions (#258)
Migrate plugin image build to new builder actions. The resulting image should be identical, while a multi-arch manifest should be now published along the per-arch images. The workflow should now also work in forked repos, unlike the old one which had home-assistant org hardcoded on several places. In forked repos, the version job is skipped now. Closes #257
1 parent c7390f4 commit 43d0841

File tree

3 files changed

+100
-89
lines changed

3 files changed

+100
-89
lines changed

.github/workflows/builder.yml

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,90 +9,107 @@ on:
99
branches: ["master"]
1010
paths:
1111
- Dockerfile
12-
- build.yaml
13-
- 'rootfs/**'
12+
- 'rootfs/**'
1413
- '**.go'
1514
- go.mod
1615

1716
env:
17+
ARCHITECTURES: '["amd64", "aarch64"]'
1818
BUILD_NAME: observer
1919
BUILD_TYPE: plugin
20+
IMAGE_NAME: hassio-observer
21+
22+
permissions:
23+
contents: read
2024

2125
jobs:
2226
init:
2327
name: Initialize build
2428
runs-on: ubuntu-latest
2529
outputs:
26-
architectures: ${{ steps.info.outputs.architectures }}
2730
version: ${{ steps.version.outputs.version }}
2831
channel: ${{ steps.version.outputs.channel }}
2932
publish: ${{ steps.version.outputs.publish }}
33+
matrix: ${{ steps.matrix.outputs.matrix }}
3034
steps:
3135
- name: Checkout the repository
32-
uses: actions/checkout@v6.0.2
36+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3337
with:
3438
fetch-depth: 0
3539

36-
- name: Get information
37-
id: info
38-
uses: home-assistant/actions/helpers/info@master
39-
4040
- name: Get version
4141
id: version
4242
uses: home-assistant/actions/helpers/version@master
4343
with:
4444
type: ${{ env.BUILD_TYPE }}
4545

46+
- name: Get build matrix
47+
id: matrix
48+
uses: home-assistant/builder/actions/prepare-multi-arch-matrix@62a1597b84b3461abad9816d9cd92862a2b542c3 # 2026.03.2
49+
with:
50+
architectures: ${{ env.ARCHITECTURES }}
51+
image-name: ${{ env.IMAGE_NAME }}
52+
4653
build:
47-
name: Build ${{ matrix.arch }} plugin
54+
name: Build ${{ matrix.arch }} image
4855
needs: init
49-
runs-on: ${{ matrix.runs-on }}
56+
runs-on: ${{ matrix.os }}
5057
permissions:
5158
contents: read
52-
packages: write
5359
id-token: write
60+
packages: write
5461
strategy:
55-
matrix:
56-
arch: ${{ fromJson(needs.init.outputs.architectures) }}
57-
include:
58-
- runs-on: ubuntu-24.04
59-
- arch: aarch64
60-
runs-on: ubuntu-24.04-arm
62+
fail-fast: false
63+
matrix: ${{ fromJSON(needs.init.outputs.matrix) }}
6164
steps:
62-
- name: Checkout the repository
63-
uses: actions/checkout@v6.0.2
64-
65-
- name: Login to GitHub Container Registry
66-
if: needs.init.outputs.publish == 'true'
67-
uses: docker/login-action@v4.0.0
68-
with:
69-
registry: ghcr.io
70-
username: ${{ secrets.GIT_USER }}
71-
password: ${{ secrets.GIT_TOKEN }}
65+
- name: Checkout the repository
66+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
67+
with:
68+
persist-credentials: false
7269

73-
- name: Set build arguments
74-
if: needs.init.outputs.publish == 'false'
75-
run: echo "BUILD_ARGS=--test" >> $GITHUB_ENV
70+
- name: Build image
71+
id: build
72+
uses: home-assistant/builder/actions/build-image@62a1597b84b3461abad9816d9cd92862a2b542c3 # 2026.03.2
73+
with:
74+
arch: ${{ matrix.arch }}
75+
container-registry-password: ${{ secrets.GITHUB_TOKEN }}
76+
cosign-base-identity: 'https://github.com/home-assistant/docker-base/.*'
77+
cosign-base-verify: ghcr.io/home-assistant/base:3.23
78+
image: ${{ matrix.image }}
79+
image-tags: |
80+
${{ needs.init.outputs.version }}
81+
latest
82+
push: ${{ needs.init.outputs.publish == 'true' }}
83+
version: ${{ needs.init.outputs.version }}
7684

77-
- name: Build plugin
78-
uses: home-assistant/builder@2026.02.1
79-
with:
80-
image: ${{ matrix.arch }}
81-
args: |
82-
$BUILD_ARGS \
83-
--${{ matrix.arch }} \
84-
--cosign \
85-
--target /data \
86-
--generic ${{ needs.init.outputs.version }}
85+
manifest:
86+
name: Publish multi-arch manifest
87+
needs: [init, build]
88+
if: needs.init.outputs.publish == 'true'
89+
runs-on: ubuntu-latest
90+
permissions:
91+
id-token: write
92+
packages: write
93+
steps:
94+
- name: Publish multi-arch manifest
95+
uses: home-assistant/builder/actions/publish-multi-arch-manifest@62a1597b84b3461abad9816d9cd92862a2b542c3 # 2026.03.2
96+
with:
97+
architectures: ${{ env.ARCHITECTURES }}
98+
container-registry-password: ${{ secrets.GITHUB_TOKEN }}
99+
image-name: ${{ env.IMAGE_NAME }}
100+
image-tags: |
101+
${{ needs.init.outputs.version }}
102+
latest
87103
88104
version:
89105
name: Update version
90-
needs: ["init", "build"]
106+
needs: [init, build, manifest]
91107
runs-on: ubuntu-latest
108+
if: github.repository_owner == 'home-assistant'
92109
steps:
93110
- name: Checkout the repository
94111
if: needs.init.outputs.publish == 'true'
95-
uses: actions/checkout@v6.0.2
112+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
96113

97114
- name: Initialize git
98115
if: needs.init.outputs.publish == 'true'

Dockerfile

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
ARG BUILD_FROM
2-
3-
FROM golang:1.25-alpine3.23 AS builder
4-
5-
WORKDIR /workspace/observer-plugin
6-
ARG BUILD_ARCH
7-
8-
COPY . .
9-
10-
# Build
11-
RUN \
12-
if [ "${BUILD_ARCH}" = "aarch64" ]; then \
13-
CGO_ENABLED=0 GOARCH=arm64 go build -ldflags="-s -w"; \
14-
elif [ "${BUILD_ARCH}" = "amd64" ]; then \
15-
CGO_ENABLED=0 GOARCH=amd64 go build -ldflags="-s -w"; \
16-
else \
17-
exit 1; \
18-
fi \
19-
&& cp -f plugin-observer /workspace/observer \
20-
&& rm -rf /workspace/observer-plugin
21-
22-
23-
FROM ${BUILD_FROM}
24-
25-
ENV DOCKER_HOST="unix:///run/docker.sock"
26-
27-
WORKDIR /
28-
COPY --from=builder /workspace/observer /usr/bin/observer
29-
COPY rootfs /
30-
31-
ENTRYPOINT ["/usr/bin/observer"]
1+
ARG BUILD_FROM=scratch
2+
3+
FROM golang:1.25-alpine3.23 AS builder
4+
5+
WORKDIR /workspace/observer-plugin
6+
ARG TARGETARCH
7+
8+
COPY . .
9+
10+
# Build
11+
RUN \
12+
if [ -z "${TARGETARCH}" ]; then \
13+
echo "TARGETARCH is not set, please use Docker BuildKit for the build." && exit 1; \
14+
fi \
15+
&& case "${TARGETARCH}" in \
16+
amd64|arm64) ;; \
17+
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" && exit 1 ;; \
18+
esac \
19+
&& CGO_ENABLED=0 GOARCH=${TARGETARCH} go build -ldflags="-s -w" \
20+
&& cp -f plugin-observer /workspace/observer \
21+
&& rm -rf /workspace/observer-plugin
22+
23+
24+
FROM ${BUILD_FROM}
25+
26+
ENV DOCKER_HOST="unix:///run/docker.sock"
27+
28+
WORKDIR /
29+
COPY --from=builder /workspace/observer /usr/bin/observer
30+
COPY rootfs /
31+
32+
ENTRYPOINT ["/usr/bin/observer"]
33+
34+
LABEL \
35+
io.hass.type="observer" \
36+
org.opencontainers.image.title="Home Assistant Observer Plugin" \
37+
org.opencontainers.image.description="Home Assistant Supervisor plugin monitor Supervisor" \
38+
org.opencontainers.image.authors="The Home Assistant Authors" \
39+
org.opencontainers.image.url="https://www.home-assistant.io/" \
40+
org.opencontainers.image.documentation="https://www.home-assistant.io/docs/" \
41+
org.opencontainers.image.licenses="Apache License 2.0"

build.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)