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

Initial setup fixes #23

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"esbenp.prettier-vscode",
"orta.vscode-jest"
"orta.vscode-jest",
"bungcip.better-toml"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5432],
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"editor.formatOnSave": true,
"html.format.templating": true,
"jest.autoRun": "off",
"jest.jestCommandLine": "yarn jest",
"[django-html]": {
"editor.formatOnSave": false
}
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

FROM node:lts AS builder
WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn --frozen-lockfile
COPY frontend ./frontend/
COPY app/templates ./app/templates
COPY vite.config.js tsconfig.json env.d.ts ./
RUN NODE_ENV=production yarn vite build

FROM python:3.10-slim-bullseye

# Configure system
WORKDIR /app

Expand All @@ -21,18 +22,17 @@ RUN mkdir -p /app && chown -R app /app
ENV POETRY_HOME=/usr/local
RUN curl -sSL https://install.python-poetry.org | python3 -
USER app
RUN poetry config virtualenvs.create false
RUN poetry config virtualenvs.create true
RUN poetry config virtualenvs.in-project true

# Install
COPY --chown=app:app pyproject.toml poetry.lock ./
RUN poetry install -n

COPY --chown=app:app . ./
COPY --chown=app --from=builder /app/dist ./dist
COPY --chown=app --from=builder /app/vite ./vite
ENV DJANGO_SETTINGS_MODULE=app.settings.production
ENV PATH=$PATH:/home/app/.local/bin
RUN SECRET_KEY=dummy poetry run python manage.py collectstatic --noinput --clear

# For simple, single instance apps optionally run $BAKCKGROUND_WORKER in the background of this container.
# It's a bit gross, but it works.
ARG BAKCKGROUND_WORKER=true
CMD ["bash", "-c", "set -m; $BAKCKGROUND_WORKER & gunicorn $GUNICORN_ARGS -b 0.0.0.0:${PORT:-80} app.wsgi & fg %1"]
CMD ["bash", "-c", "poetry run gunicorn $GUNICORN_ARGS -b 0.0.0.0:${PORT:-80} app.wsgi"]
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ formatting: codestyle
.PHONY: test
test:
poetry run pytest -vs -m "not integration_test"
yarn test
yarn test --passWithNoTests

.PHONY: check-codestyle
check-codestyle:
Expand All @@ -53,7 +53,6 @@ check-codestyle:
.PHONY: check-safety
check-safety:
poetry check
poetry run safety check --full-report
poetry run bandit -ll --recursive pyck tests

.PHONY: lint
Expand All @@ -62,7 +61,7 @@ lint: check-codestyle check-safety test
.PHONY: ci
ci: lint
poetry run pytest
yarn test
yarn test --passWithNoTests


#* Assets
Expand All @@ -73,7 +72,7 @@ build:
SECRET_KEY=dummy poetry run python manage.py collectstatic --noinput --clear

.PHONY: release
release: migrate
release: migrate


#* Cleaning
Expand Down
12 changes: 2 additions & 10 deletions app/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
BASE_DIR = os.path.dirname(PROJECT_DIR)


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/


# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -67,7 +63,6 @@


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASE_URL = os.getenv("DATABASE_URL")

Expand All @@ -81,7 +76,6 @@
}

# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -102,7 +96,6 @@


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = "en-gb"

Expand All @@ -116,7 +109,6 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
Expand All @@ -125,14 +117,14 @@


DJANGO_VITE_ASSETS_PATH = BASE_DIR + "/dist"
DJANGO_VITE_MANIFEST_PATH = DJANGO_VITE_ASSETS_PATH + "/manifest.json"
DJANGO_VITE_MANIFEST_PATH = DJANGO_VITE_ASSETS_PATH + "bundle/manifest.json"

STATICFILES_DIRS = [DJANGO_VITE_ASSETS_PATH]


# ManifestStaticFilesStorage is recommended in production, to prevent outdated
# JavaScript / CSS assets being served from cache (e.g. after a Wagtail upgrade).
# See https://docs.djangoproject.com/en/3.2/ref/contrib/staticfiles/#manifeststaticfilesstorage

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"

STATIC_ROOT = os.path.join(BASE_DIR, "static")
Expand Down
5 changes: 3 additions & 2 deletions app/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
SECRET_KEY = os.getenv("SECRET_KEY")

if os.getenv("BASE_URL"):
CSRF_TRUSTED_ORIGINS = [os.getenv("BASE_URL")]
BASE_URL = re.sub(r"/$", "", os.getenv("BASE_URL"))
ALLOWED_HOSTS = [urlparse(BASE_URL).netloc]
ALLOWED_HOSTS = [os.getenv("ALLOWED_HOSTS") or urlparse(BASE_URL).netloc]
else:
BASE_URL = ""
ALLOWED_HOSTS = ["*"]
Expand All @@ -24,7 +25,7 @@
MEDIA_URL = os.getenv("MEDIA_URL")
else:
MEDIA_ROOT = os.getenv(MEDIA_ROOT)
MEDIA_URL = os.getenv("MEDIA_URL", "/media")
MEDIA_URL = os.getenv("MEDIA_URL", "/media/")

if os.getenv("MAILGUN_API_URL"):
ANYMAIL = {
Expand Down
2 changes: 1 addition & 1 deletion app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("__debug__/", include(debug_toolbar.urls)),
path("", TemplateView.as_view(template_name="pages/index.html", extra_context=map)),
path("", TemplateView.as_view(template_name="pages/index.html")),
]


Expand Down
2 changes: 1 addition & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// <reference types="vite/client" />

declare module "*.css"
declare module "*.css";
1 change: 1 addition & 0 deletions frontend/test/file-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "file-contents";
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module.exports = {
testEnvironment: "jsdom",
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
require.resolve("./frontend/core/util/file-mock.ts"),
"\\.(css|scss)$": require.resolve("./frontend/core/util/file-mock.ts"),
require.resolve("./frontend/test/file-mock.ts"),
"\\.(css|scss)$": require.resolve("./frontend/test/file-mock.ts"),
},
setupFiles: ["mutationobserver-shim"],
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/build/"],
Expand Down
Loading