mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-09 14:42:24 -05:00
Build db migration codedeploy artifact
This commit is contained in:
14
Makefile
14
Makefile
@@ -70,9 +70,17 @@ build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy
|
||||
mkdir -p target
|
||||
zip -r -x@deploy-exclude.lst target/notifications-api.zip *
|
||||
|
||||
rm -rf build/db-migration-codedeploy
|
||||
mkdir -p build/db-migration-codedeploy
|
||||
unzip target/notifications-api.zip -d build/db-migration-codedeploy
|
||||
cd build/db-migration-codedeploy && \
|
||||
mv -f appspec-db-migration.yml appspec.yml && \
|
||||
zip -r -x@deploy-exclude.lst ../../target/notifications-api-db-migration.zip *
|
||||
|
||||
.PHONY: upload-codedeploy-artifact ## Upload the deploy artifact for CodeDeploy
|
||||
upload-codedeploy-artifact: check-env-vars
|
||||
aws s3 cp --region eu-west-1 target/notifications-api.zip s3://${DNS_NAME}-codedeploy/notifications-api-${DEPLOY_BUILD_NUMBER}.zip
|
||||
aws s3 cp --region eu-west-1 target/notifications-api-db-migration.zip s3://${DNS_NAME}-codedeploy/notifications-api-db-migration-${DEPLOY_BUILD_NUMBER}.zip
|
||||
|
||||
.PHONY: test
|
||||
test: venv generate-version-file ## Run tests
|
||||
@@ -82,6 +90,10 @@ test: venv generate-version-file ## Run tests
|
||||
deploy-api: check-env-vars ## Trigger CodeDeploy for the api
|
||||
aws deploy create-deployment --application-name notify-api --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name notify-api --s3-location bucket=${DNS_NAME}-codedeploy,key=notifications-api-${DEPLOY_BUILD_NUMBER}.zip,bundleType=zip --region eu-west-1
|
||||
|
||||
.PHONY: deploy-api
|
||||
deploy-api-db-migration: check-env-vars ## Trigger CodeDeploy for the api db migration
|
||||
aws deploy create-deployment --application-name notify-api-db-migration --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name notify-api-db-migration --s3-location bucket=${DNS_NAME}-codedeploy,key=notifications-api-db-migration-${DEPLOY_BUILD_NUMBER}.zip,bundleType=zip --region eu-west-1
|
||||
|
||||
.PHONY: deploy-admin-api
|
||||
deploy-admin-api: check-env-vars ## Trigger CodeDeploy for the admin api
|
||||
aws deploy create-deployment --application-name notify-admin-api --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name notify-admin-api --s3-location bucket=${DNS_NAME}-codedeploy,key=notifications-api-${DEPLOY_BUILD_NUMBER}.zip,bundleType=zip --region eu-west-1
|
||||
@@ -155,4 +167,4 @@ clean-docker-containers: ## Clean up any remaining docker containers
|
||||
docker rm -f $(shell docker ps -q -f "name=${DOCKER_CONTAINER_PREFIX}") 2> /dev/null || true
|
||||
|
||||
clean:
|
||||
rm -rf node_modules cache target venv .coverage
|
||||
rm -rf node_modules cache target venv .coverage build tests/.cache
|
||||
|
||||
18
appspec-db-migration.yml
Normal file
18
appspec-db-migration.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
os: linux
|
||||
version: 0.0
|
||||
files:
|
||||
- destination: /home/notify-app/notifications-api
|
||||
source: /
|
||||
hooks:
|
||||
AfterInstall:
|
||||
- location: scripts/aws_install_dependencies.sh
|
||||
runas: root
|
||||
timeout: 1000
|
||||
- location: scripts/aws_change_ownership.sh
|
||||
runas: root
|
||||
timeout: 300
|
||||
ApplicationStart:
|
||||
- location: scripts/aws_run_db_migrations.sh
|
||||
runas: root
|
||||
timeout: 300
|
||||
25
appspec.yml
25
appspec.yml
@@ -1,35 +1,28 @@
|
||||
---
|
||||
os: linux
|
||||
version: 0.0
|
||||
files:
|
||||
-
|
||||
destination: /home/notify-app/notifications-api
|
||||
- destination: /home/notify-app/notifications-api
|
||||
source: /
|
||||
hooks:
|
||||
AfterInstall:
|
||||
-
|
||||
location: scripts/aws_install_dependencies.sh
|
||||
- location: scripts/aws_install_dependencies.sh
|
||||
runas: root
|
||||
timeout: 1000
|
||||
-
|
||||
location: scripts/aws_change_ownership.sh
|
||||
- location: scripts/aws_change_ownership.sh
|
||||
runas: root
|
||||
timeout: 300
|
||||
ApplicationStart:
|
||||
-
|
||||
location: scripts/aws_start_app.sh
|
||||
- location: scripts/aws_start_app.sh
|
||||
runas: root
|
||||
timeout: 300
|
||||
-
|
||||
location: scripts/register_with_elb.sh
|
||||
- location: scripts/register_with_elb.sh
|
||||
runas: ubuntu
|
||||
timeout: 300
|
||||
ApplicationStop:
|
||||
-
|
||||
location: scripts/deregister_from_elb.sh
|
||||
- location: scripts/deregister_from_elb.sh
|
||||
runas: ubuntu
|
||||
timeout: 300
|
||||
-
|
||||
location: scripts/aws_stop_app.sh
|
||||
- location: scripts/aws_stop_app.sh
|
||||
runas: root
|
||||
timeout: 300
|
||||
os: linux
|
||||
version: 0.0
|
||||
|
||||
@@ -7,3 +7,6 @@
|
||||
*node_modules*
|
||||
*target*
|
||||
*venv*
|
||||
*build*
|
||||
*.envrc*
|
||||
*tests/.cache*
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
if [ -e "/home/notify-app" ]
|
||||
then
|
||||
echo "Chown application to be owned by notify-app"
|
||||
cd /home/notify-app/;
|
||||
chown -R notify-app:govuk-notify-applications notifications-api
|
||||
else
|
||||
echo "Chown application to be owned by ubuntu"
|
||||
cd /home/ubuntu/;
|
||||
chown -R ubuntu:ubuntu notifications-api
|
||||
fi
|
||||
echo "Chown application to be owned by notify-app"
|
||||
|
||||
cd /home/notify-app/;
|
||||
chown -R notify-app:govuk-notify-applications notifications-api
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
echo "Install dependencies"
|
||||
|
||||
|
||||
if [ -e "/home/notify-app" ]
|
||||
then
|
||||
echo "Depenencies for notify-app"
|
||||
cd /home/notify-app/notifications-api;
|
||||
pip3 install -r /home/notify-app/notifications-api/requirements.txt
|
||||
python3 db.py db upgrade
|
||||
else
|
||||
echo "Depenencies for ubuntu"
|
||||
cd /home/ubuntu/notifications-api;
|
||||
pip3 install -r /home/ubuntu/notifications-api/requirements.txt
|
||||
python3 db.py db upgrade
|
||||
fi
|
||||
cd /home/notify-app/notifications-api;
|
||||
pip3 install -r /home/notify-app/notifications-api/requirements.txt
|
||||
|
||||
8
scripts/aws_run_db_migrations.sh
Executable file
8
scripts/aws_run_db_migrations.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
echo "Run database migrations"
|
||||
|
||||
cd /home/notify-app/notifications-api;
|
||||
python3 db.py db upgrade
|
||||
@@ -1,31 +1,19 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ -e "/etc/init/notifications-api.conf" ]
|
||||
then
|
||||
echo "Starting api"
|
||||
sudo service notifications-api start
|
||||
fi
|
||||
set -eo pipefail
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-worker.conf" ]
|
||||
then
|
||||
echo "Starting celery worker"
|
||||
sudo service notifications-api-celery-worker start
|
||||
fi
|
||||
function start
|
||||
{
|
||||
service=$1
|
||||
if [ -e "/etc/init/${service}.conf" ]
|
||||
then
|
||||
echo "Starting ${service}"
|
||||
service ${service} start
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-worker-sender.conf" ]
|
||||
then
|
||||
echo "Starting celery worker"
|
||||
sudo service notifications-api-celery-worker-sender start
|
||||
fi
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-worker-db.conf" ]
|
||||
then
|
||||
echo "Starting celery worker"
|
||||
sudo service notifications-api-celery-worker-db start
|
||||
fi
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-beat.conf" ]
|
||||
then
|
||||
echo "Starting celery beat"
|
||||
sudo service notifications-api-celery-beat start
|
||||
fi
|
||||
start "notifications-api"
|
||||
start "notifications-api-celery-worker"
|
||||
start "notifications-api-celery-worker-sender"
|
||||
start "notifications-api-celery-worker-db"
|
||||
start "notifications-api-celery-beat"
|
||||
|
||||
@@ -1,53 +1,22 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
function error_exit
|
||||
function stop
|
||||
{
|
||||
echo "$1" 1>&2
|
||||
exit 0
|
||||
service=$1
|
||||
if [ -e "/etc/init/${service}.conf" ]; then
|
||||
echo "stopping ${service}"
|
||||
if service ${service} stop; then
|
||||
echo "${service} stopped"
|
||||
else
|
||||
>&2 echo "Could not stop ${service}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -e "/etc/init/notifications-api.conf" ]; then
|
||||
echo "stopping notifications-api"
|
||||
if sudo service notifications-api stop; then
|
||||
echo "notifications-api stopped"
|
||||
else
|
||||
error_exit "Could not stop notifications-api"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-beat.conf" ]; then
|
||||
echo "stopping notifications-api-celery-beat"
|
||||
if sudo service notifications-api-celery-beat stop; then
|
||||
echo "notifications-api beat stopped"
|
||||
else
|
||||
error_exit "Could not stop notifications-celery-beat"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-worker.conf" ]; then
|
||||
echo "stopping notifications-api-celery-worker"
|
||||
if sudo service notifications-api-celery-worker stop; then
|
||||
echo "notifications-api worker stopped"
|
||||
else
|
||||
error_exit "Could not stop notifications-celery-worker"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-worker-sender.conf" ]; then
|
||||
echo "stopping notifications-api-celery-worker-sender"
|
||||
if sudo service notifications-api-celery-worker-sender stop; then
|
||||
echo "notifications-api sender worker stopped"
|
||||
else
|
||||
error_exit "Could not stop notifications-celery-worker-sender"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "/etc/init/notifications-api-celery-worker-db.conf" ]; then
|
||||
echo "stopping notifications-api-celery-worker-db"
|
||||
if sudo service notifications-api-celery-worker-db stop; then
|
||||
echo "notifications-api db worker stopped"
|
||||
else
|
||||
error_exit "Could not stop notifications-celery-worker-db"
|
||||
fi
|
||||
fi
|
||||
stop "notifications-api"
|
||||
stop "notifications-api-celery-beat"
|
||||
stop "notifications-api-celery-worker"
|
||||
stop "notifications-api-celery-worker-sender"
|
||||
stop "notifications-api-celery-worker-db"
|
||||
|
||||
Reference in New Issue
Block a user