✏️ Switch form DockerHub to ghcr.io

This commit is contained in:
Sebastien Clement 2021-02-10 15:40:08 +01:00
parent eaf926f42e
commit 7e64da2d65

View File

@ -2,91 +2,90 @@ name: Build addon
on: on:
release: release:
types: [published] types: [ published ]
push: push:
workflow_dispatch: workflow_dispatch:
env: env:
TARGET: nextcloud_backup TARGET: nextcloud_backup
IMAGE: "{arch}-hassio-nextcloud-backup" IMAGE: "hassio-nextcloud-backup"
REPOSITORY: sebclemhassaddon REPOSITORY: ghcr.io/sebclem
jobs: jobs:
build-armhf: build-dockers:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: true fail-fast: true
matrix: matrix:
arch: [aarch64, amd64, armv7, i386] arch: [ aarch64, amd64, armv7, i386 ]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Add Qemu-user-static ${{matrix.arch}} - name: Add Qemu-user-static ${{matrix.arch}}
run: docker run --rm --privileged hassioaddons/qemu-user-static:latest run: docker run --rm --privileged hassioaddons/qemu-user-static:latest
- name: Set up Docker Buildx ${{matrix.arch}} - name: Set up Docker Buildx ${{matrix.arch}}
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
- name: Set Version Prod ${{matrix.arch}} - name: Set Version Prod ${{matrix.arch}}
if: github.event_name != 'workflow_dispatch' && github.event_name != 'push' if: github.event_name != 'workflow_dispatch' && github.event_name != 'push'
run: | run: |
version=${GITHUB_REF/refs\/tags\//} version=${GITHUB_REF/refs\/tags\//}
if [ -n "$version" ];then if [ -n "$version" ];then
tmp=$(mktemp) tmp=$(mktemp)
jq --arg version "$version" '.version=$version' ${{env.TARGET}}/config.json > "$tmp" && mv "$tmp" ${{env.TARGET}}/config.json jq --arg version "$version" '.version=$version' ${{env.TARGET}}/config.json > "$tmp" && mv "$tmp" ${{env.TARGET}}/config.json
fi fi
echo "version_type=prod" >> $GITHUB_ENV echo "version_type=prod" >> $GITHUB_ENV
- name: Set Version Test ${{matrix.arch}} - name: Set Version Test ${{matrix.arch}}
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
run: | run: |
version=dev_${GITHUB_RUN_ID} version=dev_${GITHUB_RUN_ID}
if [ -n "$version" ];then if [ -n "$version" ];then
tmp=$(mktemp) tmp=$(mktemp)
jq --arg version "$version" '.version=$version' ${{env.TARGET}}/config.json > "$tmp" && mv "$tmp" ${{env.TARGET}}/config.json jq --arg version "$version" '.version=$version' ${{env.TARGET}}/config.json > "$tmp" && mv "$tmp" ${{env.TARGET}}/config.json
fi fi
echo "version_type=dev" >> $GITHUB_ENV echo "version_type=dev" >> $GITHUB_ENV
- name: Get build option ${{matrix.arch}} - name: Get build option ${{matrix.arch}}
run: | run: |
echo "NAME=$(jq --raw-output '.name // empty' "${{env.TARGET}}/config.json" | sed "s/'//g")" >> $GITHUB_ENV echo "NAME=$(jq --raw-output '.name // empty' "${{env.TARGET}}/config.json" | sed "s/'//g")" >> $GITHUB_ENV
echo "DESCRIPTION=$(jq --raw-output '.description // empty' "${{env.TARGET}}/config.json" | sed "s/'//g")" >> $GITHUB_ENV echo "DESCRIPTION=$(jq --raw-output '.description // empty' "${{env.TARGET}}/config.json" | sed "s/'//g")" >> $GITHUB_ENV
echo "URL=$(jq --raw-output '.url // empty' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV echo "URL=$(jq --raw-output '.url // empty' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV
echo "VERSION=$(jq --raw-output '.version' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV echo "VERSION=$(jq --raw-output '.version' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV
echo "IMAGE=$(echo "${{env.IMAGE}}" | sed -r "s/\{arch\}/${{matrix.arch}}/g")" >> $GITHUB_ENV echo "BUILD_FROM=hassioaddons/base-${{matrix.arch}}:$(cat nextcloud_backup/.base_version)" >> $GITHUB_ENV
echo "BUILD_FROM=hassioaddons/base-${{matrix.arch}}:$(cat nextcloud_backup/.base_version)" >> $GITHUB_ENV
- name: Set Tags ${{matrix.arch}} - name: Set Tags ${{matrix.arch}}
run: | run: |
if [ "${{env.version_type}}" != "dev" ]; then if [ "${{env.version_type}}" != "dev" ]; then
echo "TAGS=${{env.REPOSITORY}}/${{env.IMAGE}}:latest, ${{env.REPOSITORY}}/${{env.IMAGE}}:$(jq --raw-output '.version' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV echo "TAGS=${{env.REPOSITORY}}/${{env.IMAGE}}/${{matrix.arch}}:latest, ${{env.REPOSITORY}}/${{env.IMAGE}}/${{matrix.arch}}:$(jq --raw-output '.version' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV
else else
echo "TAGS=${{env.REPOSITORY}}/${{env.IMAGE}}:dev, ${{env.REPOSITORY}}/${{env.IMAGE}}:$(jq --raw-output '.version' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV echo "TAGS=${{env.REPOSITORY}}/${{env.IMAGE}}/${{matrix.arch}}:dev, ${{env.REPOSITORY}}/${{env.IMAGE}}/${{matrix.arch}}:$(jq --raw-output '.version' "${{env.TARGET}}/config.json")" >> $GITHUB_ENV
fi fi
- name: Debug Env - name: Debug Env
run: | run: |
echo ${{env.IMAGE}} echo ${{env.VERSION}}
echo ${{env.VERSION}} echo ${{env.TAGS}}
echo ${{env.TAGS}}
- name: Login to DockerHub - name: Login to ghcr.io
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} registry: ghcr.io
password: ${{ secrets.DOCKER_PASSWORD }} username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push ${{matrix.arch}} - name: Build and push ${{matrix.arch}}
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
push: true push: true
context: ./${{env.TARGET}} context: ./${{env.TARGET}}
tags: ${{env.TAGS}} tags: ${{env.TAGS}}
labels: io.hass.name=${{env.NAME}}, io.hass.description=${{env.DESCRIPTION}}, io.hass.url=${{env.URL}}, io.hass.arch=${{matrix.arch}}, io.hass.version=${{env.VERSION}}, io.hass.type=addon labels: io.hass.name=${{env.NAME}}, io.hass.description=${{env.DESCRIPTION}}, io.hass.url=${{env.URL}}, io.hass.arch=${{matrix.arch}}, io.hass.version=${{env.VERSION}}, io.hass.type=addon
build-args: | build-args: |
BUILD_FROM=${{env.BUILD_FROM}} BUILD_FROM=${{env.BUILD_FROM}}
BUILD_VERSION=${{env.VERSION}} BUILD_VERSION=${{env.VERSION}}
file: ./${{env.TARGET}}/Dockerfile file: ./${{env.TARGET}}/Dockerfile