Updated base images (#87) #289
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Image CI | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| Setup: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| build: ${{ steps.set-matrix.outputs.build }} | |
| build_matrix: ${{ steps.set-matrix.outputs.build_matrix }} | |
| push_matrix: ${{ steps.set-matrix.outputs.push_matrix }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Matrix-Jobs | |
| id: set-matrix | |
| env: | |
| GITHUB_EVENT_NAME: ${{ github.event_name }} | |
| run: | | |
| echo "Run triggered by: ${GITHUB_EVENT_NAME}" | |
| CHANGED_FILES=$(git --no-pager diff HEAD HEAD~1 --name-only | grep -v -E '^\.' | cut -d'/' -f1 | uniq) | |
| echo "Changed files:" | |
| echo "$CHANGED_FILES" | |
| if [ $(echo $CHANGED_FILES | wc -l | xargs) -gt 0 ]; then | |
| BUILD="no" | |
| for i in $(echo $CHANGED_FILES); do | |
| echo "Checking $i" | |
| if [[ -d $i ]]; then | |
| BUILD="yes" | |
| fi | |
| done | |
| echo "build=$BUILD" >> $GITHUB_OUTPUT | |
| else | |
| if [[ ${GITHUB_EVENT_NAME} == 'workflow_dispatch' ]]; then | |
| echo "build=yes" >> $GITHUB_OUTPUT | |
| else | |
| echo "build=no" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| if ! [[ ${GITHUB_EVENT_NAME} == 'workflow_dispatch' ]]; then | |
| git --no-pager diff HEAD HEAD~1 --name-only | grep -v -E '^\.' | grep -E '\/' | cut -d'/' -f1 | uniq | xargs echo -n | jq -Rsc 'split(" ") | { "addons": (.) }' > .github/resources/addons.json | |
| else | |
| ls -d */ | cut -d'/' -f1 | uniq | xargs echo -n | jq -Rsc 'split(" ") | { "addons": (.) }' > .github/resources/addons.json | |
| fi | |
| build_matrix=$(jq -sc '.[0] * .[1]' .github/resources/addons.json .github/resources/platforms.json) | |
| echo "build_matrix=${build_matrix}" >> $GITHUB_OUTPUT | |
| echo "push_matrix=$(cat .github/resources/addons.json)" >> $GITHUB_OUTPUT | |
| Build: | |
| runs-on: ubuntu-latest | |
| needs: Setup | |
| if: needs.Setup.outputs.build == 'yes' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| ${{ insert }}: ${{ fromJson(needs.Setup.outputs.build_matrix) }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Login to Docker Hub | |
| if: github.event_name == 'push' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKER_HUB_USERNAME || github.actor }} | |
| password: ${{ secrets.DOCKER_HUB_DEPLOY_KEY }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Install Perquisites | |
| run: | | |
| sudo snap install yq | |
| curl -L https://omnitruck.cinc.sh/install.sh | sudo bash -s -- -P cinc-auditor -v 5 | |
| - name: Build | |
| env: | |
| DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || github.actor }} | |
| ADDON: ${{ matrix.addons }} | |
| BUILD_NR: ${{ github.run_number }} | |
| PLATFORM: ${{ matrix.platforms }} | |
| working-directory: ./${{ matrix.addons }} | |
| run: | | |
| ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}') | |
| VERSION=$(yq -r .version config.yaml) | |
| echo "" | |
| echo "=============================================================" | |
| echo "Building: ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" | |
| echo "=============================================================" | |
| echo "" | |
| docker buildx build \ | |
| --tag "${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" \ | |
| --platform ${PLATFORM} \ | |
| --build-arg "VERSION=${VERSION}" \ | |
| --load \ | |
| -f Dockerfile . | |
| - name: Test | |
| env: | |
| DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || github.actor }} | |
| ADDON: ${{ matrix.addons }} | |
| BUILD_NR: ${{ github.run_number }} | |
| PLATFORM: ${{ matrix.platforms }} | |
| working-directory: ./${{ matrix.addons }} | |
| run: | | |
| set -a | |
| ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}') | |
| VERSION=$(yq -r .version config.yaml) | |
| echo "" | |
| echo "=============================================================" | |
| echo "Testing: ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" | |
| echo "=============================================================" | |
| echo "" | |
| exec ./test/test.sh | |
| echo "" | |
| - name: Push Images | |
| if: github.event_name == 'push' | |
| env: | |
| DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || github.actor }} | |
| ADDON: ${{ matrix.addons }} | |
| BUILD_NR: ${{ github.run_number }} | |
| PLATFORM: ${{ matrix.platforms }} | |
| working-directory: ./${{ matrix.addons }} | |
| run: | | |
| ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}') | |
| VERSION=$(yq -r .version config.yaml) | |
| echo "" | |
| echo "=============================================================" | |
| echo "Pushing: ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" | |
| echo "=============================================================" | |
| echo "" | |
| docker tag "${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" "${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}" | |
| docker push "${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" | |
| docker push "${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}" | |
| Shared-Manifest: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - Build | |
| - Setup | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| ${{ insert }}: ${{ fromJson(needs.Setup.outputs.push_matrix) }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKER_HUB_USERNAME || github.actor }} | |
| password: ${{ secrets.DOCKER_HUB_DEPLOY_KEY }} | |
| - name: Create and push shared manifest | |
| env: | |
| DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || github.actor }} | |
| ADDON: ${{ matrix.addons }} | |
| BUILD_NR: ${{ github.run_number }} | |
| working-directory: ./${{ matrix.addons }} | |
| run: | | |
| VERSION=$(yq -r .version config.yaml) | |
| echo "" | |
| echo "=============================================================" | |
| echo "Pushing shared manifest: ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}" | |
| echo "=============================================================" | |
| echo "" | |
| echo "#!/bin/bash" > push-shared-tags.sh | |
| echo -n "docker manifest create ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}" >> push-shared-tags.sh | |
| while read -r PLATFORM; do | |
| ARCH=$(echo "${PLATFORM}" | awk -F "/" '{print $2$3}') | |
| echo -n " ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}-${ARCH}-${BUILD_NR}" >> push-shared-tags.sh | |
| done <<< "$(cat ../.github/resources/platforms.json | jq -r '.platforms | join("\n")')" | |
| echo "" >> push-shared-tags.sh | |
| echo "docker manifest push ${DOCKER_USER}/hass-addon-${ADDON}:${VERSION}" >> push-shared-tags.sh | |
| echo "exit 0" >> push-shared-tags.sh | |
| cat push-shared-tags.sh | |
| chmod +x ./push-shared-tags.sh | |
| ./push-shared-tags.sh | |
| Check-Build: | |
| if: ${{ always() }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - Build | |
| - Shared-Manifest | |
| steps: | |
| - run: | | |
| result="${{ needs.Build.result }}" | |
| if [[ $result == "success" || $result == "skipped" ]]; then | |
| exit 0 | |
| else | |
| exit 1 | |
| fi |