Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at a docker development environment (#334)
* First attempt at a docker development environment * Adding a section in the development docs about docker development defaults
- Loading branch information
Showing
8 changed files
with
245 additions
and
2 deletions.
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,21 @@ | ||
__pycache__ | ||
*.log | ||
pip-log.txt | ||
.coverage | ||
*.mo | ||
*.pot | ||
.idea | ||
node_modules/ | ||
socialhome/media/ | ||
.cache | ||
env.local | ||
socialhome/static/css/*.css | ||
socialhome/static/js/project.js | ||
socialhome/static/js/webpack.*.js | ||
socialhome/static/js/webpack.*.js.map | ||
socialhome/static/fonts/ | ||
staticfiles/ | ||
bower_components/ | ||
socialhome/static/mocha/ | ||
/docs/_build/ | ||
/yarn.lock |
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 |
---|---|---|
|
@@ -89,3 +89,7 @@ socialhome/static/mocha/ | |
/docs/_build/ | ||
/yarn.lock | ||
/staticfiles/ | ||
|
||
# Docker | ||
docker-compose.yml | ||
|
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,28 @@ | ||
FROM python:3 | ||
|
||
RUN mkdir /code | ||
WORKDIR /code | ||
COPY . . | ||
|
||
# Ensure pip and setuptools are up to date as well | ||
# We need a slightly older setuptools due to a bug in pip-tools | ||
RUN pip install -U pip setuptools==30.4 pip-tools | ||
|
||
# Development environment | ||
RUN pip-sync dev-requirements.txt | ||
|
||
## # We need Node for Javascript. Install it and then grab the latest version | ||
## RUN apt-get install -y npm | ||
## RUN npm cache clean -f | ||
## RUN npm install -g n | ||
## RUN n stable | ||
|
||
RUN cp .env.example .env | ||
|
||
# This file needs to be outside the /code dir as it's mounted durin development | ||
RUN cp docker/dev/docker-entrypoint.sh.django ./docker-entrypoint.sh | ||
|
||
EXPOSE 8000 | ||
|
||
ENTRYPOINT ["./docker-entrypoint.sh"] | ||
CMD ["runserver"] |
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,15 @@ | ||
FROM node | ||
|
||
RUN mkdir /code | ||
|
||
WORKDIR /code | ||
COPY . . | ||
|
||
RUN npm install | ||
RUN node_modules/.bin/bower --allow-root install | ||
RUN node_modules/.bin/grunt dev | ||
|
||
RUN cp docker/dev/docker-entrypoint.sh.npm ./docker-entrypoint.sh | ||
|
||
ENTRYPOINT ["./docker-entrypoint.sh"] | ||
CMD ["npm", "watch"] |
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,45 @@ | ||
version: '3' | ||
|
||
services: | ||
postgres: | ||
image: postgres:9.6 | ||
volumes: | ||
- pg_data:/var/lib/postgresql/data | ||
- pg_backups:/pg_backups | ||
environment: | ||
- POSTGRES_USER=socialhome | ||
- POSTGRES_PASSWORD=socialhome | ||
- POSTGRES_DB=socialhome | ||
|
||
redis: | ||
image: redis | ||
volumes: | ||
- redis_data:/data | ||
npm: | ||
build: | ||
context: . | ||
dockerfile: docker/dev/Dockerfile.npm | ||
volumes: | ||
- ./socialhome:/code/socialhome | ||
django: | ||
depends_on: | ||
- postgres | ||
- redis | ||
build: | ||
context: . | ||
dockerfile: docker/dev/Dockerfile.django | ||
environment: | ||
- REDIS_HOST=redis | ||
- REDIS_PORT=6379 | ||
- DATABASE_URL=postgres://socialhome:socialhome@postgres:5432/socialhome | ||
- DEBUG=True | ||
- DJANGO_SECRET_KEY=ForDevelopmentEyesOnly | ||
volumes: | ||
- ./socialhome:/code/socialhome | ||
ports: | ||
- 8000:8000 | ||
|
||
volumes: | ||
pg_data: {} | ||
pg_backups: {} | ||
redis_data: {} |
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,52 @@ | ||
#!/bin/bash | ||
# | ||
# Socialhome Docker Development entrypoint | ||
|
||
# Exit immediately if a command exits with a non-zero status. | ||
set -e | ||
|
||
PORT=8000 | ||
CODE_DIR=/code | ||
|
||
cd $CODE_DIR | ||
|
||
# Define help message | ||
show_help() { | ||
echo """ | ||
Usage: docker run <imagename> COMMAND | ||
Commands | ||
runserver : Run Django development server | ||
bash : Start a bash shell | ||
manage : Run a Django management command | ||
python : Run a python command | ||
shell : Start a Django Python shell | ||
help : Show this message | ||
""" | ||
} | ||
|
||
# Run | ||
case "$1" in | ||
runserver) | ||
echo "Running Development Server..." | ||
python manage.py runserver 0.0.0.0:${PORT} | ||
;; | ||
bash) | ||
/bin/bash "${@:2}" | ||
;; | ||
manage) | ||
pwd | ||
echo "Running manage:" "${@:2}" | ||
python manage.py "${@:2}" | ||
;; | ||
python) | ||
echo "Running python command..." "${@:2}" | ||
python "${@:2}" | ||
;; | ||
shell) | ||
echo "Running shell_plus..." | ||
python manage.py shell_plus | ||
;; | ||
*) | ||
show_help | ||
;; | ||
esac |
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,37 @@ | ||
#!/bin/bash | ||
# | ||
# Socialhome Docker Development entrpypoint | ||
# | ||
# Exit immediately if a command exits with a non-zero status. | ||
set -e | ||
|
||
# Define help message | ||
show_help() { | ||
echo """ | ||
Usage: docker run <imagename> COMMAND | ||
Commands | ||
npm : Run an NPM command | ||
watch : Run npm watch | ||
bash : Start a bash shell | ||
help : Show this message | ||
""" | ||
} | ||
|
||
# Run | ||
case "$1" in | ||
npm) | ||
echo "Running npm:" "${@:2}" | ||
npm "${@:2}" | ||
;; | ||
watch) | ||
echo "Running npm run watch" | ||
npm run watch | ||
;; | ||
bash) | ||
echo "Running bash" "${@:2}" | ||
/bin/bash "${@:2}" | ||
;; | ||
*) | ||
show_help | ||
;; | ||
esac |
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