Skip to content

Commit

Permalink
Fix serving of media files
Browse files Browse the repository at this point in the history
  • Loading branch information
tnaccarato committed Aug 13, 2024
1 parent 1bd5adc commit 57293a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Dockerfile.django
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ RUN npm install
# Build front-end assets with Webpack
RUN npx webpack --mode=production

#Make sure that container has write permissions
#Make sure that container has write permissions for staticfiles and media directories
RUN mkdir -p /app/vis_phewas/staticfiles && \
chmod -R 755 /app/vis_phewas/staticfiles

RUN mkdir -p /app/vis_phewas/media && \
chmod -R 755 /app/vis_phewas/media

# Collect static files with WhiteNoise in mind
RUN python manage.py collectstatic --noinput --verbosity 3

# Ensure the static files are served correctly
ENV STATIC_ROOT /app/vis_phewas/staticfiles
ENV MEDIA_ROOT /app/vis_phewas/media

# Gunicorn setup
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--timeout", "120", "vis_phewas.wsgi:application"]
Expand Down
33 changes: 20 additions & 13 deletions docker-compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,38 @@ services:
- ./vis_phewas/vis_phewas:/app/vis_phewas/vis_phewas
- ./vis_phewas/mainapp:/app/vis_phewas/mainapp
- ./vis_phewas/api:/app/vis_phewas/api
- ./vis_phewas/som:/app/vis_phewas/som
- ./vis_phewas/templates:/app/vis_phewas/templates
- ./vis_phewas/package.json:/app/vis_phewas/package.json
- ./vis_phewas/webpack.config.js:/app/vis_phewas/webpack.config.js
- ./LICENSE:/app/LICENSE
- staticfiles:/vis_phewas/staticfiles # Share static files
- staticfiles:/app/vis_phewas/staticfiles # Share static files
- media:/app/vis_phewas/media # Share media files
ports:
- "8000:8000"
env_file:
- docker.env
depends_on:
- db

# nginx:
# build:
# context: .
# dockerfile: Dockerfile.nginx
# ports:
# - "443:443"
# - "80:80"
# volumes:
# - ./nginx.conf:/etc/nginx/conf.d/default.conf
# - staticfiles:/app/vis_phewas/staticfiles # Access static files from the shared volume
# depends_on:
# - web
nginx:
build:
context: .
dockerfile: Dockerfile.nginx
ports:
- "443:443"
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- staticfiles:/app/vis_phewas/staticfiles # Access static files from the shared volume
- media:/app/vis_phewas/media # Access media files from the shared volume
- ./cert.pem:/etc/nginx/ssl/cert.pem
- ./key.pem:/etc/nginx/ssl/key.pem

depends_on:
- web

volumes:
postgres_data:
staticfiles: # Define the shared volume
media: # Define the shared volume

0 comments on commit 57293a9

Please sign in to comment.