Skip to content

Commit 4e434e7

Browse files
Added docker support
1 parent d588799 commit 4e434e7

File tree

9 files changed

+134
-3
lines changed

9 files changed

+134
-3
lines changed

docker-compose.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3'
2+
3+
volumes:
4+
pgdata:
5+
6+
services:
7+
db:
8+
image: redmine_db
9+
ports:
10+
- 127.0.0.1:5432:5432
11+
environment:
12+
DATABASE_USER: 'redmine'
13+
DATABASE_PASSWORD: 'redminepass'
14+
DATABASE_NAME: 'redmine'
15+
volumes:
16+
- pgdata:/var/lib/postgresql/data # <- important! the `/var/lib/postgresql/data` mounting point for your container is where postgresql's default data location is!
17+
redmine:
18+
image: redmine
19+
ports:
20+
- 127.0.0.1:8080:3000
21+
restart: always
22+
environment:
23+
REDMINE_DB_POSTGRES: db
24+
REDMINE_DB_DATABASE: 'redmine'
25+
REDMINE_DB_USER: 'redmine'
26+
REDMINE_DB_PASSWORD: 'redminepass'
27+
28+
web:
29+
image: reports:latest
30+
ports:
31+
- 127.0.0.1:8000:8000
32+
volumes:
33+
- .:/code/ # <- the first "." is the local directory that will be mounted to the location defined after the ":" (/svr/)
34+
depends_on:
35+
- db
36+
links:
37+
- "db:database"

docker_django/Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM python:2.7
2+
ENV PYTHONUNBUFFERED 1
3+
4+
# Make a location for all of our stuff to go into
5+
RUN mkdir /code
6+
7+
# Set the working directory to this new location
8+
WORKDIR /code
9+
10+
# Copy all of our scripts into the location
11+
ADD requirements.txt /code/
12+
13+
# Install requirements for Django
14+
RUN pip install -r requirements.txt
15+
16+
# Add our Django code
17+
ADD . /code/
18+
19+
# Expose the port so we can access Django as it's running
20+
EXPOSE 8000
21+
22+
# Set the entry point script
23+
#ADD docker_django/wait_for_postgres.sh /code/
24+
#ADD docker_django/wait_for_postgres.py /code/
25+
#RUN chmod +x /code/docker_django/wait_for_postgres.sh
26+
27+
ENTRYPOINT ["/code/docker_django/wait_for_postgres.sh"]
28+
29+
# Start the server:
30+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

docker_django/wait_for_postgres.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
import psycopg2
4+
import sys
5+
import time
6+
7+
# Default to offline (make that assumption)
8+
offline = True
9+
10+
# Until it becomes online...
11+
while offline:
12+
try:
13+
# try to connect! we don't care if the password is right, we're just checking to see if we can get
14+
# Postgres to answer us back...
15+
c = psycopg2.connect(host=sys.argv[1], database='postgres', user='postgres', password='invalid_password')
16+
17+
# if the above didn't fail, then we actually got the password right (oops), but it means we're online
18+
offline = False
19+
except psycopg2.OperationalError as e:
20+
# If the "Connection refused", then we know Postgres isn't running on the expected host, so we wait 1 second
21+
# and try again
22+
if 'Connection refused' in str(e):
23+
print("PostgreSQL cannot be found...waiting 1 second and trying again...")
24+
offline = True
25+
time.sleep(1)
26+
else:
27+
# otherwise we probably got a password error of some sort, but it does mean we're online!
28+
offline = False
29+
exit(0)

docker_django/wait_for_postgres.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# call the python script that uses pyscopg2 to check for database connections
4+
# NOTE: we pass in "db" as a parameter since this is the hostname Docker sets for us (in the docker-compose.yml)
5+
python wait_for_postgres.py db
6+
7+
# Execute anything in the "CMD" definition
8+
exec "$@"

docker_postgres/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM postgres:9.6
2+
3+
# Use the below script to initialize a user, set their password, and create a blank database
4+
# NOTE: Must set environment variables to create new user/database (apart from the postgres user):
5+
# - DATABASE_USER
6+
# - DATABASE_PASSWORD
7+
# - DATABASE_NAME
8+
#
9+
# (hint: can set with `-e 'DATABASE_USER=username'` flags in the `docker run` command)
10+
COPY docker_postgres/setup_database.sh /docker-entrypoint-initdb.d/setup_database.sh
11+
RUN chmod +x /docker-entrypoint-initdb.d/setup_database.sh
12+
13+
# Expose port 5432 so we can connect to it from outside the container
14+
EXPOSE 5432
15+
16+
# Be sure to switch to the "postgres" user so we can run the above script and start the service
17+
USER postgres

docker_postgres/setup_database.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
4+
psql -v ON_ERROR_STOP=1 <<-EOSQL
5+
CREATE USER $DATABASE_USER WITH PASSWORD '$DATABASE_PASSWORD';
6+
CREATE DATABASE $DATABASE_NAME with owner $DATABASE_USER;
7+
EOSQL

docker_redmine/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM redmine:latest
2+
3+
COPY docker_redmine/flatly_light_redmine-master /usr/src/redmine/public/themes/flatly_light_redmine-master

pr/settings/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'django_extensions',
4141
#'skillsmatrix.apps.SkillsmatrixConfig',
4242
# used on prod for CAS authentication
43-
'cas'
43+
# 'cas'
4444
]
4545

4646
MIDDLEWARE_CLASSES = [
@@ -52,7 +52,7 @@
5252
'django.contrib.messages.middleware.MessageMiddleware',
5353
'django.middleware.clickjacking.XFrameOptionsMiddleware',
5454
# used on prod for CAS authentication
55-
'cas.middleware.CASMiddleware',
55+
# 'cas.middleware.CASMiddleware',
5656
]
5757

5858

pr/settings/development.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'NAME': 'redmine',
88
'USER': 'redmine',
99
'PASSWORD': 'redminepass',
10-
'HOST': 'localhost',
10+
'HOST': 'db',
1111
'PORT': '5432'
1212
}
1313
}

0 commit comments

Comments
 (0)