Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
OchiengPaul442 committed Dec 11, 2024
1 parent e870447 commit f68fde6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/deploy-previews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1180,18 +1180,18 @@ jobs:

- name: Build and Push Container
run: |
cd src/website/
docker build --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/pr-previews/website-pr-previews:${{ github.sha }} ./
cd website/
docker build --tag ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/pr-previews/website-pr-previews:${{ github.sha }} .
docker push ${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/pr-previews/website-pr-previews:${{ github.sha }}
- name: Deploy to Cloud Run
run: |-
gcloud run deploy website-backend-nginix-website-preview \
--region=${REGION} \
gcloud run deploy ${{ needs.branch-name.outputs.lowercase }}-website-preview \
--region=${{ secrets.REGION }} \
--max-instances=10 \
--timeout=60 \
--concurrency=10 \
--image=${REGISTRY_URL}/${PROJECT_ID}/pr-previews/website-pr-previews:${GITHUB_SHA} \
--image=${{ env.REGISTRY_URL }}/${{ env.PROJECT_ID }}/pr-previews/website-pr-previews:${{ github.sha }} \
--cpu=1000m \
--memory=1024Mi \
--allow-unauthenticated
Expand All @@ -1218,5 +1218,5 @@ jobs:
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'website changes in this PR available for preview [here](${needs.website.outputs.url})'
body: 'Website changes in this PR are available for preview [here](${{ needs.website.outputs.url }})'
})
37 changes: 21 additions & 16 deletions src/website/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
FROM python:3.11-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Set work directory
WORKDIR /app

# Install system dependencies
Expand All @@ -13,32 +14,36 @@ RUN apt-get update && apt-get install -y \
libpq-dev \
nginx \
supervisor \
&& apt-get clean
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements and install
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the code
# Copy project code
COPY . .

# Remove default Nginx config
RUN rm /etc/nginx/conf.d/default.conf
# Remove default Nginx configuration if it exists
RUN rm -f /etc/nginx/conf.d/default.conf

# Make sure we have a directory for static files (to serve them via Nginx)
# Copy custom Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf

# Ensure staticfiles directory exists for Nginx
RUN mkdir -p /usr/share/nginx/html/static/

# Add execute permission to entrypoint.sh
RUN chmod +x /app/entrypoint.sh
# Copy Supervisor configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Copy custom Nginx config
COPY nginx.conf /etc/nginx/nginx.conf
# Make entrypoint.sh executable
RUN chmod +x /app/entrypoint.sh

# Copy supervisor config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Set the PORT environment variable (Cloud Run uses 8080 by default)
ENV PORT=8080

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

# Start the entrypoint script
ENTRYPOINT ["/app/entrypoint.sh"]
2 changes: 1 addition & 1 deletion 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 Supervisor (which runs Nginx + Gunicorn)..."
echo "Starting Supervisor (which runs Nginx and Gunicorn)..."
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
5 changes: 4 additions & 1 deletion src/website/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@ 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 {
# Gunicorn will be running on 127.0.0.1:8000 inside the same container
# Gunicorn is running on 127.0.0.1:8000 inside the container
server 127.0.0.1:8000;
}

server {
listen ${PORT};
server_name _;

# Serve static files
location /static/ {
alias /usr/share/nginx/html/static/;
expires 1y;
access_log off;
add_header Cache-Control "public";
}

# Proxy all other requests to Gunicorn
location / {
proxy_pass http://django_app;
proxy_set_header Host $host;
Expand Down
6 changes: 5 additions & 1 deletion src/website/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
nodaemon=true

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

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx_err.log

0 comments on commit f68fde6

Please sign in to comment.