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 }} 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 }} 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 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 + 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) diff --git a/workflow-examples/docker-build-push-dockerhub.yml b/workflow-examples/docker-build-push-dockerhub.yml new file mode 100644 index 0000000..394db7b --- /dev/null +++ b/workflow-examples/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 }} 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