Update development docker setup

This commit is contained in:
Aarni Halinen
2019-11-03 16:06:14 +02:00
parent 7457b8a24d
commit 96fc8a5569
7 changed files with 39 additions and 236 deletions
+2
View File
@@ -1,8 +1,10 @@
HOST=localhost HOST=localhost
DEBUG=True
SECRET_KEY=7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp( SECRET_KEY=7p$85^4ibb^p4-=vs44b7!y0e-zemugze18@a#30&71=a8)dp(
TG_BOT_TOKEN= TG_BOT_TOKEN=
EMAIL_HOST= EMAIL_HOST=
EMAIL_PASSWD= EMAIL_PASSWD=
DB_USER=postgres DB_USER=postgres
DB_PASSWD=postgres DB_PASSWD=postgres
DB_HOST=db
DB_PORT=5432 DB_PORT=5432
+18 -7
View File
@@ -1,8 +1,19 @@
FROM python:3.7 FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
ENV IS_DOCKER 1 ENV IS_DOCKER 0
RUN mkdir /code WORKDIR /app
WORKDIR /code COPY requirements.txt ./
ADD requirements.txt /code/ COPY requirements.production.txt ./
RUN env COPY . ./
ADD . /code/
# uWSGI, gunicorn etc.
RUN apk add --no-cache python3-dev build-base linux-headers pcre-dev openssl bash \
# PSQL
&& apk add --no-cache postgresql-dev \
# Pillow
&& apk add --no-cache jpeg-dev zlib-dev \
&& pip install --upgrade pip \
&& pip install -r requirements.txt \
&& pip install -r requirements.production.txt
RUN python manage.py collectstatic --noinput
+2 -6
View File
@@ -7,19 +7,15 @@ COPY requirements.production.txt ./
COPY . ./ COPY . ./
# uWSGI, gunicorn etc. # uWSGI, gunicorn etc.
RUN apk add --no-cache --virtual .build-deps python3-dev build-base linux-headers pcre-dev openssl \ RUN apk add --no-cache python3-dev build-base linux-headers pcre-dev openssl \
# PSQL # PSQL
&& apk add --no-cache postgresql-dev \ && apk add --no-cache postgresql-dev \
# Pillow # Pillow
&& apk add --no-cache jpeg-dev zlib-dev \ && apk add --no-cache jpeg-dev zlib-dev \
&& pip install --upgrade pip \ && pip install --upgrade pip \
&& pip install -r requirements.txt \ && pip install -r requirements.txt \
&& pip install -r requirements.production.txt \ && pip install -r requirements.production.txt
&& apk del .build-deps
RUN python manage.py collectstatic --noinput RUN python manage.py collectstatic --noinput
# run migrate
# python manage.py migrate --noinput
ENTRYPOINT ["sh", "-c", "./production_entrypoint.sh"] ENTRYPOINT ["sh", "-c", "./production_entrypoint.sh"]
+9 -2
View File
@@ -2,12 +2,19 @@ version: '3'
services: services:
db: db:
image: postgres image: postgres:12
volumes:
- dbdata:/var/lib/postgresql/data
web: web:
build: . build: .
image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend:dev image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend:dev
command: ["bash", "-c", "cd /code && ./wait-for-it.sh db:5432 -- bash setup.sh --no-input --no-npm && python manage.py runserver 0.0.0.0:8000"] command: ["bash", "-c", "cd /app & bash setup.sh --no-input --no-npm && gunicorn -w 4 -b 0.0.0.0:8000 sikweb.wsgi"]
env_file:
- .env.sample
ports: ports:
- "8000:8000" - "8000:8000"
depends_on: depends_on:
- db - db
volumes:
dbdata:
+2 -1
View File
@@ -3,7 +3,7 @@
echo "SIK WEB 2.0" echo "SIK WEB 2.0"
echo "This script will set up the environment for this project." echo "This script will set up the environment for this project."
echo "=========================================================" echo "========================================================="
echo "Dependencies: python>3.5" echo "Dependencies: python3.7"
INTERACTIVE="true" INTERACTIVE="true"
USE_NPM="true" USE_NPM="true"
@@ -65,6 +65,7 @@ fi
set -e set -e
set -x set -x
pip install -r requirements.txt pip install -r requirements.txt
pip install -r requirements.production.txt
$USE_NPM && npm install $USE_NPM && npm install
python manage.py migrate python manage.py migrate
python manage.py createdefaultadmin python manage.py createdefaultadmin
-37
View File
@@ -7,19 +7,12 @@ from django.utils.translation import ugettext_lazy as _
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
IS_DOCKER = bool(os.getenv('IS_DOCKER', None))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
if not IS_DOCKER:
ALLOWED_HOSTS = []
else:
ALLOWED_HOSTS = ["*"]
# Logger level # Logger level
LOGGERLEVEL = logging.DEBUG LOGGERLEVEL = logging.DEBUG
@@ -166,36 +159,6 @@ TEMPLATES = [
WSGI_APPLICATION = 'sikweb.wsgi.application' WSGI_APPLICATION = 'sikweb.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
if not IS_DOCKER:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'sik',
'USER': 'sik',
'PASSWORD': 'password123',
'HOST': 'localhost',
'PORT': '5432',
'TEST': {
'NAME': 'sik_test',
},
},
}
else:
logging.info('Using docker database configuration')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': '5432',
},
}
# Password validation # Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
-177
View File
@@ -1,177 +0,0 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
cmdname=$(basename $0)
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
if [[ $ISBUSY -eq 1 ]]; then
nc -z $HOST $PORT
result=$?
else
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
fi
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}
wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}
# check to see if timeout is from busybox?
# check to see if timeout is from busybox?
TIMEOUT_PATH=$(realpath $(which timeout))
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
ISBUSY=1
BUSYTIMEFLAG="-t"
else
ISBUSY=0
BUSYTIMEFLAG=""
fi
if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi
if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec "${CLI[@]}"
else
exit $RESULT
fi