Skip to content

Commit 0893d6b

Browse files
authored
Allow yml and yaml files (#107)
* Allow yml and yaml files * -q * Use self refrence to build the builder * add back json * revert test action change * Remove debug * Adjust ARG
1 parent bbaea08 commit 0893d6b

File tree

5 files changed

+140
-82
lines changed

5 files changed

+140
-82
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Test'
1+
name: "Test"
22

33
on:
44
pull_request:
@@ -10,12 +10,12 @@ jobs:
1010
outputs:
1111
architectures: ${{ steps.info.outputs.architectures }}
1212
steps:
13-
- name: Checkout the repository
14-
uses: actions/[email protected]
13+
- name: Checkout the repository
14+
uses: actions/[email protected]
1515

16-
- name: Get information
17-
id: info
18-
uses: home-assistant/actions/helpers/info@master
16+
- name: Get information
17+
id: info
18+
uses: home-assistant/actions/helpers/info@master
1919

2020
build:
2121
name: Test action build
@@ -26,23 +26,23 @@ jobs:
2626
matrix:
2727
architecture: ${{ fromJson(needs.init.outputs.architectures) }}
2828
steps:
29-
- name: Checkout the repository
30-
uses: actions/[email protected]
29+
- name: Checkout the repository
30+
uses: actions/[email protected]
3131

32-
- name: Build the builder
33-
uses: home-assistant/builder@master
34-
with:
35-
args: |
36-
--test \
37-
--amd64 \
38-
--target /data \
39-
--generic latest
32+
- name: Build the builder
33+
uses: home-assistant/builder@master
34+
with:
35+
args: |
36+
--test \
37+
--amd64 \
38+
--target /data \
39+
--generic latest
4040
41-
- name: Test ${{ matrix.architecture }} builder
42-
uses: ./
43-
with:
44-
args: |
45-
--test \
46-
--${{ matrix.architecture }} \
47-
--target /data \
48-
--generic ${{ github.sha }}
41+
- name: Test ${{ matrix.architecture }} builder
42+
uses: ./
43+
with:
44+
args: |
45+
--test \
46+
--${{ matrix.architecture }} \
47+
--target /data \
48+
--generic ${{ github.sha }}

Dockerfile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ ENV \
77
VCN_OTP_EMPTY=true \
88
LANG=C.UTF-8
99

10-
ARG BUILD_ARCH
11-
ARG VCN_VERSION
10+
ARG \
11+
BUILD_ARCH \
12+
VCN_VERSION \
13+
YQ_VERSION
1214

1315
RUN \
1416
set -x \
@@ -40,6 +42,18 @@ RUN \
4042
\
4143
&& rm -rf /root/go /root/.cache \
4244
&& mv vcn /usr/bin/vcn \
45+
&& if [ "${BUILD_ARCH}" = "armhf" ] || [ "${BUILD_ARCH}" = "armv7" ]; then \
46+
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm; \
47+
elif [ "${BUILD_ARCH}" = "aarch64" ]; then \
48+
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm64; \
49+
elif [ "${BUILD_ARCH}" = "i386" ]; then \
50+
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_386; \
51+
elif [ "${BUILD_ARCH}" = "amd64" ]; then \
52+
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64; \
53+
else \
54+
exit 1; \
55+
fi \
56+
&& chmod +x /usr/bin/yq \
4357
\
4458
&& apk del .build-dependencies \
4559
&& rm -rf /usr/src/vcn

build.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
2-
"image": "homeassistant/{arch}-builder",
3-
"shadow_repository": "ghcr.io/home-assistant",
4-
"build_from": {
5-
"aarch64": "ghcr.io/home-assistant/aarch64-base:3.13",
6-
"armv7": "ghcr.io/home-assistant/armv7-base:3.13",
7-
"armhf": "ghcr.io/home-assistant/armhf-base:3.13",
8-
"amd64": "ghcr.io/home-assistant/amd64-base:3.13",
9-
"i386": "ghcr.io/home-assistant/i386-base:3.13"
10-
},
11-
"args": {
12-
"VCN_VERSION": "0.9.6"
13-
},
14-
"labels": {
15-
"io.hass.type": "builder",
16-
"org.opencontainers.image.source": "https://github.com/home-assistant/builder"
17-
}
18-
}
2+
"image": "homeassistant/{arch}-builder",
3+
"shadow_repository": "ghcr.io/home-assistant",
4+
"build_from": {
5+
"aarch64": "ghcr.io/home-assistant/aarch64-base:3.13",
6+
"armv7": "ghcr.io/home-assistant/armv7-base:3.13",
7+
"armhf": "ghcr.io/home-assistant/armhf-base:3.13",
8+
"amd64": "ghcr.io/home-assistant/amd64-base:3.13",
9+
"i386": "ghcr.io/home-assistant/i386-base:3.13"
10+
},
11+
"args": {
12+
"VCN_VERSION": "0.9.6",
13+
"YQ_VERSION": "v4.13.2"
14+
},
15+
"labels": {
16+
"io.hass.type": "builder",
17+
"org.opencontainers.image.source": "https://github.com/home-assistant/builder"
18+
}
19+
}

build.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
image: "homeassistant/{arch}-builder"
2+
shadow_repository: "ghcr.io/home-assistant"
3+
build_from:
4+
aarch64: "ghcr.io/home-assistant/aarch64-base:3.13"
5+
armv7: "ghcr.io/home-assistant/armv7-base:3.13"
6+
armhf: "ghcr.io/home-assistant/armhf-base:3.13"
7+
amd64: "ghcr.io/home-assistant/amd64-base:3.13"
8+
i386: "ghcr.io/home-assistant/i386-base:3.13"
9+
args:
10+
VCN_VERSION: "0.9.6"
11+
YQ_VERSION: "v4.13.2"
12+
labels:
13+
io.hass.type: builder
14+
org.opencontainers.image.source: "https://github.com/home-assistant/builder"

builder.sh

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function run_build() {
309309
bashio::log.info "Generate repository shadow images"
310310
docker tag "${repository}/${image}:${version}" "${shadow_repository}/${image}:${version}"
311311
for tag_image in "${docker_tags[@]}"; do
312-
bashio::log.info "Create shadow-image tag: ${tag_image}"
312+
bashio::log.info "Create shadow-image tag: ${shadow_repository}/${image}:${tag_image}"
313313
docker tag "${repository}/${image}:${version}" "${shadow_repository}/${image}:${tag_image}"
314314
push_images+=("${shadow_repository}/${image}:${tag_image}")
315315
done
@@ -339,6 +339,28 @@ function run_build() {
339339
fi
340340
}
341341

342+
function convert_to_json() {
343+
# Convert [build|config].[yml|yaml] to json in a temp directory
344+
for file in config build; do
345+
if bashio::fs.file_exists "${TARGET}/${file}.yml"; then
346+
yq e -N -M -o=json "${TARGET}/${file}.yml" > "/tmp/build_config/${file}.json"
347+
elif bashio::fs.file_exists "${TARGET}/${file}.yaml"; then
348+
yq e -N -M -o=json "${TARGET}/${file}.yaml" > "/tmp/build_config/${file}.json"
349+
fi
350+
done
351+
}
352+
353+
function copy_config_tmp() {
354+
# Copy [build|config].json to a temp directory
355+
mkdir -p /tmp/build_config
356+
for file in config build; do
357+
if bashio::fs.file_exists "${TARGET}/${file}.json"; then
358+
cp "${TARGET}/${file}.json" "/tmp/build_config/${file}.json"
359+
fi
360+
done
361+
}
362+
363+
342364

343365
#### Build functions ####
344366

@@ -356,13 +378,14 @@ function build_base() {
356378
local docker_tags=()
357379

358380
# Read build.json
359-
if bashio::fs.file_exists "${TARGET}/build.json"; then
360-
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "${TARGET}/build.json")"
361-
args="$(jq --raw-output '.args // empty | keys[]' "${TARGET}/build.json")"
362-
labels="$(jq --raw-output '.labels // empty | keys[]' "${TARGET}/build.json")"
363-
raw_image="$(jq --raw-output '.image // empty' "${TARGET}/build.json")"
364-
version_tag="$(jq --raw-output '.version_tag // false' "${TARGET}/build.json")"
365-
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
381+
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
382+
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")"
383+
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
384+
labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")"
385+
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")"
386+
version_tag="$(jq --raw-output '.version_tag // false' "/tmp/build_config/build.json")"
387+
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
388+
366389
fi
367390

368391
# Set defaults build things
@@ -392,15 +415,15 @@ function build_base() {
392415
# Additional build args
393416
if bashio::var.has_value "${args}"; then
394417
for arg in ${args}; do
395-
value="$(jq --raw-output ".args.${arg}" "${TARGET}/build.json")"
418+
value="$(jq --raw-output ".args.${arg}" "/tmp/build_config/build.json")"
396419
docker_cli+=("--build-arg" "${arg}=${value}")
397420
done
398421
fi
399422

400423
# Additional build labels
401424
if bashio::var.has_value "${labels}"; then
402425
for label in ${labels}; do
403-
value="$(jq --raw-output ".labels.\"${label}\"" "${TARGET}/build.json")"
426+
value="$(jq --raw-output ".labels.\"${label}\"" "/tmp/build_config/build.json")"
404427
docker_cli+=("--label" "${label}=${value}")
405428
done
406429
fi
@@ -439,10 +462,10 @@ function build_addon() {
439462
local docker_tags=()
440463

441464
# Read addon build.json
442-
if bashio::fs.file_exists "$TARGET/build.json"; then
443-
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "$TARGET/build.json")"
444-
args="$(jq --raw-output '.args // empty | keys[]' "$TARGET/build.json")"
445-
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
465+
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
466+
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "/tmp/build_config/build.json")"
467+
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
468+
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
446469
fi
447470

448471
# Set defaults build things
@@ -453,23 +476,23 @@ function build_addon() {
453476
# Additional build args
454477
if [ -n "$args" ]; then
455478
for arg in $args; do
456-
value="$(jq --raw-output ".args.$arg" "$TARGET/build.json")"
479+
value="$(jq --raw-output ".args.$arg" "/tmp/build_config/build.json")"
457480
docker_cli+=("--build-arg" "$arg=$value")
458481
done
459482
fi
460483

461484
# Read addon config.json
462-
name="$(jq --raw-output '.name // empty' "$TARGET/config.json" | sed "s/'//g")"
463-
description="$(jq --raw-output '.description // empty' "$TARGET/config.json" | sed "s/'//g")"
464-
url="$(jq --raw-output '.url // empty' "$TARGET/config.json")"
465-
raw_image="$(jq --raw-output '.image // empty' "$TARGET/config.json")"
466-
mapfile -t supported_arch < <(jq --raw-output '.arch // empty' "$TARGET/config.json")
485+
name="$(jq --raw-output '.name // empty' "/tmp/build_config/config.json" | sed "s/'//g")"
486+
description="$(jq --raw-output '.description // empty' "/tmp/build_config/config.json" | sed "s/'//g")"
487+
url="$(jq --raw-output '.url // empty' "/tmp/build_config/config.json")"
488+
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/config.json")"
489+
mapfile -t supported_arch < <(jq --raw-output '.arch // empty' "/tmp/build_config/config.json")
467490

468491
# Read version from config.json when VERSION is not set
469492
if [ -n "$VERSION" ]; then
470493
version="$VERSION"
471494
else
472-
version="$(jq --raw-output '.version' "$TARGET/config.json")"
495+
version="$(jq --raw-output '.version' "/tmp/build_config/config.json")"
473496
fi
474497

475498
# Check arch
@@ -513,13 +536,13 @@ function build_generic() {
513536
local docker_tags=()
514537

515538
# Read build.json
516-
if bashio::fs.file_exists "$TARGET/build.json"; then
517-
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "$TARGET/build.json")"
518-
args="$(jq --raw-output '.args // empty | keys[]' "$TARGET/build.json")"
519-
labels="$(jq --raw-output '.labels // empty | keys[]' "$TARGET/build.json")"
520-
raw_image="$(jq --raw-output '.image // empty' "$TARGET/build.json")"
521-
version_tag="$(jq --raw-output '.version_tag // false' "$TARGET/build.json")"
522-
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
539+
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
540+
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "/tmp/build_config/build.json")"
541+
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
542+
labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")"
543+
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")"
544+
version_tag="$(jq --raw-output '.version_tag // false' "/tmp/build_config/build.json")"
545+
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
523546
fi
524547

525548
# Set defaults build things
@@ -539,15 +562,15 @@ function build_generic() {
539562
# Additional build args
540563
if bashio::var.has_value "$args"; then
541564
for arg in $args; do
542-
value="$(jq --raw-output ".args.$arg" "$TARGET/build.json")"
565+
value="$(jq --raw-output ".args.$arg" "/tmp/build_config/build.json")"
543566
docker_cli+=("--build-arg" "$arg=$value")
544567
done
545568
fi
546569

547570
# Additional build labels
548571
if bashio::var.has_value "$labels"; then
549572
for label in $labels; do
550-
value="$(jq --raw-output ".labels.\"$label\"" "$TARGET/build.json")"
573+
value="$(jq --raw-output ".labels.\"$label\"" "/tmp/build_config/build.json")"
551574
docker_cli+=("--label" "$label=$value")
552575
done
553576
fi
@@ -584,13 +607,13 @@ function build_machine() {
584607
local docker_tags=()
585608

586609
# Read build.json
587-
if bashio::fs.file_exists "${TARGET}/build.json"; then
588-
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "${TARGET}/build.json")"
589-
args="$(jq --raw-output '.args // empty | keys[]' "${TARGET}/build.json")"
590-
labels="$(jq --raw-output '.labels // empty | keys[]' "${TARGET}/build.json")"
591-
raw_image="$(jq --raw-output '.image // empty' "${TARGET}/build.json")"
592-
version_tag="$(jq --raw-output '.version_tag // false' "${TARGET}/build.json")"
593-
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
610+
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
611+
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")"
612+
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
613+
labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")"
614+
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")"
615+
version_tag="$(jq --raw-output '.version_tag // false' "/tmp/build_config/build.json")"
616+
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
594617
fi
595618

596619
# Modify build_from
@@ -614,15 +637,15 @@ function build_machine() {
614637
# Additional build args
615638
if bashio::var.has_value "${args}"; then
616639
for arg in ${args}; do
617-
value="$(jq --raw-output ".args.${arg}" "${TARGET}/build.json")"
640+
value="$(jq --raw-output ".args.${arg}" "/tmp/build_config/build.json")"
618641
docker_cli+=("--build-arg" "${arg}=${value}")
619642
done
620643
fi
621644

622645
# Additional build labels
623646
if bashio::var.has_value "${labels}"; then
624647
for label in ${labels}; do
625-
value="$(jq --raw-output ".labels.\"${label}\"" "${TARGET}/build.json")"
648+
value="$(jq --raw-output ".labels.\"${label}\"" "/tmp/build_config/build.json")"
626649
docker_cli+=("--label" "${label}=${value}")
627650
done
628651
fi
@@ -904,6 +927,12 @@ mkdir -p /data
904927
init_crosscompile
905928
start_docker
906929

930+
# Convert configuration files to json if needed
931+
convert_to_json
932+
933+
# Copy configuration files to tmp
934+
copy_config_tmp
935+
907936
# Login into dockerhub & setup CodeNotary
908937
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWORD" ]; then
909938
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"

0 commit comments

Comments
 (0)