Skip to content

Commit

Permalink
updated the configurations to run one docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
OchiengPaul442 committed Dec 11, 2024
1 parent 8b99e73 commit e870447
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 63 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/deploy-previews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1186,17 +1186,14 @@ jobs:
- name: Deploy to Cloud Run
run: |-
gcloud run deploy ${{ needs.branch-name.outputs.lowercase }}-website-preview \
--region=${{ secrets.REGION }} \
gcloud run deploy website-backend-nginix-website-preview \
--region=${REGION} \
--max-instances=10 \
--timeout=60 \
--concurrency=10 \
--image=${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/pr-previews/website-pr-previews:${{ github.sha }} \
--port=8080 \
--image=${REGISTRY_URL}/${PROJECT_ID}/pr-previews/website-pr-previews:${GITHUB_SHA} \
--cpu=1000m \
--memory=1024Mi \
--update-secrets=/etc/env/.env=sta-env-website-backend:latest,/etc/config/google_application_credentials.json=sta-key-analytics-service-account:latest \
--command="/bin/sh","-c","cat /etc/env/.env >> /app/.env; /app/entrypoint.sh" \
--allow-unauthenticated
- name: Get preview service url
Expand Down
19 changes: 17 additions & 2 deletions src/website/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ WORKDIR /app
RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
nginx \
supervisor \
&& apt-get clean

# Copy requirements and install
Expand All @@ -20,10 +22,23 @@ RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the code
COPY . .

# Expose the port for Gunicorn
EXPOSE 8000
# Remove default Nginx config
RUN rm /etc/nginx/conf.d/default.conf

# Make sure we have a directory for static files (to serve them via Nginx)
RUN mkdir -p /usr/share/nginx/html/static/

# Add execute permission to entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# Copy custom Nginx config
COPY nginx.conf /etc/nginx/nginx.conf

# Copy supervisor config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Default port for Cloud Run is 8080, ensure Nginx listens on this port
ENV PORT 8080
EXPOSE 8080

ENTRYPOINT ["/app/entrypoint.sh"]
37 changes: 0 additions & 37 deletions src/website/docker-compose.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/website/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ python manage.py migrate --noinput
echo "Collecting static files..."
python manage.py collectstatic --noinput

echo "Starting Gunicorn..."
exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --workers 3 --log-level info
echo "Starting Supervisor (which runs Nginx + Gunicorn)..."
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
9 changes: 3 additions & 6 deletions src/website/nginx/nginx.conf → src/website/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ http {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# Set client body size limit to 10MB
client_max_body_size 10M;

upstream django_app {
# Points to the Django/Gunicorn container service name defined in docker-compose
server web:8000;
# Gunicorn will be running on 127.0.0.1:8000 inside the same container
server 127.0.0.1:8000;
}

server {
listen 80;
listen ${PORT};
server_name _;

# Serving static files directly from Nginx
# Assuming 'staticfiles' directory is where Django collectstatic places files
location /static/ {
alias /usr/share/nginx/html/static/;
expires 1y;
Expand Down
10 changes: 0 additions & 10 deletions src/website/nginx/Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions src/website/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[supervisord]
nodaemon=true

[program:gunicorn]
command=gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --workers 3 --log-level info
directory=/app
autostart=true
autorestart=true

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true

0 comments on commit e870447

Please sign in to comment.