Skip to content

Commit

Permalink
Merge pull request #1380 from OpenDataServices/2023-03-17
Browse files Browse the repository at this point in the history
Docker: Can set app limits via Env variables
  • Loading branch information
odscjames authored Mar 28, 2023
2 parents 13dd07e + 096ecde commit d6824f8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/branch-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ jobs:
DOKKUSD_REMOTE_USER: ${{ vars.DOKKU_REMOTE_USER }}
DOKKUSD_HTTP_AUTH_USER: ${{ secrets.DOKKU_HTTP_AUTH_USER }}
DOKKUSD_HTTP_AUTH_PASSWORD: ${{ secrets.DOKKU_HTTP_AUTH_PASSWORD }}
DOKKUSD_NGINX_PROXY_READ_TIMEOUT: ${{ secrets.DOKKU_ENVIRONMENT_VARIABLE_APP_TIMEOUT_SECONDS }}s
DOKKUSD_NGINX_CLIENT_MAX_BODY_SIZE: ${{ secrets.DOKKU_ENVIRONMENT_VARIABLE_APP_UPLOAD_MAXIMUM_MEGABYTES }}m
2 changes: 2 additions & 0 deletions .github/workflows/live-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ jobs:
DOKKUSD_REMOTE_HOST: ${{ vars.DOKKU_REMOTE_HOST }}
DOKKUSD_REMOTE_PORT: ${{ vars.DOKKU_REMOTE_PORT }}
DOKKUSD_REMOTE_USER: ${{ vars.DOKKU_REMOTE_USER }}
DOKKUSD_NGINX_PROXY_READ_TIMEOUT: ${{ secrets.DOKKU_ENVIRONMENT_VARIABLE_APP_TIMEOUT_SECONDS }}s
DOKKUSD_NGINX_CLIENT_MAX_BODY_SIZE: ${{ secrets.DOKKU_ENVIRONMENT_VARIABLE_APP_UPLOAD_MAXIMUM_MEGABYTES }}m
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ RUN pip install --no-binary lxml -r requirements.txt
RUN python manage.py collectstatic --noinput
RUN python manage.py compilemessages

# Webserver

COPY docker/nginx.conf /etc/nginx/sites-available/default

# Run

EXPOSE 80

CMD /bin/bash -c "/etc/init.d/nginx start && gunicorn --bind 0.0.0.0:8000 --timeout 900 cove_iati.wsgi:application"
CMD /app/docker/start.sh

3 changes: 0 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"DB_NAME": "/app/database/db.sqlite",
"DEBUG": "False"
},
"nginx": {
"client_max_body_size": "100m"
},
"keep_git_dir": true
}
}
8 changes: 4 additions & 4 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ server {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

client_max_body_size 100M;
client_max_body_size APP_UPLOAD_MAXIMUM_MEGABYTESm;

proxy_read_timeout 900;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout APP_TIMEOUT_SECONDSs;
proxy_connect_timeout APP_TIMEOUT_SECONDSs;
proxy_send_timeout APP_TIMEOUT_SECONDSs;

}
29 changes: 29 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -e

############################# Get vars

# To increase this, you also need to set the Dokku config
# dokku nginx:set APPNAME proxy-read-timeout 120s
# dokku proxy:build-config APPNAME
# If you are using Dokkusd to deploy, make sure GitHub actions also sets
# DOKKUSD_NGINX_PROXY_READ_TIMEOUT and Dokkusd will do that for you.
set APP_TIMEOUT_SECONDS="${APP_TIMEOUT_SECONDS:=60}"

# To increase this, you also need to set the Dokku config
# dokku nginx:set APPNAME client-max-body-size 50m
# If you are using Dokkusd to deploy, make sure GitHub actions also sets
# DOKKUSD_NGINX_CLIENT_MAX_BODY_SIZE and Dokkusd will do that for you.
set APP_UPLOAD_MAXIMUM_MEGABYTES="${APP_UPLOAD_MAXIMUM_MEGABYTES:=1}"

############################# Set up config files
cp /app/docker/nginx.conf /etc/nginx/sites-available/default

sed -i 's/APP_TIMEOUT_SECONDS/'$APP_TIMEOUT_SECONDS'/g' /etc/nginx/sites-available/default
sed -i 's/APP_UPLOAD_MAXIMUM_MEGABYTES/'$APP_UPLOAD_MAXIMUM_MEGABYTES'/g' /etc/nginx/sites-available/default

############################# Start Services
/etc/init.d/nginx start
cd /app
gunicorn --bind 0.0.0.0:8000 --timeout $APP_TIMEOUT_SECONDS cove_iati.wsgi:application

0 comments on commit d6824f8

Please sign in to comment.