Skip to content
Snippets Groups Projects
Commit 4a5a3063 authored by jan.bednarik's avatar jan.bednarik
Browse files

Merge branch 'setup' into 'master'

Deployment setup

See merge request !23
parents 8387a1c4 2e43b18d
No related branches found
No related tags found
1 merge request!23Deployment setup
Pipeline #16820 passed
.git
.venv
.envrc
static_files/
media_files/
node_modules/
dist/
majak_uistyleguide/collectedstatic
stages:
- build
image: docker:20.10.9 image: docker:20.10.9
variables: variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
IMAGE_TAG_APP: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
services: services:
- docker:20.10.9-dind - docker:20.10.9-dind
...@@ -9,11 +13,9 @@ services: ...@@ -9,11 +13,9 @@ services:
before_script: before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build: build_app:
stage: build stage: build
script: script:
- VERSION=`cat VERSION` - docker pull $CI_REGISTRY_IMAGE:test || true
- docker pull $CI_REGISTRY_IMAGE:latest || true - docker build --cache-from $CI_REGISTRY_IMAGE:test -t $IMAGE_TAG_APP .
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$VERSION --tag $CI_REGISTRY_IMAGE:latest . - docker push $IMAGE_TAG_APP
- docker push $CI_REGISTRY_IMAGE:$VERSION
- docker push $CI_REGISTRY_IMAGE:latest
FROM python:3.11 FROM node:21
RUN apt-get update \
&& apt-get install -y python3 python3-pip \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /app RUN mkdir /app
WORKDIR /app WORKDIR /app
# Install NodeJS COPY requirements requirements/
ENV NODE_MAJOR=20 RUN pip3 install --break-system-packages -r requirements/base.txt -r requirements/prod.txt
RUN apt-get update
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install -y nodejs
RUN rm -rf /var/lib/apt/lists/*
COPY . . COPY . .
RUN pip install -r requirements/base.txt RUN bash -c 'adduser --disabled-login --quiet --gecos app app && \
RUN npm install chown -R app:app /app/ && \
RUN npm run prod chmod o+x /app/run.sh'
# Placeholder values so the static files collect
RUN DJANGO_ALLOWED_HOSTS=x \
DJANGO_SECRET_KEY=x \
python manage.py collectstatic --noinput --settings=majak_uistyleguide.settings.production
RUN bash -c "adduser --disabled-login --quiet --gecos app app && \
chmod -R o+r /app/ && \
chmod o+x /app/run.sh"
USER app USER app
RUN npm i
RUN npm run prod
ENV DJANGO_SETTINGS_MODULE "majak_uistyleguide.settings.production" ENV DJANGO_SETTINGS_MODULE "majak_uistyleguide.settings.production"
# fake values for required env variables used to run collectstatic during build
RUN DJANGO_SECRET_KEY=x DATABASE_URL=postgres://x/x DJANGO_ALLOWED_HOSTS=x \
python3 manage.py collectstatic
EXPOSE 8000 EXPOSE 8000
......
Makefile 0 → 100644
#!/usr/bin/make -f
PYTHON = python
VENV = .venv
PORT = 8009
help:
@echo "Setup:"
@echo " venv Setup virtual environment"
@echo " install Install dependencies to venv"
@echo " install-hooks Install pre-commit hooks"
@echo " hooks Run pre-commit hooks manually"
@echo " upgrade Upgrade requirements"
@echo ""
@echo "Application:"
@echo " run Run the application on port ${PORT}"
@echo " shell Run Django shell"
@echo ""
@echo "Database:"
@echo " migrations Generate migrations"
@echo " migrate Run migrations"
@echo ""
venv: .venv/bin/python
.venv/bin/python:
${PYTHON} -m venv ${VENV}
install: venv
${VENV}/bin/pip install -r requirements/base.txt
install-hooks:
pre-commit install --install-hooks
hooks:
pre-commit run -a
run: venv
${VENV}/bin/python manage.py runserver ${PORT}
shell: venv
${VENV}/bin/python manage.py shell_plus
migrations: venv
${VENV}/bin/python manage.py makemigrations
migrate: venv
${VENV}/bin/python manage.py migrate
upgrade:
(cd requirements && pip-compile -U base.in)
(cd requirements && pip-compile -U prod.in)
.PHONY: help venv install install-hooks hooks run shell upgrade migrations migrate
# EOF
...@@ -17,46 +17,41 @@ WSGI_APPLICATION = "majak_uistyleguide.wsgi.application" ...@@ -17,46 +17,41 @@ WSGI_APPLICATION = "majak_uistyleguide.wsgi.application"
# I18N and L10N # I18N and L10N
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
LANGUAGE_CODE = 'cs' LANGUAGE_CODE = "cs"
TIME_ZONE = "Europe/Prague" TIME_ZONE = "Europe/Prague"
USE_I18N = True USE_I18N = True
USE_TZ = True USE_TZ = True
# DATABASES # DATABASES
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
DATABASES = { DATABASES = {"default": env.db("DATABASE_URL")}
'default': { DATABASES["default"]["ATOMIC_REQUESTS"] = True
'ENGINE': 'django.db.backends.sqlite3', DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
'NAME': ROOT_DIR / 'db.sqlite3',
}
}
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# APPS # APPS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.admin', "django.contrib.admin",
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
"django_vite",
'django_vite', "pattern_library",
'pattern_library',
] ]
# MIDDLEWARE # MIDDLEWARE
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', "django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'django.middleware.clickjacking.XFrameOptionsMiddleware', "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
# TEMPLATES # TEMPLATES
...@@ -78,7 +73,7 @@ TEMPLATES = [ ...@@ -78,7 +73,7 @@ TEMPLATES = [
], ],
"builtins": [ "builtins": [
"pattern_library.loader_tags", "pattern_library.loader_tags",
"majak_uistyleguide.templatetags.math" "majak_uistyleguide.templatetags.math",
], ],
}, },
}, },
...@@ -102,8 +97,8 @@ MEDIA_ROOT = str(ROOT_DIR / "media_files") ...@@ -102,8 +97,8 @@ MEDIA_ROOT = str(ROOT_DIR / "media_files")
# VITE SETTINGS # VITE SETTINGS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Where ViteJS assets are built. # Where ViteJS assets are built.
DJANGO_VITE_ASSETS_PATH = ROOT_DIR / 'dist' DJANGO_VITE_ASSETS_PATH = ROOT_DIR / "dist"
STATIC_FILES = PROJECT_DIR / 'static' STATIC_FILES = PROJECT_DIR / "static"
# If use HMR or not. # If use HMR or not.
DJANGO_VITE_DEV_MODE = False DJANGO_VITE_DEV_MODE = False
...@@ -113,7 +108,7 @@ STATIC_ROOT = PROJECT_DIR / "collectedstatic" ...@@ -113,7 +108,7 @@ STATIC_ROOT = PROJECT_DIR / "collectedstatic"
# Include DJANGO_VITE_ASSETS_PATH into STATICFILES_DIRS to be copied inside # Include DJANGO_VITE_ASSETS_PATH into STATICFILES_DIRS to be copied inside
# when run command python manage.py collectstatic # when run command python manage.py collectstatic
SRC_PATH = ROOT_DIR / 'src' SRC_PATH = ROOT_DIR / "src"
STATICFILES_DIRS = [DJANGO_VITE_ASSETS_PATH, STATIC_FILES, SRC_PATH] STATICFILES_DIRS = [DJANGO_VITE_ASSETS_PATH, STATIC_FILES, SRC_PATH]
# PATTERN LIBRARY SETTINGS # PATTERN LIBRARY SETTINGS
...@@ -131,14 +126,11 @@ PATTERN_LIBRARY = { ...@@ -131,14 +126,11 @@ PATTERN_LIBRARY = {
("organisms", ["patterns/organisms"]), ("organisms", ["patterns/organisms"]),
("templates", ["patterns/templates"]), ("templates", ["patterns/templates"]),
), ),
# Configure which files to detect as templates. # Configure which files to detect as templates.
"TEMPLATE_SUFFIX": ".html", "TEMPLATE_SUFFIX": ".html",
# Set which template components should be rendered inside of, # Set which template components should be rendered inside of,
# so they may use page-level component dependencies like CSS. # so they may use page-level component dependencies like CSS.
"PATTERN_BASE_TEMPLATE_NAME": "patterns/base.html", "PATTERN_BASE_TEMPLATE_NAME": "patterns/base.html",
# Any template in BASE_TEMPLATE_NAMES or any template that extends a template in # Any template in BASE_TEMPLATE_NAMES or any template that extends a template in
# BASE_TEMPLATE_NAMES is a "page" and will be rendered as-is without being wrapped. # BASE_TEMPLATE_NAMES is a "page" and will be rendered as-is without being wrapped.
"BASE_TEMPLATE_NAMES": ["patterns/base_page.html"], "BASE_TEMPLATE_NAMES": ["patterns/base_page.html"],
......
from .base import * from .base import *
from .base import env from .base import env
# DATABASES
# ------------------------------------------------------------------------------
DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60)
# SECURITY # SECURITY
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS") ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS")
......
...@@ -11,6 +11,6 @@ import os ...@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'majak_uistyleguide.settings') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "majak_uistyleguide.settings.dev")
application = get_wsgi_application() application = get_wsgi_application()
#!/usr/bin/env python #!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os import os
import sys import sys
def main(): def main():
"""Run administrative tasks.""" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "majak_uistyleguide.settings.dev")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'majak_uistyleguide.settings')
try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__': if __name__ == "__main__":
main() main()
django<4
django-pattern-library
django-environ
django-vite
psycopg2-binary
whitenoise
django==4.0 #
django-pattern-library==1.0.0 # This file is autogenerated by pip-compile with Python 3.10
django-environ==0.9.0 # by the following command:
django-vite==2.0.2 #
gunicorn==21.2.0 # pip-compile base.in
#
asgiref==3.7.2
# via django
django==3.2.24
# via
# -r base.in
# django-pattern-library
# django-vite
django-environ==0.11.2
# via -r base.in
django-pattern-library==1.2.0
# via -r base.in
django-vite==3.0.3
# via -r base.in
markdown==3.5.2
# via django-pattern-library
psycopg2-binary==2.9.9
# via -r base.in
pytz==2024.1
# via django
pyyaml==6.0.1
# via django-pattern-library
sqlparse==0.4.4
# via django
typing-extensions==4.9.0
# via asgiref
whitenoise==6.6.0 whitenoise==6.6.0
# via -r base.in
gunicorn
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile prod.in
#
gunicorn==21.2.0
# via -r prod.in
packaging==23.2
# via gunicorn
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
set -e set -e
# migrate database # migrate database
python manage.py migrate python3 manage.py migrate
# start webserver # start webserver
exec gunicorn -c gunicorn.conf.py majak_uistyleguide.wsgi exec gunicorn -c gunicorn.conf.py majak_uistyleguide.wsgi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment