Skip to content

try to fix deployment #367 #37

try to fix deployment #367

try to fix deployment #367 #37

Workflow file for this run

name: Deploy addons
on:
push:
branches:
- master
workflow_run:
workflows: ["CI"]
branches: [master]
types:
- completed
jobs:
check-addon-changes:
runs-on: ubuntu-latest
outputs:
changedAddons: ${{ steps.filter.outputs.changes }}
steps:
- name: ↩️ Checkout
uses: actions/checkout@v4
- name: 📂 Detect chanced files
uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/paths-filter.yml
build-addon:
name: Build and deploy addon
if: ${{ needs.check-addon-changes.outputs.changedAddons != '[]' }}
runs-on: ubuntu-latest
needs: check-addon-changes
strategy:
fail-fast: false
matrix:
addon: ${{ fromJSON(needs.check-addon-changes.outputs.changedAddons) }}
steps:
- name: ↩️ Checkout
uses: actions/checkout@v4
- name: ℹ️ Gather addon info
id: information
uses: frenck/action-addon-information@v1
with:
path: "./${{ matrix.addon }}/"
- name: 🗄️ Cache docker layers
uses: actions/cache@v4
with:
path: /tmp/buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.addon }}-${{ hashFiles('**/Dockerfile') }}
restore-keys: ${{ runner.os }}-buildx-${{ matrix.addon }}-
- name: 🔖 Create addon image tags
id: tags
shell: bash
run: |
imagetemplate=${{ steps.information.outputs.image }}
version=${{ steps.information.outputs.version }}
echo "Using imagetemplate '$imagetemplate'"
echo "armhf=${imagetemplate/\{arch\}/armhf}:${version}" >> $GITHUB_ENV
echo "armv7=${imagetemplate/\{arch\}/armv7}:${version}" >> $GITHUB_ENV
echo "aarch64=${imagetemplate/\{arch\}/aarch64}:${version}" >> $GITHUB_ENV
echo "amd64=${imagetemplate/\{arch\}/amd64}:${version}" >> $GITHUB_ENV
echo "i386=${imagetemplate/\{arch\}/i386}:${version}" >> $GITHUB_ENV
echo "Tag for armhf: ${{ env.armhf }}"
echo "Tag for armv7: ${{ env.armv7 }}"
echo "Tag for aarch64: ${{ env.aarch64 }}"
echo "Tag for amd64: ${{ env.amd64 }}"
echo "Tag for i386: ${{ env.i386 }}"
if [[ ! "${{ env.armhf }}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*(:[a-z0-9]+([._-][a-z0-9]+)*)?$ ]]; then
echo "ERROR: Invalid tag format for armhf: ${{ env.armhf }}"
exit 1
fi
if [[ ! "${{ env.armv7 }}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*(:[a-z0-9]+([._-][a-z0-9]+)*)?$ ]]; then
echo "ERROR: Invalid tag format for armv7: ${{ env.armv7 }}"
exit 1
fi
if [[ ! "${{ env.aarch64 }}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*(:[a-z0-9]+([._-][a-z0-9]+)*)?$ ]]; then
echo "ERROR: Invalid tag format for aarch64: ${{ env.aarch64 }}"
exit 1
fi
if [[ ! "${{ env.amd64 }}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*(:[a-z0-9]+([._-][a-z0-9]+)*)?$ ]]; then
echo "ERROR: Invalid tag format for amd64: ${{ env.amd64 }}"
exit 1
fi
if [[ ! "${{ env.i386 }}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*(:[a-z0-9]+([._-][a-z0-9]+)*)?$ ]]; then
echo "ERROR: Invalid tag format for i386: ${{ env.i386 }}"
exit 1
fi
- name: 🏷️ Create addon labels
id: labels
shell: bash
run: |
labels="io.hass.version=${{ steps.information.outputs.version }}"
labels=$(printf "$labels\nio.hass.name=${{ steps.information.outputs.name }}")
labels=$(printf "$labels\nio.hass.description=${{ steps.information.outputs.description }}")
labels=$(printf "$labels\nio.hass.type=addon")
labels=$(printf "$labels\nio.hass.url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/main/${{ matrix.addon }}")
echo "Using version ${{ steps.information.outputs.version }} as tag"
clean_version=$(echo ${{ steps.information.outputs.version }} | sed 's/^://')
labels=$(printf "$labels\norg.opencontainers.image.title=${{ steps.information.outputs.name }}")
labels=$(printf "$labels\norg.opencontainers.image.description=${{ steps.information.outputs.description }}")
labels=$(printf "$labels\norg.opencontainers.image.version=$clean_version")
labels=$(printf "$labels\norg.opencontainers.image.authors=FaserF <github@fabiseitz.de>")
labels=$(printf "$labels\norg.opencontainers.image.url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}")
labels=$(printf "$labels\norg.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/main/${{ matrix.addon }}")
labels=$(printf "$labels\norg.opencontainers.image.created=$(date -Is)")
labels=$(printf "$labels\norg.opencontainers.image.revision=${GITHUB_SHA}")
echo "Generic labels: $labels"
armhf_labels=$(printf "$labels\nio.hass.arch=armhf")
armv7_labels=$(printf "$labels\nio.hass.arch=armv7")
aarch64_labels=$(printf "$labels\nio.hass.arch=aarch64")
amd64_labels=$(printf "$labels\nio.hass.arch=amd64")
i386_labels=$(printf "$labels\nio.hass.arch=i386")
# allow multiline outputs
armhf_labels="${armhf_labels//$'\n'/'%0A'}"
armv7_labels="${armv7_labels//$'\n'/'%0A'}"
aarch64_labels="${aarch64_labels//$'\n'/'%0A'}"
amd64_labels="${amd64_labels//$'\n'/'%0A'}"
i386_labels="${i386_labels//$'\n'/'%0A'}"
echo "armhf_labels=${armhf_labels}" >> $GITHUB_ENV
echo "armv7_labels=${armv7_labels}" >> $GITHUB_ENV
echo "aarch64_labels=${aarch64_labels}" >> $GITHUB_ENV
echo "amd64_labels=${amd64_labels}" >> $GITHUB_ENV
echo "i386_labels=${i386_labels}" >> $GITHUB_ENV
- name: 💽 Create addon build-args
id: build_args
shell: bash
run: |
echo "armhf_BUILD_FROM=$(yq -r '.build_from.armhf // ""' ${{ steps.information.outputs.build }})" >> $GITHUB_ENV
echo "armv7_BUILD_FROM=$(yq -r '.build_from.armv7 // ""' ${{ steps.information.outputs.build }})" >> $GITHUB_ENV
echo "aarch64_BUILD_FROM=$(yq -r '.build_from.aarch64 // ""' ${{ steps.information.outputs.build }})" >> $GITHUB_ENV
echo "amd64_BUILD_FROM=$(yq -r '.build_from.amd64 // ""' ${{ steps.information.outputs.build }})" >> $GITHUB_ENV
echo "i386_BUILD_FROM=$(yq -r '.build_from.i386 // ""' ${{ steps.information.outputs.build }})" >> $GITHUB_ENV
- name: 🏗️ Set up QEMU
uses: docker/setup-qemu-action@v3
- name: 🏗️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 💿 Build Addon - armhf
if: ${{ steps.information.outputs.armhf == 'true' }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.addon }}
push: false
load: true
file: ${{ matrix.addon }}/Dockerfile
tags: ${{ env.armhf }}
labels: |
${{ env.armhf_labels }}
build-args: ${{ env.armhf_BUILD_FROM }}
cache-from: type=local,src=/tmp/buildx-cache/armhf
cache-to: type=local,dest=/tmp/buildx-cache-new/armhf
- name: 💿 Build Addon - armv7
if: ${{ steps.information.outputs.armv7 == 'true' }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.addon }}
push: false
load: true
file: ${{ matrix.addon }}/Dockerfile
tags: ${{ env.armv7 }}
labels: |
${{ env.armv7_labels }}
build-args: ${{ env.armv7_BUILD_FROM }}
cache-from: type=local,src=/tmp/buildx-cache/armv7
cache-to: type=local,dest=/tmp/buildx-cache-new/armv7
- name: 💿 Build Addon - aarch64
if: ${{ steps.information.outputs.aarch64 == 'true' }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.addon }}
push: false
load: true
file: ${{ matrix.addon }}/Dockerfile
tags: ${{ env.aarch64 }}
labels: |
${{ env.aarch64_labels }}
build-args: ${{ env.aarch64_BUILD_FROM }}
cache-from: type=local,src=/tmp/buildx-cache/aarch64
cache-to: type=local,dest=/tmp/buildx-cache-new/aarch64
- name: 💿 Build Addon - amd64
if: ${{ steps.information.outputs.amd64 == 'true' }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.addon }}
push: false
load: true
file: ${{ matrix.addon }}/Dockerfile
tags: ${{ env.amd64 }}
labels: |
${{ env.amd64_labels }}
build-args: ${{ env.amd64_BUILD_FROM }}
cache-from: type=local,src=/tmp/buildx-cache/amd64
cache-to: type=local,dest=/tmp/buildx-cache-new/amd64
- name: 💿 Build Addon - i386
if: ${{ steps.information.outputs.i386 == 'true' }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.addon }}
push: false
load: true
file: ${{ matrix.addon }}/Dockerfile
tags: ${{ env.i386 }}
labels: |
${{ env.i386_labels }}
build-args: ${{ env.i386_BUILD_FROM }}
cache-from: type=local,src=/tmp/buildx-cache/i386
cache-to: type=local,dest=/tmp/buildx-cache-new/i386
# Fix for https://github.com/docker/build-push-action/issues/252
- name: 🗄️ Update cache Folder
run: |
rm -rf /tmp/buildx-cache
mv /tmp/buildx-cache-new /tmp/buildx-cache
- name: 🔑 GHCR Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🚀 Push images
shell: bash
run: |
if [ "${{ steps.information.outputs.armhf }}" = 'true' ]; then
docker push ${{ env.armhf }}
fi
if [ "${{ steps.information.outputs.armv7 }}" = 'true' ]; then
docker push ${{ env.armv7 }}
fi
if [ "${{ steps.information.outputs.aarch64 }}" = 'true' ]; then
docker push ${{ env.aarch64 }}
fi
if [ "${{ steps.information.outputs.amd64 }}" = 'true' ]; then
docker push ${{ env.amd64 }}
fi
if [ "${{ steps.information.outputs.i386 }}" = 'true' ]; then
docker push ${{ env.i386 }}
fi