Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add govuk frontend jinja #23

Merged
merged 12 commits into from
Nov 28, 2023
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
13 changes: 0 additions & 13 deletions .github/workflows/deploy-to-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ env:
ECR_REGION: ${{ vars.DEVELOPMENT_ECR_REGION }}
ECR_ROLE_TO_ASSUME: ${{ secrets.DEVELOPMENT_ECR_ROLE_TO_ASSUME }}

# AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID }}
# AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET }}

# FLASK_APP_SECRET: ${{ secrets.DEV_FLASK_APP_SECRET }}
# OPS_ENG_REPORTS_ENCRYPT_KEY: ${{ secrets.DEV_OPS_ENG_REPORTS_ENCRYPT_KEY }}
# OPERATIONS_ENGINEERING_REPORTS_API_KEY: ${{ secrets.DEV_OPERATIONS_ENGINEERING_REPORTS_API_KEY }}

jobs:
build-push:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -83,9 +76,3 @@ jobs:
--set image.repository=${ECR_REGISTRY}/${ECR_REPOSITORY} \
--set ingress.host=operations-engineering-example-${ENV}.cloud-platform.service.justice.gov.uk \
--set ingress.identifier=example-ingress-operations-engineering-example-${ENV}-green

# --set application.auth0ClientId=${AUTH0_CLIENT_ID} \
# --set application.auth0ClientSecret=${AUTH0_CLIENT_SECRET} \
# --set application.appSecretKey=${FLASK_APP_SECRET} \
# --set application.encryptionKey=${OPS_ENG_REPORTS_ENCRYPT_KEY} \
# --set application.apiKey=${OPERATIONS_ENGINEERING_REPORTS_API_KEY} \
24 changes: 0 additions & 24 deletions .github/workflows/deploy-to-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ env:
ECR_REGION: ${{ vars.PRODUCTION_ECR_REGION }}
ECR_ROLE_TO_ASSUME: ${{ secrets.PRODUCTION_ECR_ROLE_TO_ASSUME }}

# AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID }}
# AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET }}

# FLASK_APP_SECRET: ${{ secrets.PROD_FLASK_APP_SECRET }}
# OPS_ENG_REPORTS_ENCRYPT_KEY: ${{ secrets.PROD_OPS_ENG_REPORTS_ENCRYPT_KEY }}
# OPERATIONS_ENGINEERING_REPORTS_API_KEY: ${{ secrets.PROD_OPERATIONS_ENGINEERING_REPORTS_API_KEY }}

jobs:
build-push:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -89,20 +82,3 @@ jobs:
--set image.repository=${ECR_REGISTRY}/${ECR_REPOSITORY} \
--set ingress.host=operations-engineering-example-${ENV}.cloud-platform.service.justice.gov.uk \
--set ingress.identifier=example-ingress-operations-engineering-example-${ENV}-green


# --set application.auth0ClientId=${AUTH0_CLIENT_ID} \
# --set application.auth0ClientSecret=${AUTH0_CLIENT_SECRET} \
# --set application.appSecretKey=${FLASK_APP_SECRET} \
# --set application.encryptionKey=${OPS_ENG_REPORTS_ENCRYPT_KEY} \
# --set application.apiKey=${OPERATIONS_ENGINEERING_REPORTS_API_KEY} \

# - name: Report failure to Slack
# if: always()
# uses: ravsamhq/notify-slack-action@v2
# with:
# status: ${{ job.status }}
# notify_when: "failure"
# notification_title: "Failed to deploy the example application to production"
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
58 changes: 51 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
.env
.venv
.terraform/
coverage/
venv/
env/
.DS_STORE
.vscode
*.code-workspace
*.sha256

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

### Terraform ###
.terraform/
terraform.tfstate
__pycache__/

### GOV.UK Frontend ###
application/static/*
govuk_components*

### Flask ###
instance/*
!instance/.gitignore
.webassets-cache

### Flask.Python Stack ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build
lib/
lib64/
var/
wheels/

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
coverage/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.12.0-alpine3.17

# Set working directory in the container
WORKDIR /app/operations-engineering-example
WORKDIR /app

# Set to run as non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup -u 1051
Expand All @@ -16,10 +16,14 @@ RUN \

# Copy dirs/files from the repo to the container working directory
COPY requirements.txt requirements.txt
COPY ops_eng_app ops_eng_app
COPY application application
COPY build.py build.py
COPY config.py config.py

# Install deps and run build
RUN pip3 install --upgrade pip && \
pip3 install --no-cache-dir --upgrade -r requirements.txt
RUN python build.py

# Send logs direct to terminal
ENV PYTHONUNBUFFERED 1
Expand All @@ -31,6 +35,6 @@ USER 1051
EXPOSE 1551

# Use in production, bind to another port so not to run as root
ENTRYPOINT gunicorn ops_eng_app:app \
ENTRYPOINT gunicorn application:app \
--bind 0.0.0.0:1551 \
--timeout 120
28 changes: 28 additions & 0 deletions application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from flask import Flask, render_template, url_for
import logging
import os

from flask import Flask
from flask_cors import CORS
from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader

from config import Config


app = Flask(__name__)
app.config.from_object(Config)

app.jinja_loader = ChoiceLoader(
[
PackageLoader("application"),
PrefixLoader({"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")}),
]
)

app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True


@app.route("/", methods=["GET", "POST"])
def index():
return render_template("index.html")
15 changes: 15 additions & 0 deletions application/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% block pageTitle %}Page not found – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% set mainClasses = "govuk-main-wrapper--l" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Page not found</h1>
<p class="govuk-body">If you typed the web address, check it is correct.</p>
<p class="govuk-body">If you pasted the web address, check you copied the entire address.</p>
</div>
</div>
{% endblock %}
15 changes: 15 additions & 0 deletions application/templates/429.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% block pageTitle %}Too many requests – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% set mainClasses = "govuk-main-wrapper--l" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Sorry, there is a problem</h1>
<p class="govuk-body">There have been too many attempts to access this page.</p>
<p class="govuk-body">Try again later.</p>
</div>
</div>
{% endblock %}
15 changes: 15 additions & 0 deletions application/templates/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% block pageTitle %}Sorry, there is a problem with the service – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% set mainClasses = "govuk-main-wrapper--l" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Sorry, there is a problem with the service</h1>
<p class="govuk-body">Try again later.</p>
<p class="govuk-body">We saved your answers. They will be available for 30 days.</p>
</div>
</div>
{% endblock %}
14 changes: 14 additions & 0 deletions application/templates/503.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "base.html" %}

{% block pageTitle %}Sorry, the service is unavailable – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% set mainClasses = "govuk-main-wrapper--l" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Sorry, the service is unavailable</h1>
<p class="govuk-body">You will be able to use the service from 9am on Monday 19&nbsp;November&nbsp;2018.</p>
</div>
</div>
{% endblock %}
Loading