Skip to content
Snippets Groups Projects
Commit 4a18d621 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

docker integration, CI

parent 3dc46f0a
No related branches found
No related tags found
No related merge requests found
Pipeline #10930 failed
.git
.venv
staticfiles/
stages:
- build
image: docker:20.10.8
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_TAG_APP: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
IMAGE_TAG_NGINX: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-nginx
services:
- docker:20.10.8-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build_app:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:test || true
- docker build --cache-from $CI_REGISTRY_IMAGE:test -t $IMAGE_TAG_APP .
- docker push $IMAGE_TAG_APP
build_nginx:
stage: build
when: manual
script:
- docker pull $CI_REGISTRY_IMAGE:test-nginx || true
- docker build --cache-from $CI_REGISTRY_IMAGE:test-nginx -t $IMAGE_TAG_NGINX . -f Dockerfile.nginx
- docker push $IMAGE_TAG_NGINX
FROM python:3.10
RUN mkdir /app
WORKDIR /app
RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash -
RUN apt-get install nodejs && rm -rf /var/lib/apt/lists/*
COPY . .
RUN pip install -r requirements/base.txt -r requirements/prod.txt
RUN npm install
RUN npm run build
RUN python manage.py collectstatic --noinput --settings=rybicka.settings.prod
RUN bash -c "adduser --disabled-login --quiet --gecos app app && \
chmod -R o+r /app/ && \
chmod o+x /app/run.sh"
USER app
ENV DJANGO_SETTINGS_MODULE "rybicka.settings.prod"
EXPOSE 8000
CMD ["bash", "run.sh"]
FROM nginx:1.18
EXPOSE 8080
ADD nginx.conf /etc/nginx/conf.d/rybicka.conf
......@@ -3,7 +3,7 @@
PYTHON = python
VENV = .venv
PORT = 8012
SETTINGS = rybicka.settings.dev
SETTINGS = rybicka.settings.prod
.PHONY: help venv install build run shell migrations migrate
......@@ -26,7 +26,7 @@ venv: .venv/bin/python
${PYTHON} -m venv ${VENV}
install: venv
${VENV}/bin/pip install -r requirements/base.txt
${VENV}/bin/pip install -r requirements/base.txt -r requirements/prod.txt
${VENV}/bin/nodeenv --python-virtualenv --node=19.3.0
${VENV}/bin/npm install
......
......@@ -2,7 +2,7 @@
Aplikace pro všemožné jednoduché nástroje, které pomohou automatizovat složité úkony.
## Setup
## Lokální setup
Požadavky:
- Python 3.9+
......
DATABASE_URL="postgresql://rybicka:rybicka@localhost:5432/rybicka"
SECRET_KEY="%@=^sip3=tqn6d_-xvvidc1@-t0t3&*kab@vr4c4"
# Production settings
ALLOWED_HOSTS="nastroje.pirati.cz"
bind = "0.0.0.0:8000"
accesslog = "-"
workers = 1
max_requests = 1000
max_requests_jitter = 10
timeout = 60
graceful_timeout = 60
Django==4.1.5
django-database-url==1.0.3
python-dotenv==0.21.0
django-environ==0.9.0
psycopg2-binary==2.9.5
django-webpack-loader==1.8.0
nodeenv==1.7.0
gunicorn==20.1.0
whitenoise==6.3.0
run.sh 0 → 100644
#!/bin/bash
# exit on error
set -e
# migrate database
python manage.py migrate
# start webserver
exec gunicorn -c gunicorn.conf.py rybicka.wsgi
......@@ -14,27 +14,26 @@ import os
import pathlib
import dj_database_url
import dotenv
dotenv.load_dotenv()
import environ
# Build paths inside the project like this: BASE_DIR / "subdir".
BASE_DIR = pathlib.Path(__file__).parents[2]
env = environ.Env()
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
DEBUG = False
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ["SECRET_KEY"]
SECRET_KEY = env.str("SECRET_KEY")
ALLOWED_HOSTS = []
STATIC_ROOT = os.environ.get(
"STATIC_ROOT",
"staticfiles"
)
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
# Application definition
......
"""
Production settings.
"""
import os
from .base import *
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")
MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware")
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
......@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rybicka.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rybicka.settings.prod")
application = get_wsgi_application()
......@@ -18,7 +18,7 @@
<article class="card">
<a href="{% url "member_group_size_calc_index" %}">
<img
src="{% static "member_group_size_calc/calculator.webp" %}"
src="{% static "shared/calculator.webp" %}"
alt="Kalkulačka výpočtu skupiny členů"
class="w-full h-48 object-cover"
>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment