From e390422e26b2a5589a0e3976d87cd4b058d0ca6d Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 08:13:55 +0000 Subject: [PATCH 1/7] Allow yml and yaml files --- Dockerfile | 14 +++++++ build.json | 18 --------- build.yaml | 14 +++++++ builder.sh | 107 ++++++++++++++++++++++++++++++++++------------------- 4 files changed, 96 insertions(+), 57 deletions(-) delete mode 100644 build.json create mode 100644 build.yaml diff --git a/Dockerfile b/Dockerfile index 840d9d5..9a70074 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ ENV \ ARG BUILD_ARCH ARG VCN_VERSION +ARG YQ_VERSION RUN \ set -x \ @@ -40,6 +41,19 @@ RUN \ \ && rm -rf /root/go /root/.cache \ && mv vcn /usr/bin/vcn \ + && if [ "${BUILD_ARCH}" = "armhf" ] || [ "${BUILD_ARCH}" = "armv7" ]; then \ + wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm; \ + elif [ "${BUILD_ARCH}" = "aarch64" ]; then \ + wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm64; \ + elif [ "${BUILD_ARCH}" = "i386" ]; then \ + wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_386; \ + elif [ "${BUILD_ARCH}" = "amd64" ]; then \ + wget -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 \ + && yq --help \ \ && apk del .build-dependencies \ && rm -rf /usr/src/vcn diff --git a/build.json b/build.json deleted file mode 100644 index 973ea3f..0000000 --- a/build.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "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" - } -} diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..f396d8f --- /dev/null +++ b/build.yaml @@ -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" diff --git a/builder.sh b/builder.sh index 24bb22c..56d11d4 100755 --- a/builder.sh +++ b/builder.sh @@ -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 @@ -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 #### @@ -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 @@ -392,7 +415,7 @@ 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 @@ -400,7 +423,7 @@ function build_base() { # 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 @@ -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 @@ -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 @@ -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 @@ -539,7 +562,7 @@ 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 @@ -547,7 +570,7 @@ function build_generic() { # 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 @@ -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 @@ -614,7 +637,7 @@ 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 @@ -622,7 +645,7 @@ function build_machine() { # 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 @@ -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" From 1e6fbc98d739734114336e14c43ad1096f2d19f7 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 08:16:28 +0000 Subject: [PATCH 2/7] -q --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a70074..947036a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,13 +42,13 @@ RUN \ && rm -rf /root/go /root/.cache \ && mv vcn /usr/bin/vcn \ && if [ "${BUILD_ARCH}" = "armhf" ] || [ "${BUILD_ARCH}" = "armv7" ]; then \ - wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm; \ + wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm; \ elif [ "${BUILD_ARCH}" = "aarch64" ]; then \ - wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm64; \ + wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_arm64; \ elif [ "${BUILD_ARCH}" = "i386" ]; then \ - wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_386; \ + wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_386; \ elif [ "${BUILD_ARCH}" = "amd64" ]; then \ - wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64; \ + wget -q -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64; \ else \ exit 1; \ fi \ From d0d128449ce37c9a98a456e1cc86262abbd6d1c7 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 09:38:37 +0000 Subject: [PATCH 3/7] Use self refrence to build the builder --- .github/workflows/test.yml | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c48f72e..0969159 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: 'Test' +name: "Test" on: pull_request: @@ -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 @@ -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: ./ + 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 }} From 9a0fe8c8968e01af51bf3d4810ee2ce033531765 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 09:49:30 +0000 Subject: [PATCH 4/7] add back json --- build.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 build.json diff --git a/build.json b/build.json new file mode 100644 index 0000000..14f8212 --- /dev/null +++ b/build.json @@ -0,0 +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", + "YQ_VERSION": "v4.13.2" + }, + "labels": { + "io.hass.type": "builder", + "org.opencontainers.image.source": "https://github.com/home-assistant/builder" + } +} \ No newline at end of file From d4aafb447bee9bf2437157a06b206529c2bb42c2 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 09:53:28 +0000 Subject: [PATCH 5/7] revert test action change --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0969159..a3408eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@v2.3.4 - name: Build the builder - uses: ./ + uses: home-assistant/builder@master with: args: | --test \ From b8ec06266c71532f71d800e9cafd05d25bba65c7 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 09:53:40 +0000 Subject: [PATCH 6/7] Remove debug --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 947036a..41c28e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,7 +53,6 @@ RUN \ exit 1; \ fi \ && chmod +x /usr/bin/yq \ - && yq --help \ \ && apk del .build-dependencies \ && rm -rf /usr/src/vcn From 58c4a6216d9038d4e4d60981b9c78d436ec62bad Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sat, 25 Sep 2021 09:57:08 +0000 Subject: [PATCH 7/7] Adjust ARG --- Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 41c28e3..d81d920 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,10 @@ ENV \ VCN_OTP_EMPTY=true \ LANG=C.UTF-8 -ARG BUILD_ARCH -ARG VCN_VERSION -ARG YQ_VERSION +ARG \ + BUILD_ARCH \ + VCN_VERSION \ + YQ_VERSION RUN \ set -x \