Skip to content

Commit

Permalink
Better docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Dec 31, 2023
1 parent f5f9aca commit 5cb18a1
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Use virtualenv
run: source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt -r requirements-dev.txt
run: pip install .
- name: Use the dev configuration
run: cp kmicms/kmicms/configuration.dev.py kmicms/kmicms/configuration.py
- name: Check Formatting
Expand Down
14 changes: 8 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ services:
volumes:
- staticfiles:/app/static
- mediafiles:/app/media
ports:
- 8001:80
depends_on:
- web
networks:
- traefik
# - traefik
- default
labels:
- "traefik.enable=true"
Expand All @@ -29,8 +31,8 @@ services:
image: kmicms_web
command: /start
volumes:
- staticfiles:/app/static
- mediafiles:/app/media
- staticfiles:/wagtail-static
- mediafiles:/wagtail-media
env_file:
- .env
environment:
Expand Down Expand Up @@ -70,6 +72,6 @@ volumes:
staticfiles:
mediafiles:

networks:
traefik:
external: true
# networks:
# traefik:
# external: true
46 changes: 33 additions & 13 deletions etc/docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
ARG PYTHON_VERSION=3.12-slim-bookworm

FROM python:${PYTHON_VERSION}
FROM python:${PYTHON_VERSION} as builder

WORKDIR /app

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

RUN pip install wheel poetry==1.7.1

RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
build-essential

COPY pyproject.toml poetry.lock ./
RUN touch README.md

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

FROM python:${PYTHON_VERSION} as runtime

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"

WORKDIR /app

RUN addgroup --system wagtail \
&& adduser --system --ingroup wagtail wagtail

# Install system packages required by Wagtail and wagtail.
RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
Expand All @@ -14,13 +40,6 @@ RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-r
libwebp-dev \
&& rm -rf /var/lib/apt/lists/*

RUN addgroup --system wagtail \
&& adduser --system --ingroup wagtail wagtail

# Requirements are installed here to ensure they will be cached.
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

COPY ./etc/docker/web/entrypoint /entrypoint
RUN chmod +x /entrypoint
RUN chown wagtail /entrypoint
Expand All @@ -29,16 +48,17 @@ COPY ./etc/docker/web/start /start
RUN chmod +x /start
RUN chown wagtail /start

WORKDIR /app

# avoid 'permission denied' error
RUN mkdir /app/static
RUN mkdir /app/media

COPY . .
COPY ./kmicms/kmicms/configuration.prod.py /app/kmicms/kmicms/configuration.py
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

COPY ./kmicms/kmicms/configuration.prod.py ./kmicms/configuration.py

COPY kmicms .

RUN chown -R wagtail:wagtail /app
RUN chown -R wagtail:wagtail .

USER wagtail

Expand Down
6 changes: 3 additions & 3 deletions etc/docker/web/start
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o errexit
set -o pipefail
set -o nounset

python /app/kmicms/manage.py collectstatic --noinput
python /app/kmicms/manage.py migrate
python /app/manage.py collectstatic --noinput
python /app/manage.py migrate

/usr/local/bin/gunicorn kmicms.wsgi:application --bind 0.0.0.0:8000 --chdir=/app/kmicms
/app/.venv/bin/gunicorn kmicms.wsgi:application --bind 0.0.0.0:8000 --chdir=/app
4 changes: 2 additions & 2 deletions kmicms/kmicms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@
},
}

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_ROOT = os.path.join(BASE_DIR, "wagtail-static")
STATIC_URL = "/static/"

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_ROOT = os.path.join(BASE_DIR, "wagtail-media")
MEDIA_URL = "/media/"


Expand Down
3 changes: 1 addition & 2 deletions kmicms/kmicms/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from core import views as search_views
from django.conf import settings
from django.contrib import admin
from django.urls import include, path
Expand All @@ -6,8 +7,6 @@
from wagtail.contrib.sitemaps.views import sitemap
from wagtail.documents import urls as wagtaildocs_urls

from core import views as search_views

urlpatterns = [
path("admin/", include(wagtailadmin_urls)),
path("accounts/", include("accounts.urls")),
Expand Down
3 changes: 1 addition & 2 deletions kmicms/pages/contact/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from typing import Any

from django.db import models
from integrations.discord import submit_discord_webhook_for_form
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.contrib.forms.models import AbstractFormField, FormMixin
from wagtail.contrib.forms.panels import FormSubmissionsPanel
from wagtail.fields import RichTextField
from wagtail.models import Page

from integrations.discord import submit_discord_webhook_for_form

from .forms import ContactFormBuilder, remove_captcha_field


Expand Down
3 changes: 1 addition & 2 deletions kmicms/pages/home/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from core.blocks import BodyBlock
from wagtail.admin.panels import FieldPanel, TitleFieldPanel
from wagtail.fields import StreamField
from wagtail.models import Page
from wagtail.search import index

from core.blocks import BodyBlock


class HomePage(Page):
parent_page_types = ["wagtailcore.Page"]
Expand Down
3 changes: 1 addition & 2 deletions kmicms/pages/infra/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from django.conf import settings
from django.http import Http404, HttpRequest, HttpResponse
from integrations.netbox import NetboxClient, NetboxRequestError
from wagtail.admin.panels import FieldPanel, TitleFieldPanel
from wagtail.contrib.routable_page.models import RoutablePageMixin, path
from wagtail.fields import RichTextField
from wagtail.models import Page

from integrations.netbox import NetboxClient, NetboxRequestError


class NetboxInfrastructurePage(RoutablePageMixin, Page):
max_count = 1
Expand Down
3 changes: 1 addition & 2 deletions kmicms/pages/standard_page/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from core.blocks import StoryBlock
from django.db import models
from wagtail.admin.panels import FieldPanel, TitleFieldPanel
from wagtail.fields import StreamField
from wagtail.models import Page
from wagtail.search import index

from core.blocks import StoryBlock


class StandardPage(Page):
content = StreamField(StoryBlock(), use_json_field=True)
Expand Down
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ requests = "^2.31.0"
gunicorn = "^21.2.0"
psycopg = {extras = ["binary", "pool"], version = "^3.1.16"}
redis = "^5.0.1"
setuptools = "^69.0.3"

[tool.poetry.group.dev.dependencies]
django-debug-toolbar = "^4.2.0"
Expand Down

0 comments on commit 5cb18a1

Please sign in to comment.