From 5e6a923c35248d69d8910ec4524fec13a10c02e0 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 17 Sep 2021 23:37:28 +0200 Subject: [PATCH] Attempt to setup GitHub Container Registry --- .github/workflows/github-container.yml | 117 +++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/github-container.yml diff --git a/.github/workflows/github-container.yml b/.github/workflows/github-container.yml new file mode 100644 index 00000000..1d4a5e6e --- /dev/null +++ b/.github/workflows/github-container.yml @@ -0,0 +1,117 @@ +name: Test, build and push tagged release to GitHub container repo + +on: + push: + tags: + - '*.*' + - 'master' + +jobs: + build: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - uses: olegtarasov/get-tag@v2.1 + id: tagName + +# with: +# tagRegex: "foobar-(.*)" # Optional. Returns specified group text as tag name. Full tag string is returned if regex is not defined. +# tagRegexGroup: 1 # Optional. Default is 1. + + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Create release metadata + run: | + # COPY'ed by Dockerfile into changedetectionio/ of the image, then read by the server in store.py + echo ${{ github.sha }} > changedetectionio/source.txt + echo ${{ github.ref }} > changedetectionio/tag.txt + + - name: Test with pytest + run: | + # Each test is totally isolated and performs its own cleanup/reset + cd changedetectionio; ./run_all_tests.sh + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + install: true + version: latest + driver-opts: image=moby/buildkit:master + + - name: tag + run : echo ${{ github.event.release.tag_name }} + + # Make a new token here https://github.com/settings/tokens/new?scopes=repo,write:packages&description=Github+Container+Registry + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CONTAINER_GITHUB_REGISTRY_TOKEN }} + + - name: Build and Push Docker Image to GitHub Repo + uses: docker/build-push-action@v2 + with: + push: true # Will only build if this is not here + tags: | + ghcr.io/${{ github.repository }}:${{ github.ref }} + ghcr.io/${{ github.repository }}:latest + context: ./ + file: ./Dockerfile + platforms: linux/amd64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + env: + SOURCE_NAME: ${{ steps.branch_name.outputs.SOURCE_NAME }} + SOURCE_BRANCH: ${{ steps.branch_name.outputs.SOURCE_BRANCH }} + SOURCE_TAG: ${{ steps.branch_name.outputs.SOURCE_TAG }} + + - name: Image digest + run: echo step SHA ${{ steps.vars.outputs.sha_short }} tag ${{steps.vars.outputs.tag}} branch ${{steps.vars.outputs.branch}} digest ${{ steps.docker_build.outputs.digest }} + + + + + + - name: Build and push tagged version + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: | + ${{ secrets.DOCKER_HUB_USERNAME }}/changedetection.io:${{ steps.tagName.outputs.tag }} + platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + env: + SOURCE_NAME: ${{ steps.branch_name.outputs.SOURCE_NAME }} + SOURCE_BRANCH: ${{ steps.branch_name.outputs.SOURCE_BRANCH }} + SOURCE_TAG: ${{ steps.branch_name.outputs.SOURCE_TAG }}