Skip to content

Commit

Permalink
Merge pull request #22 from dtekcth/less_hard_coding
Browse files Browse the repository at this point in the history
Less hard coding
  • Loading branch information
malmz authored Nov 9, 2022
2 parents d7169c9 + 171b617 commit db34dd9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 43 deletions.
35 changes: 22 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
FROM python:3.7
ENV PYTHONUNBUFFERED 1
FROM python:3.7-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code

# Installs gettext tools so that localizations stuff works
RUN apt-get update && apt-get install -y gettext libgettextpo-dev
RUN apt-get update && apt-get install -y build-essential gettext libgettextpo-dev

RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code
COPY requirements.txt ./
RUN pip install -r requirements.txt

COPY dtekportal .
COPY locale /locale
COPY scripts /scripts

RUN mkdir /logs

ENV DB_HOST db
ENV DB_PORT 5432
ENV PORT 80
EXPOSE $PORT
CMD /scripts/wait-for-it.sh "$DB_HOST:$DB_PORT" -- \
uwsgi --http-socket ":$PORT" --module dtekportal.wsgi
# Default values to match previous hardcoded values
ENV DJANGO_ALLOWED_HOSTS="dtek.se,www.dtek.se"
ENV DB_NAME="dtekportal"
ENV DB_USER="postgres"
ENV DB_HOST="db"
ENV DB_PORT="5432"

EXPOSE 80

CMD ["uwsgi", "--socket", "0.0.0.0:3000", \
"--protocol", "uwsgi", \
"--module", "dtekportal.wsgi"]

#CMD /scripts/wait-for-it.sh "$DB_HOST:$DB_PORT" -- \
# uwsgi --http-socket ":$PORT" --module dtekportal.wsgi
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ services:
web:
build: .
restart: always
env_file: .env
environment:
DB_NAME: "dtekportal"
DB_USER: "postgres"
DB_PASSWORD: "$DB_PASSWORD"
DB_HOST: "db"
DB_PORT: "5432"
depends_on:
- db
volumes:
Expand All @@ -28,7 +33,7 @@ services:
- web
volumes:
- static:/usr/share/nginx/html:ro
- ./site.conf:/etc/nginx/conf.d/default.conf:ro
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro

volumes:
db_data:
Expand Down
15 changes: 9 additions & 6 deletions dtekportal/dtekportal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool('DJANGO_DEBUG' in os.environ)

ALLOWED_HOSTS = ['localhost', 'dtek.se', 'www.dtek.se', 'local.dtek.se', 'sagge.dtek.se', 'flan2.dtek.se']
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '0.0.0.0']
ALLOWED_HOSTS.extend(os.environ.get('DJANGO_ALLOWED_HOSTS', '').split(','))

#ALLOWED_HOSTS = ['localhost', 'dtek.se', 'www.dtek.se', 'local.dtek.se', 'sagge.dtek.se', 'flan2.dtek.se']


# Application definition
Expand Down Expand Up @@ -87,11 +90,11 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dtekportal',
'HOST': 'db',
'USER': 'postgres',
'PORT': 5432,
'PASSWORD' : os.environ['DB_PASSWORD'],
'NAME': os.environ.get('DB_NAME'),
'HOST': os.environ.get('DB_HOST'),
'USER': os.environ.get('DB_USER'),
'PORT': os.environ.get('DB_PORT'),
'PASSWORD' : os.environ.get('DB_PASSWORD'),
}
}

Expand Down
17 changes: 17 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server {
listen 80;

location / {
include uwsgi_params;
uwsgi_pass web:3000;
}

location /static/ {
alias /usr/share/nginx/html/;
index index.html index.htm;
}

location /robots.txt {
alias /usr/share/nginx/html/robots.txt;
}
}
22 changes: 0 additions & 22 deletions site.conf

This file was deleted.

0 comments on commit db34dd9

Please sign in to comment.