Add Dockerfile and misc files to build docker image

This commit is contained in:
madmaurice 2020-08-08 23:23:11 +02:00
parent 6c7d8728f4
commit 0e83ec2edf
5 changed files with 218 additions and 0 deletions

28
Dockerfile Normal file
View file

@ -0,0 +1,28 @@
FROM python:3.8
ENV GITLAB_HOST=git.zom.bi
ENV GITEA_HOST=gitea.zom.bi
WORKDIR /usr/src/app
RUN useradd migrate
RUN mkdir -p /var/data/db && chown -R migrate /var/data
RUN apt-get update && apt-get install --yes --no-install-recommends nginx supervisor
RUN pip install gunicorn
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
RUN mkdir ./logs && chown -R migrate ./logs && rm -f giteamigrate/settings.py && ln -s ../docker/settings.docker.py giteamigrate/settings.py
USER migrate
EXPOSE 8000
VOLUME ["/var/data"]
ENTRYPOINT ["./docker/entrypoint.sh"]

15
docker/entrypoint.sh Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
cd /usr/src/app
if ! python manage.py migrate ; then
echo "Unable to migrate"
[[ "$#" -eq 0 ]] && exit 1
fi
if [[ "$#" -gt 0 ]]; then
exec "$@"
else
exec supervisord -c /usr/src/app/docker/supervisord.conf
fi

40
docker/nginx.conf Normal file
View file

@ -0,0 +1,40 @@
error_log /usr/src/app/logs/nginx.error.log warn;
pid /tmp/nginx.pid;
daemon off;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream appserver {
server localhost:8001;
}
server {
listen 8000;
access_log /usr/src/app/logs/nginx.access.log combined;
client_body_temp_path /tmp/client_body;
fastcgi_temp_path /tmp/fastcgi;
proxy_temp_path /tmp/proxy;
scgi_temp_path /tmp/scgi;
uwsgi_temp_path /tmp/uwsgi;
location / {
proxy_pass http://appserver;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
root /usr/src/app;
}
}
}

117
docker/settings.docker.py Normal file
View file

@ -0,0 +1,117 @@
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GITLAB_HOST = os.getenv("GITLAB_HOST", "localhost")
GITEA_HOST = os.getenv("GITEA_HOST", "localhost")
GITLAB_API = 'https://' + GITLAB_HOST + '/api/v4'
GITEA_API = 'https://' + GITEA_HOST + '/api/v1'
GITLAB_REPO_URL = 'https://%s:%s@' + GITLAB_HOST + '/%s.git'
GITEA_REPO_URL = 'https://%s:%s@' + GITEA_HOST + '/%s.git'
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY",None)
DEBUG = False
ALLOWED_HOSTS = [
'*'
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'migrator',
'workers',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'giteamigrate.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'giteamigrate.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/var/data/db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]

18
docker/supervisord.conf Normal file
View file

@ -0,0 +1,18 @@
[supervisord]
nodaemon=true
logfile=/usr/src/app/logs/supervisord.log
[program:nginx]
command=nginx -c /usr/src/app/docker/nginx.conf -p /usr/src/app
[program:app_server]
directory=/usr/src/app
command=gunicorn -b 127.0.0.1:8001 giteamigrate.wsgi
[program:background_worker]
directory=/usr/src/app
command=python manage.py runworkers
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0