Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/docker-build-push-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -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 }}
56 changes: 56 additions & 0 deletions .github/workflows/docker-build-push-ghcr.yml
Original file line number Diff line number Diff line change
@@ -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 }}
37 changes: 37 additions & 0 deletions .github/workflows/flake8-pytest.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,4 +23,4 @@ RUN flask init-db
EXPOSE 5000

CMD [ "python3", "app.py" ]


2 changes: 1 addition & 1 deletion handlers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
51 changes: 51 additions & 0 deletions workflow-examples/docker-build-push-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -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 }}
56 changes: 56 additions & 0 deletions workflow-examples/docker-build-push-ghcr.yml
Original file line number Diff line number Diff line change
@@ -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 }}
37 changes: 37 additions & 0 deletions workflow-examples/python-app.yml
Original file line number Diff line number Diff line change
@@ -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