Skip to content

Commit

Permalink
Add https
Browse files Browse the repository at this point in the history
  • Loading branch information
tnaccarato committed Aug 11, 2024
1 parent d2d4d44 commit 291dc2f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ jobs:
echo "DJANGO_ALLOWED_HOSTS=${{ secrets.DJANGO_ALLOWED_HOSTS }}" >> docker.env
cat docker.env
- name: Save SSL Certificates
run: |
echo "${{ secrets.SSL_CERTIFICATE }}" > cert.pem
echo "${{ secrets.SSL_PRIVATE_KEY }}" > key.pem
- name: Build and Run with Docker Compose
run: |
docker compose --env-file docker.env -f docker-compose-build.yml up -d --build
- name: Health Check
run: |
sleep 10 # Give the containers some time to start
curl --fail http://localhost:8000/ || (docker compose -f docker-compose-build.yml logs web && docker compose -f docker-compose-build.yml exec web cat /app/vis_phewas/debug.log && exit 1)
curl --fail https://localhost || (docker compose -f docker-compose-build.yml logs nginx && \
docker compose -f docker-compose-build.yml exec web cat /app/vis_phewas/debug.log && exit 1)
- name: Run Integration Tests
run: |
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.django
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ RUN pip install --no-cache-dir -r requirements.txt
# Copy only necessary files
COPY ./vis_phewas /app/vis_phewas
COPY ./LICENSE /app/LICENSE
COPY ./cert.pem /app/cert.pem
COPY ./key.pem /app/key.pem

# Change directory to where manage.py is located
WORKDIR /app/vis_phewas
Expand All @@ -52,4 +54,5 @@ RUN python manage.py collectstatic --noinput --verbosity 3
ENV STATIC_ROOT /app/vis_phewas/staticfiles

# Gunicorn setup
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "vis_phewas.wsgi:application"]
CMD ["gunicorn", "--certfile=/app/cert.pem", "--keyfile=/app/key.pem", "--bind", "0.0.0.0:443", "vis_phewas.wsgi:application"]

13 changes: 12 additions & 1 deletion docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# docker-compose-build.yml
services:
db:
build:
Expand Down Expand Up @@ -32,5 +31,17 @@ services:
depends_on:
- db

nginx:
image: nginx:latest
ports:
- "443:443"
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./cert.pem:/etc/nginx/ssl/cert.pem
- ./key.pem:/etc/nginx/ssl/key.pem
depends_on:
- web

volumes:
postgres_data:
29 changes: 29 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server {
listen 443 ssl;
server_name _; # Replace with your domain name or IP address

ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;

location / {
proxy_pass http://web:8000; # Proxy to the Django service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /static/ {
alias /app/vis-phewas/staticfiles/; # Adjust the path to your static files
}

}

server {
listen 80;
server_name _; # Replace with your domain name or IP address

location / {
return 301 https://$host$request_uri;
}
}
4 changes: 2 additions & 2 deletions vis_phewas/vis_phewas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # WhiteNoise Middleware for serving static files
# 'whitenoise.middleware.WhiteNoiseMiddleware', # WhiteNoise Middleware for serving static files
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -161,7 +161,7 @@
STATIC_ROOT = BASE_DIR / 'staticfiles'

# WhiteNoise configuration for compressing static files
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
Expand Down

0 comments on commit 291dc2f

Please sign in to comment.