diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c48f72e..a3408eb 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: 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 }} diff --git a/Dockerfile b/Dockerfile index 840d9d5..d81d920 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 diff --git a/build.json b/build.json index 973ea3f..14f8212 100644 --- a/build.json +++ b/build.json @@ -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" + } +} \ No newline at end of file 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"