Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# Use lowercase name of repository, as buildx rejects the name otherwise.
echo "repository=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
Expand All @@ -35,14 +35,14 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ env.repository }}:${{ env.tag_name }}
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM python:3.10
FROM python:3.10-alpine

RUN addgroup --gid 1000 server && adduser --uid 1000 --gid 1000 --system server
RUN adduser -D server
WORKDIR /home/server

# Copy requirements first as to not disturb cache for other changes.
COPY requirements.txt .

# Install dependencies
RUN apk add -U --no-cache libpq-dev build-base git

RUN pip3 install -r requirements.txt && \
pip3 install gunicorn

Expand All @@ -14,6 +17,6 @@
# Finally, copy the entire source.
COPY . .

ENV FLASK_APP food.py

Check warning on line 20 in Dockerfile

View workflow job for this annotation

GitHub Actions / Push Docker image to GitHub Packages

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
EXPOSE 5000
ENTRYPOINT ["gunicorn", "-b", ":5000", "--access-logfile", "-", "--error-logfile", "-", "food:app"]
1 change: 0 additions & 1 deletion migrations/versions/b0abdec8d94c_initial_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "b0abdec8d94c"
down_revision = None
Expand Down
102 changes: 68 additions & 34 deletions thepantry/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,52 +49,86 @@ def common_css():
# Error handling
@app.errorhandler(404)
def page_not_found(e):
return render_template('errors/error.html',
error_code=404,
error_title="Page Not Found",
error_message="The page you're looking for doesn't exist or has been moved.",
error_details=str(e)), 404
return (
render_template(
"errors/error.html",
error_code=404,
error_title="Page Not Found",
error_message="The page you're looking for doesn't exist or has been moved.",
error_details=str(e),
),
404,
)


@app.errorhandler(500)
def server_error(e):
return render_template('errors/error.html',
error_code=500,
error_title="Server Error",
error_message="Something went wrong on our end. Please contact a developer.",
error_details=str(e)), 500
return (
render_template(
"errors/error.html",
error_code=500,
error_title="Server Error",
error_message="Something went wrong on our end. Please contact a developer.",
error_details=str(e),
),
500,
)


@app.errorhandler(401)
def unauthorized(e):
return render_template('errors/error.html',
error_code=401,
error_title="Unauthorized",
error_message="You need to be authenticated to access this resource.",
error_details=str(e)), 401
return (
render_template(
"errors/error.html",
error_code=401,
error_title="Unauthorized",
error_message="You need to be authenticated to access this resource.",
error_details=str(e),
),
401,
)


@app.errorhandler(403)
def forbidden(e):
return render_template('errors/error.html',
error_code=403,
error_title="Forbidden",
error_message="You don't have permission to access this resource.",
error_details=str(e)), 403
return (
render_template(
"errors/error.html",
error_code=403,
error_title="Forbidden",
error_message="You don't have permission to access this resource.",
error_details=str(e),
),
403,
)


@app.errorhandler(Exception)
def handle_exception(e):
if hasattr(e, 'code') and 400 <= e.code < 600:
if hasattr(e, "code") and 400 <= e.code < 600:
return e

if "MismatchingStateError" in str(e) or "invalid_request" in str(e):
session.clear()
return render_template('errors/error.html',
error_code="Auth",
error_title="Authentication Error",
error_message="There was a problem with your authentication session. Please try logging in again.",
error_details=str(e),
auto_redirect=True), 400

return render_template('errors/error.html',
error_code=500,
error_title="Server Error",
error_message="An unexpected error occurred.",
error_details=str(e)), 500
return (
render_template(
"errors/error.html",
error_code="Auth",
error_title="Authentication Error",
error_message="There was a problem with your authentication session. Please try logging in again.",
error_details=str(e),
auto_redirect=True,
),
400,
)

return (
render_template(
"errors/error.html",
error_code=500,
error_title="Server Error",
error_message="An unexpected error occurred.",
error_details=str(e),
),
500,
)
Loading