forked from OSQA/osqa
-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Master py3 docker 00 #867
Open
martin-bts
wants to merge
6
commits into
ASKBOT:master
Choose a base branch
from
martin-bts:master-py3-docker-00
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Master py3 docker 00 #867
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d235c6
DB and path changes in settings.py.jinja2
c6bcd5a
removed duplicate setup related files
18c4390
Replace hardcoded askbot_app with os.environ value
247d2d2
Added setup-templates/urls.py
7752859
Added .dockerignore augment_settings.py uwsgi.txt
8a3f5f3
Removed Dockerfile.redis, updated Dockerfile
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.git/ | ||
.tox/ | ||
askbot.egg-info/ | ||
dist/ | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,10 +1,3 @@ | ||||||
# | ||||||
# WARNING: this Docker file is not tested with the current askbot-setup script. | ||||||
# most likely at least this file will need to be adapted to make it work. | ||||||
# if you can help - please make explain what you want to do in the issues | ||||||
# section of the repository and once your contribution is accepted - make a pull request. | ||||||
# | ||||||
#---------------------------------------------------- | ||||||
# This Dockerifle builds a simple Askbot installation | ||||||
# | ||||||
# It makes use of environment variables: | ||||||
|
@@ -17,49 +10,166 @@ | |||||
# | ||||||
# Start with something like | ||||||
# | ||||||
# docker run -e 'DATABASE_URL=sqlite:////askbot-site/askbot.db' -e "SECRET_KEY=$(openssl rand 14 | base64)" -e ADMIN_PASSWORD=admin -p 8080:80 askbot/askbot:latest | ||||||
# docker run -e 'DATABASE_URL=sqlite:////askbot_site/askbot.sqlite' -e "SECRET_KEY=$(openssl rand 14 | base64)" -e ADMIN_PASSWORD=admin -p 8080:8000 askbot/askbot:latest | ||||||
# | ||||||
# User uploads are stored in **/askbot_site/askbot/upfiles** . I'd recommend to make it a kubernetes volume. | ||||||
# User uploads are stored in **/askbot_site/upfiles** . I'd recommend to make it a kubernetes volume. | ||||||
# Static files are stored in **/askbot_site/static** . I'd recommend to make it a kubernetes volume. | ||||||
|
||||||
# Stage 0 | ||||||
FROM tiangolo/uwsgi-nginx:python3.8-alpine | ||||||
|
||||||
ARG HTTP_PROXY= | ||||||
ARG HTTPS_PROXY= | ||||||
|
||||||
ENV http_proxy $HTTP_PROXY | ||||||
ENV https_proxy $HTTPS_PROXY | ||||||
ENV no_proxy "" | ||||||
|
||||||
RUN apk add --update --no-cache git py3-cffi \ | ||||||
gcc g++ git make mkinitfs kmod mtools squashfs-tools py3-cffi \ | ||||||
libffi-dev linux-headers musl-dev libc-dev openssl-dev \ | ||||||
python3-dev zlib-dev libxml2-dev libxslt-dev jpeg-dev \ | ||||||
postgresql-dev zlib jpeg libxml2 libxslt postgresql-libs \ | ||||||
hiredis \ | ||||||
&& python -m pip install --upgrade pip \ | ||||||
&& pip install psycopg2 | ||||||
|
||||||
COPY ${ASKBOT}/askbot/__init__.py /askbot_meta.py | ||||||
WORKDIR / | ||||||
RUN pip install virtualenv \ | ||||||
&& pip install setuptools \ | ||||||
&& pip install wheel \ | ||||||
&& python3 -c "from askbot_meta import REQUIREMENTS; _=[print(r) for r in REQUIREMENTS.values()];" >requirements.txt \ | ||||||
&& pip install -r requirements.txt | ||||||
|
||||||
COPY ${ASKBOT}/askbot /usr/local/src/askbot/askbot | ||||||
COPY ${ASKBOT}/AUTHORS ${ASKBOT}/COPYING ${ASKBOT}/LICENSE ${ASKBOT}/setup.py ${ASKBOT}/ez_setup.py ${ASKBOT}/askbot_requirements.txt ${ASKBOT}/MANIFEST.in /usr/local/src/askbot/ | ||||||
RUN cd /usr/local/src/askbot \ | ||||||
&& python3 setup.py bdist_wheel \ | ||||||
&& cp /usr/local/src/askbot/dist/askbot*.whl / \ | ||||||
&& cp /usr/local/src/askbot/askbot_requirements.txt / | ||||||
|
||||||
FROM tiangolo/uwsgi-nginx:python3.6-alpine3.9 | ||||||
RUN pip install /askbot*.whl \ | ||||||
&& find /root/.cache -name "*.whl" -exec cp {} / \; \ | ||||||
&& ls /*.whl | ||||||
|
||||||
|
||||||
# Stage 1 | ||||||
FROM tiangolo/uwsgi-nginx:python3.8-alpine | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
ARG SITE=askbot-site | ||||||
ARG APP=askbot_app | ||||||
ARG ASKBOT=. | ||||||
ARG HTTP_PROXY= | ||||||
ARG HTTPS_PROXY= | ||||||
ARG CACHE_PASSWORD | ||||||
|
||||||
ENV PYTHONUNBUFFERED 1 | ||||||
ENV ASKBOT_SITE /${SITE} | ||||||
ENV ASKBOT_APP ${APP} | ||||||
ENV ASKBOT_CACHE locmem | ||||||
ENV CACHE_NODES "" | ||||||
ENV NO_CRON yes | ||||||
ENV ADMIN_PASSWORD admin | ||||||
ENV SECRET_KEY 0123456789abcdef | ||||||
ENV DATABASE_URL "sqlite:///${ASKBOT_SITE}/askbot.sqlite" | ||||||
ENV DJANGO_SETTINGS_MODULE ${ASKBOT_APP}.settings | ||||||
ENV http_proxy $HTTP_PROXY | ||||||
ENV https_proxy $HTTPS_PROXY | ||||||
ENV no_proxy "" | ||||||
|
||||||
ENV UWSGI_INI /${SITE}/askbot_app/uwsgi.ini | ||||||
ENV UWSGI_INI ${ASKBOT_SITE}/${ASKBOT_APP}/uwsgi.ini | ||||||
# Not recognized by uwsgi-nginx, yet. | ||||||
# The file doesn't exist either! | ||||||
#ENV PRE_START_PATH /${SITE}/prestart.sh | ||||||
|
||||||
# TODO: changing this requires another cache backend | ||||||
# using more than 1 process each requires redis or memcached as backend | ||||||
ENV NGINX_WORKER_PROCESSES 1 | ||||||
ENV UWSGI_PROCESSES 1 | ||||||
ENV UWSGI_CHEAPER 0 | ||||||
ENV LISTEN_PORT 8000 | ||||||
|
||||||
ADD askbot_requirements.txt / | ||||||
|
||||||
#RUN apt-get update && apt-get -y install cron git \ | ||||||
RUN apk add --update --no-cache git py3-cffi \ | ||||||
gcc g++ git make unzip mkinitfs kmod mtools squashfs-tools py3-cffi \ | ||||||
libffi-dev linux-headers musl-dev libc-dev openssl-dev \ | ||||||
python3-dev zlib-dev libxml2-dev libxslt-dev jpeg-dev \ | ||||||
postgresql-dev zlib jpeg libxml2 libxslt postgresql-libs \ | ||||||
&& python -m pip install --upgrade pip \ | ||||||
&& pip install -r /askbot_requirements.txt \ | ||||||
&& pip install psycopg2 | ||||||
zlib jpeg libxml2 libxslt postgresql-libs \ | ||||||
hiredis | ||||||
|
||||||
COPY ${ASKBOT}/askbot_requirements.txt / | ||||||
COPY --from=0 /*.whl / | ||||||
|
||||||
RUN python -m pip install --upgrade pip \ | ||||||
&& pip install redis django-redis-cache simplejson \ | ||||||
&& pip install /*.whl && rm /*.whl \ | ||||||
&& rm -rf /root/.cache | ||||||
|
||||||
ADD $ASKBOT /src | ||||||
RUN cd /src/ && python setup.py install \ | ||||||
&& askbot-setup -n /${SITE} -e 1 -d postgres -u postgres -p askbotPW --db-host=postgres --db-port=5432 --logfile-name=stdout --no-secret-key --create-project container-uwsgi | ||||||
# lets not use the Askbot installer for now. Let's do this instead: | ||||||
|
||||||
RUN true \ | ||||||
&& cp /${SITE}/askbot_app/prestart.sh /app \ | ||||||
&& /usr/bin/crontab /${SITE}/askbot_app/crontab \ | ||||||
&& cd /${SITE} && SECRET_KEY=whatever DJANGO_SETTINGS_MODULE=askbot_app.settings python manage.py collectstatic --noinput | ||||||
RUN pip install j2render dj-database-url \ | ||||||
&& mkdir -p ${ASKBOT_SITE}/log ${ASKBOT_SITE}/cron ${ASKBOT_SITE}/upfiles ${ASKBOT_SITE}/static ${ASKBOT_SITE}/askbot_app \ | ||||||
&& SRC_DIR=`python -c 'import os; from askbot import setup_templates; print(os.path.dirname(setup_templates.__file__))'` \ | ||||||
&& cp ${SRC_DIR}/celery_app.py ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/__init__.py ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/urls.py ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/django.wsgi ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/prestart.py ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/prestart.sh ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/cron-askbot.sh ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& cp ${SRC_DIR}/manage.py ${ASKBOT_SITE} \ | ||||||
&& ln -sf `realpath ${SRC_DIR}/../doc` ${ASKBOT_SITE}/doc \ | ||||||
&& echo "{\"askbot_app\": \"${ASKBOT_APP}\", \"askbot_site\": \"${SITE}\", \"database_engine\": \"\" , \"database_name\": \"\" , \"database_password\": \"\", \"database_user\": \"\" , \"settings_path\": \"${ASKBOT_APP}\", \"logfile_name\": \"stdout\"}" >/data.json \ | ||||||
&& j2render -o ${ASKBOT_SITE}/${ASKBOT_APP}/settings.py --source /data.json ${SRC_DIR}/settings.py.jinja2 \ | ||||||
&& j2render -o ${ASKBOT_SITE}/cron/crontab --source /data.json ${SRC_DIR}/crontab.jinja2 \ | ||||||
&& j2render -o ${ASKBOT_SITE}/${ASKBOT_APP}/uwsgi.ini --source /data.json ${SRC_DIR}/uwsgi.ini.jinja2 \ | ||||||
&& cat ${SRC_DIR}/../container/uwsgi.txt >> ${ASKBOT_SITE}/${ASKBOT_APP}/uwsgi.ini \ | ||||||
&& cat ${SRC_DIR}/../container/augment_settings.py >> ${ASKBOT_SITE}/${ASKBOT_APP}/settings.py | ||||||
|
||||||
# adapt image to our needs (in order of appearance) | ||||||
# * install wait to stall instances of this container until the database | ||||||
# reachable | ||||||
# * remove /etc/uwsgi/uwsgi.ini; we bring our own uwsgi.ini and tell the | ||||||
# container in the env var UWSGI_INI about it | ||||||
# * copy our prestart.sh into /app because that's where the entrypoint | ||||||
# looks for it and this behaviour cannot (yet) be overwritten through | ||||||
# env vars. | ||||||
# * add Askbot tasks to cron | ||||||
# * collect staticfiles | ||||||
# * make nginx serve staticfiles directly without involving uwsgi/python | ||||||
# this is a bit tricky as this image writes nginx.conf at startup time | ||||||
# and takes env vars into account when doing so. In order to keep this | ||||||
# mechanism, changing the nginx.conf actually means modifying the | ||||||
# logic in /entrypoint.sh, which creates the nginx.conf | ||||||
# * we keep unix domain sockets into /tmp, not /run | ||||||
# * change owning group to gid 0 and make things group-writable | ||||||
# (essential to OpenShift support and some Kubernetes deployments) | ||||||
# * add the uwsgi user to group root(0) | ||||||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.5.0/wait /wait | ||||||
RUN chmod +x /wait | ||||||
RUN chmod +x /wait \ | ||||||
&& rm /etc/uwsgi/uwsgi.ini \ | ||||||
&& sed -i "s%^\(\s*command\s*=.*\)--ini\s*/etc/uwsgi/uwsgi.ini\(.*\)$%\1\2%" /etc/supervisor.d/supervisord.ini \ | ||||||
&& cp ${ASKBOT_SITE}/${ASKBOT_APP}/prestart.sh /app \ | ||||||
&& /usr/bin/crontab ${ASKBOT_SITE}/cron/crontab \ | ||||||
&& cd ${ASKBOT_SITE} \ | ||||||
&& SECRET_KEY=whatever \ | ||||||
ASKBOT_CACHE=locmem python manage.py collectstatic --noinput \ | ||||||
&& cd ${ASKBOT_SITE}/${ASKBOT_APP} \ | ||||||
&& STATIC_URL=`SECRET_KEY=whatever python -c 'import settings;print(settings.STATIC_URL)'` \ | ||||||
&& STATIC_ROOT=`SECRET_KEY=whatever python -c 'import settings;print(settings.STATIC_ROOT)'` \ | ||||||
&& MEDIA_URL=`SECRET_KEY=whatever python -c 'import settings;print(settings.MEDIA_URL)'` \ | ||||||
&& MEDIA_ROOT=`SECRET_KEY=whatever python -c 'import settings;print(settings.MEDIA_ROOT)'` \ | ||||||
&& sed -i "/content_server.*USE_LISTEN_PORT/a content_server=\$content_server\" location ${STATIC_URL} { alias ${STATIC_ROOT}/; }\n\"" /entrypoint.sh \ | ||||||
&& sed -i "/content_server.*USE_LISTEN_PORT/a content_server=\$content_server\" location ${MEDIA_URL} { alias ${MEDIA_ROOT}/; }\n\"" /entrypoint.sh \ | ||||||
&& sed -i 's%/run/supervisord.sock%/tmp/supervisor.sock%g' /etc/supervisord.conf \ | ||||||
&& for i in ${ASKBOT_SITE} /etc/nginx /var/log /var/cache /run; do\ | ||||||
mkdir -p $i; chown -Rh :0 $i && chmod -R g+w $i; done \ | ||||||
&& sed -i '/^chown-socket/d' ${ASKBOT_SITE}/${ASKBOT_APP}/uwsgi.ini \ | ||||||
&& sed -i 's/^chmod-socket.*/chmod-socket = 666/' ${ASKBOT_SITE}/${ASKBOT_APP}/uwsgi.ini \ | ||||||
&& chmod 660 /etc/supervisord.conf \ | ||||||
&& sed -i 's/0:root/0:root,uwsgi/' /etc/group | ||||||
|
||||||
RUN apk add --update --no-cache dos2unix \ | ||||||
&& dos2unix ${ASKBOT_SITE}/${ASKBOT_APP}/* ${ASKBOT_SITE}/* /app/* /etc/supervisord.conf /etc/supervisor.d/* /etc/nginx/* | ||||||
|
||||||
USER uwsgi | ||||||
|
||||||
WORKDIR /${SITE} | ||||||
VOLUME ["${ASKBOT_SITE}/static", "${ASKBOT_SITE}/upfiles"] | ||||||
EXPOSE ${LISTEN_PORT} | ||||||
WORKDIR ${ASKBOT_SITE} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This requires the following environment variables to be set: | ||
# * DATABASE_URL | ||
# * SECRET_KEY | ||
# * CACHE_NODES (,-separated list) | ||
# The following environment variables are optional: | ||
# * CACHE_DB (defaults to 1) | ||
# * CACHE_PASSWORD (defaults to none) | ||
|
||
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'upfiles') | ||
TIME_ZONE = 'Europe/Berlin' | ||
|
||
import dj_database_url | ||
|
||
db_url = os.environ.get('DATABASE_URL') | ||
|
||
if db_url is not None and len(db_url.strip()) > 0: | ||
DATABASES['default'] = dj_database_url.parse(db_url) | ||
DATABASES['default'].update({ 'TEST': { | ||
'CHARSET': 'utf8', # Setting the character set and collation to utf-8 | ||
}}) | ||
|
||
SECRET_KEY = os.environ['SECRET_KEY'] | ||
|
||
CACHES['locmem'] = CACHES['default'] | ||
CACHES['redis'] = { | ||
'BACKEND': 'redis_cache.RedisCache', | ||
'LOCATION': os.environ['CACHE_NODES'].split(','), | ||
'OPTIONS': { | ||
'DB': os.environ.get('CACHE_DB', 1), | ||
'CONNECTION_POOL_CLASS': 'redis.BlockingConnectionPool', | ||
'CONNECTION_POOL_CLASS_KWARGS': { | ||
'max_connections': 50, | ||
'timeout': 20, | ||
}, | ||
'MAX_CONNECTIONS': 1000, | ||
'PICKLE_VERSION': -1, | ||
}, | ||
} | ||
|
||
cache_select = os.environ.get('ASKBOT_CACHE', 'locmem') | ||
CACHES['default'] = CACHES[cache_select] | ||
|
||
if 'CACHE_PASSWORD' in os.environ and 'OPTIONS' in CACHES['default']: | ||
CACHES['default']['OPTIONS']['PASSWORD'] = os.environ['CACHE_PASSWORD'] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.8 would be downgrade