mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-10 06:04:18 +00:00
Improving docker support (#179)
Allow docker to reuse previous pip layer Fixed newlines
This commit is contained in:
parent
a7fa867a7c
commit
38a88634ce
3 changed files with 46 additions and 14 deletions
14
.dockerignore
Normal file
14
.dockerignore
Normal file
|
@ -0,0 +1,14 @@
|
|||
.git
|
||||
.gitignore
|
||||
CONTRIBUTORS.txt
|
||||
LICENSE.rst
|
||||
README.md
|
||||
|
||||
*.pyc
|
||||
*media/*
|
||||
*static/*
|
||||
*build/*
|
||||
*.DS_STORE
|
||||
db.*
|
||||
venv*
|
||||
node_modules
|
33
Dockerfile
33
Dockerfile
|
@ -1,31 +1,38 @@
|
|||
# Build the app on top of Ubuntu
|
||||
from ubuntu
|
||||
FROM ubuntu:xenial
|
||||
|
||||
RUN echo 'deb http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial main' > /etc/apt/sources.list.d/redis-server.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C7917B12
|
||||
|
||||
# Patch and Install Dependencies
|
||||
RUN apt-get -y update && apt-get -y upgrade
|
||||
RUN apt-get -y install git python-dev make python-pip libpq-dev
|
||||
RUN apt-get -y install postgresql postgresql-contrib
|
||||
RUN apt-get -y update && apt-get -y install git python-dev make python-pip libpq-dev postgresql postgresql-contrib redis-server && apt-get -y clean
|
||||
|
||||
# Updating redis config
|
||||
RUN sed -i 's/# bind 127\.0\.0\.1/bind 127\.0\.0\.1/' /etc/redis/redis.conf
|
||||
|
||||
CMD mkdir -p /app && chown -R postgres:postgres /app
|
||||
|
||||
# Add the application code to the image
|
||||
ADD . /app/
|
||||
# Add python requirements to the image
|
||||
ADD requirements.txt /app/requirements.txt
|
||||
ADD test-requirements.txt /app/test-requirements.txt
|
||||
|
||||
# Set a working directory
|
||||
WORKDIR /app/
|
||||
|
||||
# Build the application
|
||||
RUN pip install -r requirements.txt --upgrade
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Add the application code to the image
|
||||
ADD . /app/
|
||||
|
||||
# Start postgres database and use it while it is running in the container
|
||||
# Create the default db user (ash)
|
||||
RUN sudo -u postgres service postgresql start && \
|
||||
sudo -u postgres psql --command "CREATE USER ash WITH PASSWORD 'pokemon'" && \
|
||||
sudo -u postgres createdb -O ash pokeapi && \
|
||||
RUN service postgresql start && \
|
||||
service redis-server start && \
|
||||
su - postgres -c "psql --command \"CREATE USER ash WITH PASSWORD 'pokemon'\"" && \
|
||||
su - postgres -c "createdb -O ash pokeapi" && \
|
||||
python manage.py migrate --settings=config.docker && \
|
||||
printf "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker
|
||||
echo "from data.v2.build import build_all; build_all(); quit()" | python -u manage.py shell --settings=config.docker
|
||||
|
||||
# Expose the app and serve the API.
|
||||
EXPOSE 8000
|
||||
CMD service postgresql start && python manage.py runserver --settings=config.docker 0.0.0.0:8000
|
||||
|
||||
CMD service postgresql start && service redis-server start && python manage.py runserver --settings=config.docker 0.0.0.0:8000
|
||||
|
|
|
@ -12,5 +12,16 @@ DATABASES = {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG = True
|
||||
TASTYPIE_FULL_DEBUG = True
|
||||
|
|
Loading…
Reference in a new issue