Skip to content

Commit

Permalink
Get migrations working
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Gilmer committed Jan 7, 2020
1 parent 610c931 commit 7db4b05
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
15 changes: 11 additions & 4 deletions cmd/ecs-deploy/task_def.go
Expand Up @@ -450,6 +450,10 @@ func taskDefFunction(cmd *cobra.Command, args []string) error {
commandName := entryPointList[0]
subCommandName := entryPointList[1]

// Register the new task definition
executionRoleArn := fmt.Sprintf("ecs-task-execution-role-%s-%s", serviceName, environmentName)
taskRoleArn := fmt.Sprintf("ecs-task-role-%s-%s", serviceName, environmentName)

// handle entrypoint specific logic
var awsLogsStreamPrefix string
var awsLogsGroup string
Expand All @@ -471,6 +475,13 @@ func taskDefFunction(cmd *cobra.Command, args []string) error {
awsLogsStreamPrefix = serviceName
awsLogsGroup = fmt.Sprintf("ecs-tasks-%s-%s", serviceNameShort, environmentName)
containerDefName = fmt.Sprintf("%s-%s", serviceName, environmentName)

// TODO: The execution role needs to be split from the app
// This needs to be fixed in terraform
executionRoleArn = fmt.Sprintf("ecs-task-execution-role-%s-%s", serviceNameShort, environmentName)
// TODO: The task role is missing an (s) so we can't use service name
// This needs to be fixed in terraform
taskRoleArn = fmt.Sprintf("ecs-task-role-app-migration-%s", environmentName)
} else {
awsLogsStreamPrefix = serviceNameShort
awsLogsGroup = fmt.Sprintf("ecs-tasks-%s-%s", serviceName, environmentName)
Expand All @@ -487,10 +498,6 @@ func taskDefFunction(cmd *cobra.Command, args []string) error {
}
}

// Register the new task definition
executionRoleArn := fmt.Sprintf("ecs-task-execution-role-%s-%s", serviceName, environmentName)
taskRoleArn := fmt.Sprintf("ecs-task-role-%s-%s", serviceName, environmentName)

// Get the database host using the instance identifier
dbInstanceIdentifier := fmt.Sprintf("%s-%s", serviceNameShort, environmentName)
dbInstancesOutput, err := serviceRDS.DescribeDBInstances(&rds.DescribeDBInstancesInput{
Expand Down
3 changes: 2 additions & 1 deletion scripts/deploy-app
Expand Up @@ -46,7 +46,8 @@ CIRCLE_SHA1=$(curl -s "https://${compare_host}/health" | jq -r .gitCommit)

scripts/compare-deployed-commit "${compare_host}" "${CIRCLE_SHA1}"

scripts/ecs-deploy-service-container app "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app:git-${CIRCLE_SHA1}" "${APP_ENVIRONMENT}"
readonly image="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app:git-${CIRCLE_SHA1}"
scripts/ecs-deploy-service-container app "${image}" "${APP_ENVIRONMENT}"

bin/health-checker --schemes http,https --hosts "${health_check_hosts}" --tries 10 --backoff 3 --log-level info --timeout 15m

Expand Down
3 changes: 2 additions & 1 deletion scripts/deploy-app-client-tls
Expand Up @@ -51,7 +51,8 @@ CIRCLE_SHA1=$(curl -sk --key <(echo "${KEY}" | base64 --decode) --cert <(echo "$

scripts/compare-deployed-commit "${compare_host}" "${CIRCLE_SHA1}" "${KEY}" "${CERT}" "${CA}"

scripts/ecs-deploy-service-container app-client-tls "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app:git-${CIRCLE_SHA1}" "${APP_ENVIRONMENT}"
readonly image="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app:git-${CIRCLE_SHA1}"
scripts/ecs-deploy-service-container app-client-tls "${image}" "${APP_ENVIRONMENT}"

# NOTE: The health checker in all environments ought to work with the values from experimental for the key, cert, and ca.
bin/health-checker --schemes https --hosts "${health_check_hosts}" --key "${KEY}" --cert "${CERT}" --ca "${CA}" --tries 10 --backoff 3 --log-level info --timeout 15m
Expand Down
3 changes: 2 additions & 1 deletion scripts/deploy-app-migrations
Expand Up @@ -43,4 +43,5 @@ CIRCLE_SHA1=$(curl -s "https://${compare_host}/health" | jq -r .gitCommit)

scripts/compare-deployed-commit "${compare_host}" "${CIRCLE_SHA1}"

scripts/ecs-run-app-migrations-container "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app-migrations:git-${CIRCLE_SHA1}" "${APP_ENVIRONMENT}"
readonly image="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app-migrations:git-${CIRCLE_SHA1}"
scripts/ecs-run-app-migrations-container "${image}" "${APP_ENVIRONMENT}"
1 change: 0 additions & 1 deletion scripts/deploy-app-tasks
Expand Up @@ -44,6 +44,5 @@ CIRCLE_SHA1=$(curl -s "https://${compare_host}/health" | jq -r .gitCommit)
scripts/compare-deployed-commit "${compare_host}" "${CIRCLE_SHA1}"

readonly image="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/app-tasks:git-${CIRCLE_SHA1}"

scripts/ecs-deploy-task-container save-fuel-price-data "${image}" "${APP_ENVIRONMENT}"
scripts/ecs-deploy-task-container send-post-move-survey "${image}" "${APP_ENVIRONMENT}"
14 changes: 7 additions & 7 deletions scripts/ecs-run-app-migrations-container
Expand Up @@ -4,11 +4,14 @@
#
set -eo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
readonly DIR

usage() {
echo "$0 <image> <environment>"
exit 1
}
[[ -z $1 || -z $2 || -z $3 ]] && usage
[[ -z $1 || -z $2 ]] && usage

set -u

Expand Down Expand Up @@ -56,14 +59,11 @@ task_definition_arn=$(ecs-deploy task-def \
--service "${name}" \
--environment "${environment}" \
--image "${image}" \
--variables-file "config/env/${environment}.migrations.env" \
--variables-file "${DIR}/../config/env/${environment}.migrations.env" \
--entrypoint "/bin/milmove migrate" \
--cpu "${RESERVATION_CPU}" \
--memory "${RESERVATION_MEM}" \
--register \
--dry-run)
# TODO: This is broken until tested
exit 1
--register)

readonly task_definition_arn
check_arn "$task_definition_arn"
Expand All @@ -72,7 +72,7 @@ echo "Obtaining the current network configuration"
network_configuration=$(aws ecs describe-services --services app --cluster "$cluster" --query 'services[0].networkConfiguration')
readonly network_configuration

echo "Running task definition $task_definition_arn ..."
echo "Running migration with task definition $task_definition_arn ..."
task_arn=$(aws ecs run-task --launch-type FARGATE --network-configuration "$network_configuration" --task-definition "$task_definition_arn" --cluster "$cluster" --query 'tasks[].taskArn' --output text)
readonly task_arn
check_arn "$task_arn"
Expand Down

0 comments on commit 7db4b05

Please sign in to comment.