Skip to content

Commit

Permalink
Allow yml and yaml files (#107)
Browse files Browse the repository at this point in the history
* Allow yml and yaml files

* -q

* Use self refrence to build the builder

* add back json

* revert test action change

* Remove debug

* Adjust ARG
  • Loading branch information
ludeeus committed Sep 25, 2021
1 parent bbaea08 commit 0893d6b
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 82 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test'
name: "Test"

on:
pull_request:
Expand All @@ -10,12 +10,12 @@ jobs:
outputs:
architectures: ${{ steps.info.outputs.architectures }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2.3.4
- name: Checkout the repository
uses: actions/checkout@v2.3.4

- name: Get information
id: info
uses: home-assistant/actions/helpers/info@master
- name: Get information
id: info
uses: home-assistant/actions/helpers/info@master

build:
name: Test action build
Expand All @@ -26,23 +26,23 @@ jobs:
matrix:
architecture: ${{ fromJson(needs.init.outputs.architectures) }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2.3.4
- name: Checkout the repository
uses: actions/checkout@v2.3.4

- name: Build the builder
uses: home-assistant/builder@master
with:
args: |
--test \
--amd64 \
--target /data \
--generic latest
- name: Build the builder
uses: home-assistant/builder@master
with:
args: |
--test \
--amd64 \
--target /data \
--generic latest
- name: Test ${{ matrix.architecture }} builder
uses: ./
with:
args: |
--test \
--${{ matrix.architecture }} \
--target /data \
--generic ${{ github.sha }}
- name: Test ${{ matrix.architecture }} builder
uses: ./
with:
args: |
--test \
--${{ matrix.architecture }} \
--target /data \
--generic ${{ github.sha }}
18 changes: 16 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ ENV \
VCN_OTP_EMPTY=true \
LANG=C.UTF-8

ARG BUILD_ARCH
ARG VCN_VERSION
ARG \
BUILD_ARCH \
VCN_VERSION \
YQ_VERSION

RUN \
set -x \
Expand Down Expand Up @@ -40,6 +42,18 @@ RUN \
\
&& rm -rf /root/go /root/.cache \
&& mv vcn /usr/bin/vcn \
&& if [ "${BUILD_ARCH}" = "armhf" ] || [ "${BUILD_ARCH}" = "armv7" ]; then \
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm; \
elif [ "${BUILD_ARCH}" = "aarch64" ]; then \
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm64; \
elif [ "${BUILD_ARCH}" = "i386" ]; then \
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_386; \
elif [ "${BUILD_ARCH}" = "amd64" ]; then \
wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64; \
else \
exit 1; \
fi \
&& chmod +x /usr/bin/yq \
\
&& apk del .build-dependencies \
&& rm -rf /usr/src/vcn
Expand Down
35 changes: 18 additions & 17 deletions build.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"image": "homeassistant/{arch}-builder",
"shadow_repository": "ghcr.io/home-assistant",
"build_from": {
"aarch64": "ghcr.io/home-assistant/aarch64-base:3.13",
"armv7": "ghcr.io/home-assistant/armv7-base:3.13",
"armhf": "ghcr.io/home-assistant/armhf-base:3.13",
"amd64": "ghcr.io/home-assistant/amd64-base:3.13",
"i386": "ghcr.io/home-assistant/i386-base:3.13"
},
"args": {
"VCN_VERSION": "0.9.6"
},
"labels": {
"io.hass.type": "builder",
"org.opencontainers.image.source": "https://github.com/home-assistant/builder"
}
}
"image": "homeassistant/{arch}-builder",
"shadow_repository": "ghcr.io/home-assistant",
"build_from": {
"aarch64": "ghcr.io/home-assistant/aarch64-base:3.13",
"armv7": "ghcr.io/home-assistant/armv7-base:3.13",
"armhf": "ghcr.io/home-assistant/armhf-base:3.13",
"amd64": "ghcr.io/home-assistant/amd64-base:3.13",
"i386": "ghcr.io/home-assistant/i386-base:3.13"
},
"args": {
"VCN_VERSION": "0.9.6",
"YQ_VERSION": "v4.13.2"
},
"labels": {
"io.hass.type": "builder",
"org.opencontainers.image.source": "https://github.com/home-assistant/builder"
}
}
14 changes: 14 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: "homeassistant/{arch}-builder"
shadow_repository: "ghcr.io/home-assistant"
build_from:
aarch64: "ghcr.io/home-assistant/aarch64-base:3.13"
armv7: "ghcr.io/home-assistant/armv7-base:3.13"
armhf: "ghcr.io/home-assistant/armhf-base:3.13"
amd64: "ghcr.io/home-assistant/amd64-base:3.13"
i386: "ghcr.io/home-assistant/i386-base:3.13"
args:
VCN_VERSION: "0.9.6"
YQ_VERSION: "v4.13.2"
labels:
io.hass.type: builder
org.opencontainers.image.source: "https://github.com/home-assistant/builder"
107 changes: 68 additions & 39 deletions builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function run_build() {
bashio::log.info "Generate repository shadow images"
docker tag "${repository}/${image}:${version}" "${shadow_repository}/${image}:${version}"
for tag_image in "${docker_tags[@]}"; do
bashio::log.info "Create shadow-image tag: ${tag_image}"
bashio::log.info "Create shadow-image tag: ${shadow_repository}/${image}:${tag_image}"
docker tag "${repository}/${image}:${version}" "${shadow_repository}/${image}:${tag_image}"
push_images+=("${shadow_repository}/${image}:${tag_image}")
done
Expand Down Expand Up @@ -339,6 +339,28 @@ function run_build() {
fi
}

function convert_to_json() {
# Convert [build|config].[yml|yaml] to json in a temp directory
for file in config build; do
if bashio::fs.file_exists "${TARGET}/${file}.yml"; then
yq e -N -M -o=json "${TARGET}/${file}.yml" > "/tmp/build_config/${file}.json"
elif bashio::fs.file_exists "${TARGET}/${file}.yaml"; then
yq e -N -M -o=json "${TARGET}/${file}.yaml" > "/tmp/build_config/${file}.json"
fi
done
}

function copy_config_tmp() {
# Copy [build|config].json to a temp directory
mkdir -p /tmp/build_config
for file in config build; do
if bashio::fs.file_exists "${TARGET}/${file}.json"; then
cp "${TARGET}/${file}.json" "/tmp/build_config/${file}.json"
fi
done
}



#### Build functions ####

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

# Read build.json
if bashio::fs.file_exists "${TARGET}/build.json"; then
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "${TARGET}/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "${TARGET}/build.json")"
labels="$(jq --raw-output '.labels // empty | keys[]' "${TARGET}/build.json")"
raw_image="$(jq --raw-output '.image // empty' "${TARGET}/build.json")"
version_tag="$(jq --raw-output '.version_tag // false' "${TARGET}/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")"
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")"
version_tag="$(jq --raw-output '.version_tag // false' "/tmp/build_config/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"

fi

# Set defaults build things
Expand Down Expand Up @@ -392,15 +415,15 @@ function build_base() {
# Additional build args
if bashio::var.has_value "${args}"; then
for arg in ${args}; do
value="$(jq --raw-output ".args.${arg}" "${TARGET}/build.json")"
value="$(jq --raw-output ".args.${arg}" "/tmp/build_config/build.json")"
docker_cli+=("--build-arg" "${arg}=${value}")
done
fi

# Additional build labels
if bashio::var.has_value "${labels}"; then
for label in ${labels}; do
value="$(jq --raw-output ".labels.\"${label}\"" "${TARGET}/build.json")"
value="$(jq --raw-output ".labels.\"${label}\"" "/tmp/build_config/build.json")"
docker_cli+=("--label" "${label}=${value}")
done
fi
Expand Down Expand Up @@ -439,10 +462,10 @@ function build_addon() {
local docker_tags=()

# Read addon build.json
if bashio::fs.file_exists "$TARGET/build.json"; then
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "$TARGET/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "$TARGET/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "/tmp/build_config/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
fi

# Set defaults build things
Expand All @@ -453,23 +476,23 @@ function build_addon() {
# Additional build args
if [ -n "$args" ]; then
for arg in $args; do
value="$(jq --raw-output ".args.$arg" "$TARGET/build.json")"
value="$(jq --raw-output ".args.$arg" "/tmp/build_config/build.json")"
docker_cli+=("--build-arg" "$arg=$value")
done
fi

# Read addon config.json
name="$(jq --raw-output '.name // empty' "$TARGET/config.json" | sed "s/'//g")"
description="$(jq --raw-output '.description // empty' "$TARGET/config.json" | sed "s/'//g")"
url="$(jq --raw-output '.url // empty' "$TARGET/config.json")"
raw_image="$(jq --raw-output '.image // empty' "$TARGET/config.json")"
mapfile -t supported_arch < <(jq --raw-output '.arch // empty' "$TARGET/config.json")
name="$(jq --raw-output '.name // empty' "/tmp/build_config/config.json" | sed "s/'//g")"
description="$(jq --raw-output '.description // empty' "/tmp/build_config/config.json" | sed "s/'//g")"
url="$(jq --raw-output '.url // empty' "/tmp/build_config/config.json")"
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/config.json")"
mapfile -t supported_arch < <(jq --raw-output '.arch // empty' "/tmp/build_config/config.json")

# Read version from config.json when VERSION is not set
if [ -n "$VERSION" ]; then
version="$VERSION"
else
version="$(jq --raw-output '.version' "$TARGET/config.json")"
version="$(jq --raw-output '.version' "/tmp/build_config/config.json")"
fi

# Check arch
Expand Down Expand Up @@ -513,13 +536,13 @@ function build_generic() {
local docker_tags=()

# Read build.json
if bashio::fs.file_exists "$TARGET/build.json"; then
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "$TARGET/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "$TARGET/build.json")"
labels="$(jq --raw-output '.labels // empty | keys[]' "$TARGET/build.json")"
raw_image="$(jq --raw-output '.image // empty' "$TARGET/build.json")"
version_tag="$(jq --raw-output '.version_tag // false' "$TARGET/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
build_from="$(jq --raw-output ".build_from.$build_arch // empty" "/tmp/build_config/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")"
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")"
version_tag="$(jq --raw-output '.version_tag // false' "/tmp/build_config/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
fi

# Set defaults build things
Expand All @@ -539,15 +562,15 @@ function build_generic() {
# Additional build args
if bashio::var.has_value "$args"; then
for arg in $args; do
value="$(jq --raw-output ".args.$arg" "$TARGET/build.json")"
value="$(jq --raw-output ".args.$arg" "/tmp/build_config/build.json")"
docker_cli+=("--build-arg" "$arg=$value")
done
fi

# Additional build labels
if bashio::var.has_value "$labels"; then
for label in $labels; do
value="$(jq --raw-output ".labels.\"$label\"" "$TARGET/build.json")"
value="$(jq --raw-output ".labels.\"$label\"" "/tmp/build_config/build.json")"
docker_cli+=("--label" "$label=$value")
done
fi
Expand Down Expand Up @@ -584,13 +607,13 @@ function build_machine() {
local docker_tags=()

# Read build.json
if bashio::fs.file_exists "${TARGET}/build.json"; then
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "${TARGET}/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "${TARGET}/build.json")"
labels="$(jq --raw-output '.labels // empty | keys[]' "${TARGET}/build.json")"
raw_image="$(jq --raw-output '.image // empty' "${TARGET}/build.json")"
version_tag="$(jq --raw-output '.version_tag // false' "${TARGET}/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "${TARGET}/build.json")"
if bashio::fs.file_exists "/tmp/build_config/build.json"; then
build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")"
args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")"
labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")"
raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")"
version_tag="$(jq --raw-output '.version_tag // false' "/tmp/build_config/build.json")"
shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")"
fi

# Modify build_from
Expand All @@ -614,15 +637,15 @@ function build_machine() {
# Additional build args
if bashio::var.has_value "${args}"; then
for arg in ${args}; do
value="$(jq --raw-output ".args.${arg}" "${TARGET}/build.json")"
value="$(jq --raw-output ".args.${arg}" "/tmp/build_config/build.json")"
docker_cli+=("--build-arg" "${arg}=${value}")
done
fi

# Additional build labels
if bashio::var.has_value "${labels}"; then
for label in ${labels}; do
value="$(jq --raw-output ".labels.\"${label}\"" "${TARGET}/build.json")"
value="$(jq --raw-output ".labels.\"${label}\"" "/tmp/build_config/build.json")"
docker_cli+=("--label" "${label}=${value}")
done
fi
Expand Down Expand Up @@ -904,6 +927,12 @@ mkdir -p /data
init_crosscompile
start_docker

# Convert configuration files to json if needed
convert_to_json

# Copy configuration files to tmp
copy_config_tmp

# Login into dockerhub & setup CodeNotary
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWORD" ]; then
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
Expand Down

0 comments on commit 0893d6b

Please sign in to comment.