Skip to content

Commit

Permalink
Merge pull request #1252 from GSA/maintenance-page
Browse files Browse the repository at this point in the history
Maintenance page
  • Loading branch information
FuhuXia authored Feb 14, 2024
2 parents 53e487d + 441cba7 commit c90f7a0
Show file tree
Hide file tree
Showing 7 changed files with 864 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ validate-proxy:
sed -i 's#{{env "S3_URL"}}#http://test.com#g' proxy/nginx-common.conf
sed -i 's#{{env "S3_BUCKET"}}#somebucket#g' proxy/nginx-common.conf
sed -i 's#{{env "DENY_PACKAGE_CREATE"}}#truetodeny#g' proxy/nginx-common.conf
sed -i 's#{{env "CATALOG_WEB_MODE"}}#webmaintenance#g' proxy/nginx.conf
sed -i 's#{{env "CATALOG_ADMIN_MODE"}}#adminmaintenance#g' proxy/nginx.conf
docker run --rm -e nameservers=127.0.0.1 -v $(shell pwd)/proxy:/proxy nginx nginx -t -c /proxy/nginx.conf
sed -i 's/127.0.0.1/{{nameservers}}/g' proxy/nginx.conf
sed -i 's/127.0.0.2/{{env "EXTERNAL_ROUTE"}}/g' proxy/nginx.conf proxy/nginx-cloudfront.conf
Expand All @@ -72,6 +74,8 @@ validate-proxy:
sed -i 's#http://test.com#{{env "S3_URL"}}#g' proxy/nginx-common.conf
sed -i 's#somebucket#{{env "S3_BUCKET"}}#g' proxy/nginx-common.conf
sed -i 's/truetodeny/{{env "DENY_PACKAGE_CREATE"}}/g' proxy/nginx-common.conf
sed -i 's/webmaintenance/{{env "CATALOG_WEB_MODE"}}/g' proxy/nginx.conf
sed -i 's/adminmaintenance/{{env "CATALOG_ADMIN_MODE"}}/g' proxy/nginx.conf

quick-bat-test:
# if local environment is already build and running
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,8 @@ You can log into your instance with you login.gov user.
Continuous Integration via [GitHub Actions](https://github.com/GSA/catalog.data.gov/actions/workflows/commit.yml).

Continuous Deployment via [GitHub Actions](https://github.com/GSA/catalog.data.gov/actions/workflows/publish.yml).


## Put site into maintenance mode

To block access to the catalog apps (`catalog-web`, `catalog-admin`), set the environment variables (`CATALOG_WEB_MODE`, `CATALOG_ADMIN_MODE`) in the `catalog-proxy` app. Use 'MAINTENANCE' for scheduled downtime, 'DOWN' for unscheduled downtime. Any other value will resume normal operation.
6 changes: 5 additions & 1 deletion proxy/nginx-common.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ location /sitemap {
proxy_pass https://${s3_url}/${s3_bucket}$request_uri;
}

error_page 500 502 503 504 /500.html;
proxy_intercept_errors on;
error_page 500 502 504 /500.html;
location = /500.html {
root ./public;
}
# NGINX searches for a URI that starts with /static-assets/ in the ./public/static-assets/ directory
location /static-assets/ {}

# prevent users from accessing: '/dataset/new' route, 'package_create' and 'resource_create' API routes
location ~ ^/(dataset\/new|api\/action\/package_create|api\/action\/resource_create)/?$ {
Expand All @@ -103,3 +106,4 @@ location /maptiles {
proxy_redirect off;
proxy_pass https://tile.openstreetmap.org/;
}

42 changes: 42 additions & 0 deletions proxy/nginx-maintenance.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## This will put the site into maintenance mode depending on the environment variable.

# $operation_mode is set from {{env "CATALOG_WEB_MODE"}} or {{env "CATALOG_ADMIN_MODE"}}
# from previous nginx configuration
# it is '' if the environment variable is not set
set $takedown "0";
if ($operation_mode = 'MAINTENANCE') {
set $takedown "1";
}
if ($operation_mode = 'DOWN') {
set $takedown "2";
}
# Allow access to the following paths
if ($uri = "/api/action/status_show") {
set $takedown "0";
}
if ($uri = "/user/saml2login") {
set $takedown "0";
}
if ($uri ~* "/static-assets/") {
set $takedown "0";
}

if ($takedown != "0") {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
if ($takedown = "1") {
rewrite ^(.*)$ /maintenance.html break;
}
if ($takedown = "2") {
rewrite ^(.*)$ /sitedown.html break;
}
rewrite ^(.*)$ /500.html break;
}
location = /maintenance.html {
root ./public;
}
location = /sitedown.html {
root ./public;
}
4 changes: 4 additions & 0 deletions proxy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ http {
include nginx-badbot403.conf;
include nginx-goodbot200.conf;
include nginx-common.conf;
set $operation_mode '{{env "CATALOG_WEB_MODE"}}';
include nginx-maintenance.conf;
}

server {
Expand All @@ -49,6 +51,8 @@ http {

include nginx-authy.conf;
include nginx-common.conf;
set $operation_mode '{{env "CATALOG_ADMIN_MODE"}}';
include nginx-maintenance.conf;
}
}

Expand Down
Loading

0 comments on commit c90f7a0

Please sign in to comment.