Merge pull request #129 from cisagov/ik/build-deploy-script

Add build and deploy scripts
This commit is contained in:
Igor Korenfeld 2022-09-16 13:00:05 -04:00 committed by GitHub
commit 331d2e575a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 3 deletions

View file

@ -49,9 +49,10 @@ cf target -o cisa-getgov-prototyping -s unstable
cf push getgov-unstable -f ops/manifests/manifest-unstable.yaml
cf run-task getgov-unstable --command 'python manage.py migrate' --name migrate
```
Alternatively, you could run the `deploy.sh` script in the `/src` directory to build the assets and deploy to `unstable`. Similarly, you could run `build.sh` script to just compile and collect the assets without deploying.
## Serving static assets
We are using [WhiteNoise](http://whitenoise.evans.io/en/stable/index.html) plugin to serve our static assets on cloud.gov. This plugin is added to the `MIDDLEWARE` list in our apps `settings.py`.
Note that its a good idea to run `collectstatic` locally or in the docker container before pushing files up to `unstable`. This is because `collectstatic` relies on timestamps when deciding to whether to overwrite the existing assets in `/public`. Due the way files are uploaded, the compiled css in the `/assets/css` folder on `unstable` will have a slightly earlier timestamp than the files in `/public/css`, and consequently running `collectstatic` on`unstable` will not update `public/css` as you may expect.
Note that its a good idea to run `collectstatic` locally or in the docker container before pushing files up to `unstable`. This is because `collectstatic` relies on timestamps when deciding to whether to overwrite the existing assets in `/public`. Due the way files are uploaded, the compiled css in the `/assets/css` folder on `unstable` will have a slightly earlier timestamp than the files in `/public/css`, and consequently running `collectstatic` on`unstable` will not update `public/css` as you may expect. For convenience, both the `deploy.sh` and `build.sh` scripts will take care of that.

View file

@ -3,4 +3,4 @@
This directory contains files related to deploying or running the application(s).
Documentation is in [docs/ops](../docs/ops).
Documentation is in [docs/ops](../docs/operations/).

8
ops/scripts/build.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
# Compile assets
docker compose run node npx gulp compile;
docker compose run node npx gulp copyAssets;
# Collect assets
docker compose run app python manage.py collectstatic --noinput

10
ops/scripts/deploy.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
# Compile and collect static assets
../ops/scripts/build.sh
# Deploy to unstable
cf target -o cisa-getgov-prototyping -s unstable
cf push getgov-unstable -f ../ops/manifests/manifest-unstable.yaml
cf run-task getgov-unstable --command 'python manage.py migrate' --name migrate

1
src/build.sh Symbolic link
View file

@ -0,0 +1 @@
../ops/scripts/build.sh

1
src/deploy.sh Symbolic link
View file

@ -0,0 +1 @@
../ops/scripts/deploy.sh

View file

@ -26,3 +26,4 @@ i.e.
p {
color: color('blue-10v');
}

View file

@ -15,5 +15,7 @@ else
fi
fi
python manage.py collectstatic --settings=registrar.config.settings --noinput
# Make sure that django's `collectstatic` has been run locally before pushing up to unstable,
# so that the styles and static assets to show up correctly on unstable.
gunicorn registrar.config.wsgi -t 60