From 2c84e7c4933e15319e5311c176c662bf69c30bc5 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 13:19:52 +0100 Subject: [PATCH 01/21] Adding github action for flake8 and pytest --- .github/workflows/python-app.yml | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..ba3e310 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,37 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - 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 + - 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: Test with pytest + run: | + flask init-db + pytest From 61f85b469126e2a3c928a973dc533fa11319c7d2 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 13:44:47 +0100 Subject: [PATCH 02/21] Adding docker build and push to ghcr workflow --- .github/workflows/main.yml | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ae74102 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,56 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Server address of Docker registry. If not set then will default to Docker Hub + registry: ghcr.io + # Username used to log against the Docker registry + username: ${{ github.repository_owner }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.GHCR_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} From 15402239937e181b9e8e2d7526fe231cf2b85382 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 13:51:02 +0100 Subject: [PATCH 03/21] Removing unnecessary copy command. --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4cebcda..f5c4cec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN pip3 install -r requirements.txt COPY database /app/database COPY handlers /app/handlers COPY templates /app/templates -COPY instance /app/instance +#COPY instance /app/instance COPY app.py /app/app.py COPY schema.sql /app/schema.sql @@ -23,4 +23,4 @@ RUN flask init-db EXPOSE 5000 CMD [ "python3", "app.py" ] - \ No newline at end of file + From fefac6c46f9fab7a419a69af57c8b968763f845c Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 14:04:22 +0100 Subject: [PATCH 04/21] Adding workflow templates --- workflow-examples/docker-build-push-ghcr.yml | 56 ++++++++++++++++++++ workflow-examples/python-app.yml | 37 +++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 workflow-examples/docker-build-push-ghcr.yml create mode 100644 workflow-examples/python-app.yml diff --git a/workflow-examples/docker-build-push-ghcr.yml b/workflow-examples/docker-build-push-ghcr.yml new file mode 100644 index 0000000..ae74102 --- /dev/null +++ b/workflow-examples/docker-build-push-ghcr.yml @@ -0,0 +1,56 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Server address of Docker registry. If not set then will default to Docker Hub + registry: ghcr.io + # Username used to log against the Docker registry + username: ${{ github.repository_owner }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.GHCR_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/workflow-examples/python-app.yml b/workflow-examples/python-app.yml new file mode 100644 index 0000000..ba3e310 --- /dev/null +++ b/workflow-examples/python-app.yml @@ -0,0 +1,37 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - 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 + - 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: Test with pytest + run: | + flask init-db + pytest From e6627bd2505bebece4056d540f770285b8e47a32 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 14:18:41 +0100 Subject: [PATCH 05/21] Adding workflow for push to dockerhub --- .../docker-build-push-dockerhub.yml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 workflow-examples/docker-build-push-dockerhub.yml diff --git a/workflow-examples/docker-build-push-dockerhub.yml b/workflow-examples/docker-build-push-dockerhub.yml new file mode 100644 index 0000000..ae74102 --- /dev/null +++ b/workflow-examples/docker-build-push-dockerhub.yml @@ -0,0 +1,56 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Server address of Docker registry. If not set then will default to Docker Hub + registry: ghcr.io + # Username used to log against the Docker registry + username: ${{ github.repository_owner }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.GHCR_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} From 8cb25092b19ff665231d8b8558de05ffe10642f8 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 14:21:32 +0100 Subject: [PATCH 06/21] Adjusting workflow for docker hub --- workflow-examples/docker-build-push-dockerhub.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/workflow-examples/docker-build-push-dockerhub.yml b/workflow-examples/docker-build-push-dockerhub.yml index ae74102..d35c821 100644 --- a/workflow-examples/docker-build-push-dockerhub.yml +++ b/workflow-examples/docker-build-push-dockerhub.yml @@ -4,11 +4,8 @@ name: Build and push image to GitHub container registry # Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - pull_request: - branches: [ main ] + release: + types: [ created ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -33,9 +30,9 @@ jobs: # Server address of Docker registry. If not set then will default to Docker Hub registry: ghcr.io # Username used to log against the Docker registry - username: ${{ github.repository_owner }} + username: ${{ secrets.DOCKER_HUB_USERNAME }} # Password or personal access token used to log against the Docker registry - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} # Log out from the Docker registry at the end of a job logout: true # optional, default is true @@ -50,7 +47,7 @@ jobs: context: ./ file: ./Dockerfile push: true - tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest + tags: ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/flask-pytest-example:latest - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} From d71654a0b6ace91bc04f5bde0213aee5d22a8387 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 14:26:13 +0100 Subject: [PATCH 07/21] Removing registry --- workflow-examples/docker-build-push-dockerhub.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/workflow-examples/docker-build-push-dockerhub.yml b/workflow-examples/docker-build-push-dockerhub.yml index d35c821..394db7b 100644 --- a/workflow-examples/docker-build-push-dockerhub.yml +++ b/workflow-examples/docker-build-push-dockerhub.yml @@ -27,8 +27,6 @@ jobs: # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 uses: docker/login-action@v1.10.0 with: - # Server address of Docker registry. If not set then will default to Docker Hub - registry: ghcr.io # Username used to log against the Docker registry username: ${{ secrets.DOCKER_HUB_USERNAME }} # Password or personal access token used to log against the Docker registry From 8ffd887a1608a89631ac8a6352b4e99f1246164a Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 14:27:27 +0100 Subject: [PATCH 08/21] Removing workflows --- .github/workflows/main.yml | 56 -------------------------------- .github/workflows/python-app.yml | 37 --------------------- 2 files changed, 93 deletions(-) delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index ae74102..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,56 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Build and push image to GitHub container registry - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - pull_request: - branches: [ main ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - - name: Docker Login - # You may pin to the exact commit or the version. - # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - uses: docker/login-action@v1.10.0 - with: - # Server address of Docker registry. If not set then will default to Docker Hub - registry: ghcr.io - # Username used to log against the Docker registry - username: ${{ github.repository_owner }} - # Password or personal access token used to log against the Docker registry - password: ${{ secrets.GHCR_TOKEN }} - # Log out from the Docker registry at the end of a job - logout: true # optional, default is true - - - name: Set up Docker builder - id: buildx - uses: docker/setup-buildx-action@v1.6.0 - - - name: Build and push image - id: docker_build - uses: docker/build-push-action@v2 - with: - context: ./ - file: ./Dockerfile - push: true - tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index ba3e310..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,37 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python application - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.10 - uses: actions/setup-python@v2 - with: - python-version: "3.10" - - 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 - - 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: Test with pytest - run: | - flask init-db - pytest From 67817eec3c4b97ea607f09c505cc0427120475ef Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 14:58:34 +0100 Subject: [PATCH 09/21] Adding workflow for flake8 and pytest --- .github/workflows/flake8-pytest.yml | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/flake8-pytest.yml diff --git a/.github/workflows/flake8-pytest.yml b/.github/workflows/flake8-pytest.yml new file mode 100644 index 0000000..ba3e310 --- /dev/null +++ b/.github/workflows/flake8-pytest.yml @@ -0,0 +1,37 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - 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 + - 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: Test with pytest + run: | + flask init-db + pytest From 56dfcb693949ef0a1aeb964bf3f57a25ea04619d Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 15:00:21 +0100 Subject: [PATCH 10/21] Fixing removeentry route --- handlers/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/routes.py b/handlers/routes.py index d9d3b6e..06d5684 100644 --- a/handlers/routes.py +++ b/handlers/routes.py @@ -35,7 +35,7 @@ def remove_value(): db = get_db() db.execute( "DELETE FROM shoppinglist WHERE item = ?", - (item) # change this to (item,) <- the comma is what matters - don't ask me why... + (item,) # change this to (item,) <- the comma is what matters - don't ask me why... ) db.commit() return redirect("/", code=302) From 58c9c7b9845a6f1a0202d76f3b48cb3c1e71db5f Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 15:14:42 +0100 Subject: [PATCH 11/21] Adding docker build and push to GHCR --- .github/workflows/docker-build-push-ghcr.yml | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/docker-build-push-ghcr.yml diff --git a/.github/workflows/docker-build-push-ghcr.yml b/.github/workflows/docker-build-push-ghcr.yml new file mode 100644 index 0000000..ae74102 --- /dev/null +++ b/.github/workflows/docker-build-push-ghcr.yml @@ -0,0 +1,56 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Server address of Docker registry. If not set then will default to Docker Hub + registry: ghcr.io + # Username used to log against the Docker registry + username: ${{ github.repository_owner }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.GHCR_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} From bb7cd31b2c3d61ede56f1c486574c015dc61363a Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Mon, 6 Dec 2021 15:19:56 +0100 Subject: [PATCH 12/21] Adding push to docker.io upon release --- .../workflows/docker-build-push-dockerhub.yml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/docker-build-push-dockerhub.yml diff --git a/.github/workflows/docker-build-push-dockerhub.yml b/.github/workflows/docker-build-push-dockerhub.yml new file mode 100644 index 0000000..394db7b --- /dev/null +++ b/.github/workflows/docker-build-push-dockerhub.yml @@ -0,0 +1,51 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + release: + types: [ created ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Username used to log against the Docker registry + username: ${{ secrets.DOCKER_HUB_USERNAME }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.DOCKER_HUB_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} From 70309764d15a1f620f4da48f43932970f6f68be1 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 11:59:05 +0100 Subject: [PATCH 13/21] Fixing tag for docker hub image --- .github/workflows/docker-build-push-dockerhub.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build-push-dockerhub.yml b/.github/workflows/docker-build-push-dockerhub.yml index 394db7b..8d63bad 100644 --- a/.github/workflows/docker-build-push-dockerhub.yml +++ b/.github/workflows/docker-build-push-dockerhub.yml @@ -45,7 +45,7 @@ jobs: context: ./ file: ./Dockerfile push: true - tags: ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/flask-pytest-example:latest + tags: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/flask-pytest-example:latest - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} From 33ea2146443424d7216b0ca6da317392cb7af164 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 12:21:06 +0100 Subject: [PATCH 14/21] Removing workflows pre-demo --- .../workflows/docker-build-push-dockerhub.yml | 51 ----------------- .github/workflows/docker-build-push-ghcr.yml | 56 ------------------- .github/workflows/flake8-pytest.yml | 37 ------------ 3 files changed, 144 deletions(-) delete mode 100644 .github/workflows/docker-build-push-dockerhub.yml delete mode 100644 .github/workflows/docker-build-push-ghcr.yml delete mode 100644 .github/workflows/flake8-pytest.yml diff --git a/.github/workflows/docker-build-push-dockerhub.yml b/.github/workflows/docker-build-push-dockerhub.yml deleted file mode 100644 index 8d63bad..0000000 --- a/.github/workflows/docker-build-push-dockerhub.yml +++ /dev/null @@ -1,51 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Build and push image to GitHub container registry - -# Controls when the workflow will run -on: - release: - types: [ created ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - - name: Docker Login - # You may pin to the exact commit or the version. - # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - uses: docker/login-action@v1.10.0 - with: - # Username used to log against the Docker registry - username: ${{ secrets.DOCKER_HUB_USERNAME }} - # Password or personal access token used to log against the Docker registry - password: ${{ secrets.DOCKER_HUB_TOKEN }} - # Log out from the Docker registry at the end of a job - logout: true # optional, default is true - - - name: Set up Docker builder - id: buildx - uses: docker/setup-buildx-action@v1.6.0 - - - name: Build and push image - id: docker_build - uses: docker/build-push-action@v2 - with: - context: ./ - file: ./Dockerfile - push: true - tags: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/flask-pytest-example:latest - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/docker-build-push-ghcr.yml b/.github/workflows/docker-build-push-ghcr.yml deleted file mode 100644 index ae74102..0000000 --- a/.github/workflows/docker-build-push-ghcr.yml +++ /dev/null @@ -1,56 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Build and push image to GitHub container registry - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - pull_request: - branches: [ main ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - - name: Docker Login - # You may pin to the exact commit or the version. - # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - uses: docker/login-action@v1.10.0 - with: - # Server address of Docker registry. If not set then will default to Docker Hub - registry: ghcr.io - # Username used to log against the Docker registry - username: ${{ github.repository_owner }} - # Password or personal access token used to log against the Docker registry - password: ${{ secrets.GHCR_TOKEN }} - # Log out from the Docker registry at the end of a job - logout: true # optional, default is true - - - name: Set up Docker builder - id: buildx - uses: docker/setup-buildx-action@v1.6.0 - - - name: Build and push image - id: docker_build - uses: docker/build-push-action@v2 - with: - context: ./ - file: ./Dockerfile - push: true - tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/flake8-pytest.yml b/.github/workflows/flake8-pytest.yml deleted file mode 100644 index ba3e310..0000000 --- a/.github/workflows/flake8-pytest.yml +++ /dev/null @@ -1,37 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python application - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.10 - uses: actions/setup-python@v2 - with: - python-version: "3.10" - - 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 - - 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: Test with pytest - run: | - flask init-db - pytest From 046fdebec0225d8358d9073e2b00f61af096df21 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:21:02 +0100 Subject: [PATCH 15/21] Adding flake8 and pytest workflow --- .github/workflows/flake8-pytest.yml | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/flake8-pytest.yml diff --git a/.github/workflows/flake8-pytest.yml b/.github/workflows/flake8-pytest.yml new file mode 100644 index 0000000..ba3e310 --- /dev/null +++ b/.github/workflows/flake8-pytest.yml @@ -0,0 +1,37 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - 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 + - 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: Test with pytest + run: | + flask init-db + pytest From a40c4508576eeab54ed79bc12f309ea15237a938 Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:22:21 +0100 Subject: [PATCH 16/21] Intentionally adding an error to show failing workflow --- handlers/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/routes.py b/handlers/routes.py index 06d5684..d9d3b6e 100644 --- a/handlers/routes.py +++ b/handlers/routes.py @@ -35,7 +35,7 @@ def remove_value(): db = get_db() db.execute( "DELETE FROM shoppinglist WHERE item = ?", - (item,) # change this to (item,) <- the comma is what matters - don't ask me why... + (item) # change this to (item,) <- the comma is what matters - don't ask me why... ) db.commit() return redirect("/", code=302) From 123823ae6994921025c022e16d51bbeef4b7cb9f Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:24:46 +0100 Subject: [PATCH 17/21] Trying a fix. --- handlers/routes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/handlers/routes.py b/handlers/routes.py index d9d3b6e..33fbf83 100644 --- a/handlers/routes.py +++ b/handlers/routes.py @@ -36,6 +36,7 @@ def remove_value(): db.execute( "DELETE FROM shoppinglist WHERE item = ?", (item) # change this to (item,) <- the comma is what matters - don't ask me why... + #(item,) # change this to (item,) <- the comma is what matters - don't ask me why... ) db.commit() return redirect("/", code=302) From 6779680dfcd868b33be152df748c1211a24f7d2a Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:28:50 +0100 Subject: [PATCH 18/21] Fixing the route. --- handlers/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/routes.py b/handlers/routes.py index d9d3b6e..06d5684 100644 --- a/handlers/routes.py +++ b/handlers/routes.py @@ -35,7 +35,7 @@ def remove_value(): db = get_db() db.execute( "DELETE FROM shoppinglist WHERE item = ?", - (item) # change this to (item,) <- the comma is what matters - don't ask me why... + (item,) # change this to (item,) <- the comma is what matters - don't ask me why... ) db.commit() return redirect("/", code=302) From 54a1222730b98c0d7ceb56560f4101ecaa3ae13a Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:29:27 +0100 Subject: [PATCH 19/21] Fixing the route --- handlers/routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers/routes.py b/handlers/routes.py index 33fbf83..f2f198a 100644 --- a/handlers/routes.py +++ b/handlers/routes.py @@ -35,8 +35,8 @@ def remove_value(): db = get_db() db.execute( "DELETE FROM shoppinglist WHERE item = ?", - (item) # change this to (item,) <- the comma is what matters - don't ask me why... - #(item,) # change this to (item,) <- the comma is what matters - don't ask me why... + #(item) # change this to (item,) <- the comma is what matters - don't ask me why... + (item,) # change this to (item,) <- the comma is what matters - don't ask me why... ) db.commit() return redirect("/", code=302) From 0420b14507e9cc9ed43d4996603914fbc92ee8bc Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:41:00 +0100 Subject: [PATCH 20/21] Adding ghcr workflow --- .github/workflows/docker-build-push-ghcr.yml | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/docker-build-push-ghcr.yml diff --git a/.github/workflows/docker-build-push-ghcr.yml b/.github/workflows/docker-build-push-ghcr.yml new file mode 100644 index 0000000..ae74102 --- /dev/null +++ b/.github/workflows/docker-build-push-ghcr.yml @@ -0,0 +1,56 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Server address of Docker registry. If not set then will default to Docker Hub + registry: ghcr.io + # Username used to log against the Docker registry + username: ${{ github.repository_owner }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.GHCR_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} From 1621d9ca86092186523e39c1557f9ddc1daf5a1b Mon Sep 17 00:00:00 2001 From: Tim Irnich Date: Wed, 8 Dec 2021 17:46:41 +0100 Subject: [PATCH 21/21] Adding dockerhub workflow --- .../workflows/docker-build-push-dockerhub.yml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/docker-build-push-dockerhub.yml diff --git a/.github/workflows/docker-build-push-dockerhub.yml b/.github/workflows/docker-build-push-dockerhub.yml new file mode 100644 index 0000000..8d63bad --- /dev/null +++ b/.github/workflows/docker-build-push-dockerhub.yml @@ -0,0 +1,51 @@ +# This is a basic workflow to help you get started with Actions + +name: Build and push image to GitHub container registry + +# Controls when the workflow will run +on: + release: + types: [ created ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v1.10.0 + with: + # Username used to log against the Docker registry + username: ${{ secrets.DOCKER_HUB_USERNAME }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.DOCKER_HUB_TOKEN }} + # Log out from the Docker registry at the end of a job + logout: true # optional, default is true + + - name: Set up Docker builder + id: buildx + uses: docker/setup-buildx-action@v1.6.0 + + - name: Build and push image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/flask-pytest-example:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}