Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Add docker-based deployment tooling environment
Browse files Browse the repository at this point in the history
- Add docker-compose.ci.yml, with a terraform 0.9.11 container for deployments
- Add STRATA script to deploy terraform changes and upload files to site bucket
- Don’t run STRTA scripts in the VM
- Make linter output available outside of app container
  • Loading branch information
tnation14 committed Sep 7, 2017
1 parent 1e1aa1d commit 6067bc4
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 54 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ deployment/ansible/roles/azavea.*

.env

deployment/terraform/.terraform
*.tfvars
*.tfplan
*.tfstate*
37 changes: 12 additions & 25 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ node {
}

env.AWS_PROFILE = 'climate'
env.GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
env.CLIMATE_CHANGE_LAB_PORT = 4422
env.CC_SETTINGS_BUCKET = 'staging-us-east-1-climate-lab-config'
env.CC_SITE_BUCKET = 'staging-us-east-1-climate-lab-site'

// set environment variables for staging or production; default to staging
env.API_HOST = 'https://app.staging.climate.azavea.com';
env.S3_WEBSITE_CONFIG_DIR = ".";
env.CLOUDFRONT_ID_VAR = "CCLAB_AWS_STAGING_CLOUDFRONT_ID";

if (env.BRANCH_NAME == 'master') {
env.API_HOST = 'https://app.climate.azavea.com';
env.S3_WEBSITE_CONFIG_DIR = "production_s3/";
env.CLOUDFRONT_ID_VAR = "CCLAB_AWS_PRODUCTION_CLOUDFRONT_ID";
env.CC_SETTINGS_BUCKET = 'production-us-east-1-climate-lab-config'
env.CC_SITE_BUCKET = 'production-us-east-1-climate-lab-site'
}

stage('setup') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'scripts/setup'
sh 'scripts/update'
}
}

Expand All @@ -34,12 +32,12 @@ node {
export const apiHost = \'${env.API_HOST}\';
export const defaultScenario = \'RCP85\';\n"""

sh 'vagrant ssh -c "/vagrant/scripts/test --jenkins"'
sh './scripts/test --jenkins'

step([$class: 'WarningsPublisher',
parserConfigurations: [[
parserName: 'JSLint',
pattern: 'violations.xml'
pattern: 'jenkins/violations.xml'
]],
// mark build unstable if there are any linter warnings
unstableTotalAll: '0',
Expand All @@ -50,28 +48,17 @@ node {

stage('cibuild') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'vagrant ssh -c "/vagrant/scripts/cibuild"'
sh './scripts/cibuild'
}
}

// Publish to S3
stage('publish') {
stage('infra') {
if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master') {
// Decode the credentials stored within Jenkins.
withCredentials([[$class: 'StringBinding',
credentialsId: 'CCLAB_AWS_S3_ACCESS_KEY',
variable: 'CCLAB_AWS_S3_ACCESS_KEY'],
[$class: 'StringBinding',
credentialsId: 'CCLAB_AWS_S3_SECRET_ACCESS_KEY',
variable: 'CCLAB_AWS_S3_SECRET_ACCESS_KEY'],
[$class: 'StringBinding',
credentialsId: "${env.CLOUDFRONT_ID_VAR}",
variable: 'CCLAB_AWS_CLOUDFRONT_ID']]) {
wrap([$class: 'AnsiColorBuildWrapper']) {
writeFile file: '.env', text: """export CCLAB_AWS_S3_ACCESS_KEY="${env.CCLAB_AWS_S3_ACCESS_KEY}"\nexport CCLAB_AWS_S3_SECRET_ACCESS_KEY="${env.CCLAB_AWS_S3_SECRET_ACCESS_KEY}"\nexport CCLAB_AWS_CLOUDFRONT_ID="${env.CCLAB_AWS_CLOUDFRONT_ID}"\nexport S3_WEBSITE_CONFIG_DIR="${env.S3_WEBSITE_CONFIG_DIR}"\n"""
sh 'vagrant ssh -c "/vagrant/scripts/cipublish"'
sh 'docker-compose -f docker-compose.ci.yml run --rm terraform ./scripts/infra plan'
sh 'docker-compose -f docker-compose.ci.yml run --rm terraform ./scripts/infra apply'
}
}
}
}

Expand Down Expand Up @@ -100,7 +87,7 @@ node {
} finally {
stage('cleanup') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'vagrant halt'
sh 'docker-compose down -v'
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '2.1'
services:
terraform:
image: quay.io/azavea/terraform:0.9.11
volumes:
- ./:/usr/local/src
- $HOME/.aws:/root/.aws:ro
environment:
- AWS_PROFILE=climate
- CC_DEBUG=1
- CC_SETTINGS_BUCKET=${CC_SETTINGS_BUCKET:-staging-us-east-1-climate-lab-config}
- CC_SITE_BUCKET=${CC_SITE_BUCKET:-staging-us-east-1-climate-lab-site}
working_dir: /usr/local/src
entrypoint: bash
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
entrypoint: yarn
volumes:
- ./src/:/opt/app/src/
- ./jenkins/:/opt/app/jenkins/
- ./dist/:/opt/app/dist/
- ./.angular-cli.json:/opt/app/.angular-cli.json
- ./karma.conf.js:/opt/app/karma.conf.js
Expand Down
10 changes: 8 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ module.exports = function (config) {
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: true
singleRun: true,
customLaunchers: {
ChromeHeadless: {
base: 'Chromium',
flags: ['--no-sandbox', '--disable-gpu', '--headless', '--remote-debugging-port=9222']
}
}
});
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build:prod": "ng build -prod --aot --extract-css",
"test": "ng test",
"lint": "ng lint --type-check",
"lint:ci": "ng lint --type-check --format checkstyle > violations.xml",
"lint:ci": "ng lint --type-check --format checkstyle > jenkins/violations.xml",
"e2e": "ng e2e"
},
"private": true,
Expand Down
26 changes: 0 additions & 26 deletions scripts/cipublish

This file was deleted.

62 changes: 62 additions & 0 deletions scripts/infra
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

set -e

if [[ -n "${CC_DEBUG}" ]]; then
set -x
fi

DIR="$(dirname "$0")"

TERRAFORM_DIR="${DIR}/../deployment/terraform"
CC_SITE_BUCKET="staging-us-east-1-climate-lab-site"

function usage() {
echo -n \
"Usage: $(basename "$0")
Execute Terraform subcommands with remote state management.
"
}

if [ "${BASH_SOURCE[0]}" = "${0}" ]
then
if [ "${1:-}" = "--help" ]
then
usage
else
if [[ -n "${CC_SETTINGS_BUCKET}" ]] && [[ -n "${CC_SITE_BUCKET}" ]];
then
pushd "${TERRAFORM_DIR}"
aws s3 cp "s3://${CC_SETTINGS_BUCKET}/terraform/terraform.tfvars" "${CC_SETTINGS_BUCKET}.tfvars"

case "${1}" in
plan)
rm -rf .terraform terraform.tfstate*

terraform init \
-backend-config="bucket=${CC_SETTINGS_BUCKET}" \
-backend-config="key=terraform/state"

terraform plan \
-var-file="${CC_SETTINGS_BUCKET}.tfvars" \
-out="${CC_SETTINGS_BUCKET}.tfplan"
aws s3 sync --dryrun --delete ../../dist/_site "s3://${CC_SITE_BUCKET}/"
;;
apply)
terraform apply "${CC_SETTINGS_BUCKET}.tfplan"
aws s3 sync --delete ../../dist/_site "s3://${CC_SITE_BUCKET}/"
;;
*)
echo "ERROR: I don't have support for that Terraform subcommand!"
exit 1
;;
esac

popd

else
echo "ERROR: CC_SETTINGS_BUCKET is undefined."
exit 1
fi
fi
fi

0 comments on commit 6067bc4

Please sign in to comment.