Skip to content

Instantly share code, notes, and snippets.

@ChristopherJohnson25
Last active November 1, 2020 21:59
Show Gist options
  • Save ChristopherJohnson25/7350169203a2ecfa9193785bede52bd3 to your computer and use it in GitHub Desktop.
Save ChristopherJohnson25/7350169203a2ecfa9193785bede52bd3 to your computer and use it in GitHub Desktop.
Ember/Travis Deployment Pipeline
---
language: node_js
node_js:
- "6"
sudo: false
dist: trusty
addons:
chrome: stable
cache:
directories:
- $HOME/.npm
deploy:
- provider: script
skip_cleanup: true
script: node_modules/.bin/ember deploy production --activate --verbose
on:
branch: master
- provider: script
skip_cleanup: true
script: node_modules/.bin/ember deploy staging --activate --verbose
on:
branch: staging
branches:
only:
- master
- staging
script:
- npm test
script:
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then node_modules/.bin/ember build; fi
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then npm install surge; fi
env:
global:
- JOBS=1
before_install:
- npm config set spin false
after_success:
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then chmod ugo+x ./pr_deploy.sh; fi
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then ./deploy.sh; fi
/* located in /config/deploy.js */
/* eslint-env node */
'use strict';
module.exports = function(deployTarget) {
let ENV = {
build: {
environment: deployTarget
},
'revision-data': {
type: 'git-commit'
},
's3-index': {
accessKeyId: "<AWS_ACCESS_KEY_ID>",
secretAccessKey: "<AWS_ACCESS_KEY>",
region: "us-east-2",
allowOverwrite: true
},
's3': {
accessKeyId: "<AWS_ACCESS_KEY_ID>",
secretAccessKey: "<AWS_ACCESS_KEY>",
region: "us-east-2",
},
'slack': {
webhookURL: 'https://hooks.slack.com/services/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',
channel: '#deployments',
username: 'DeployBot',
iconEmoji: ':monkey_face:',
willDeploy: function(context) {
return function(slack) {
return {
slackStartDeployDate: new Date()
};
};
},
didDeploy: function(context) {
return function(slack) {
var start = context.slackStartDeployDate;
var end = new Date();
var duration = (end - start) / 1000;
return slack.notify({
text: 'Deployed to '+deployTarget+'! Deployment took '+duration+' seconds.'
});
};
},
didFail: function(context) {
return function(slack) {
return slack.notify({
text: 'Deployment to '+deployTarget+' failed! Check your code and try again.'
});
};
}
}
};
if (deployTarget === 'development') {
ENV.build.environment = 'development';
}
if (deployTarget === 'staging') {
ENV.build.environment = 'staging';
// replace buckets with different staging/production server buckets
ENV.s3.bucket = '<bucket-name>';
ENV['s3-index'].bucket = '<bucket-name>';
}
if (deployTarget === 'production') {
ENV.build.environment = 'production';
// replace buckets with different staging/production server buckets
ENV.s3.bucket = '<bucket-name>';
ENV['s3-index'].bucket = '<bucket-name>';
}
return ENV;
};
$ ember install ember-cli-deploy
$ ember install ember-cli-deploy-build
$ ember install ember-cli-deploy-revision-data
$ ember install ember-cli-deploy-display-revisions
$ ember install ember-cli-deploy-gzip
$ ember install ember-cli-deploy-s3-index
$ ember install ember-cli-deploy-slack
#!/bin/bash
# Split on "/", ref: http://stackoverflow.com/a/5257398/689223
REPO_SLUG_ARRAY=(${TRAVIS_REPO_SLUG//\// })
REPO_OWNER=${REPO_SLUG_ARRAY[0]}
REPO_NAME=${REPO_SLUG_ARRAY[1]}
DEPLOY_PATH=./dist
DEPLOY_SUBDOMAIN_UNFORMATTED_LIST=()
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
DEPLOY_SUBDOMAIN_UNFORMATTED_LIST+=(pull-request-${TRAVIS_PULL_REQUEST})
# scripts for push and tag servers, currently PR viewing is only needed but will leave these here.
# elif [ -n "${TRAVIS_TAG// }" ] #TAG is not empty
# then
# #sorts the tags and picks the latest
# #sort -V does not work on the travis machine
# #sort -V ref: http://stackoverflow.com/a/14273595/689223
# #sort -t ... ref: http://stackoverflow.com/a/4495368/689223
# #reverse with sed ref: http://stackoverflow.com/a/744093/689223
# #git tags | ignore release candidates | sort versions | reverse | pick first line
# LATEST_TAG=`git tag | grep -v rc | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | sed '1!G;h;$!d' | sed -n 1p`
# echo $LATEST_TAG
# if [ "$TRAVIS_TAG" == "$LATEST_TAG" ]
# then
# DEPLOY_SUBDOMAIN_UNFORMATTED_LIST+=(latest)
# fi
# DEPLOY_SUBDOMAIN_UNFORMATTED_LIST+=(${TRAVIS_TAG}-tag)
# else
# DEPLOY_SUBDOMAIN_UNFORMATTED_LIST+=(${TRAVIS_BRANCH}-branch)
fi
for DEPLOY_SUBDOMAIN_UNFORMATTED in "${DEPLOY_SUBDOMAIN_UNFORMATTED_LIST[@]}"
do
echo $DEPLOY_SUBDOMAIN_UNFORMATTED
DEPLOY_SUBDOMAIN=`echo "$DEPLOY_SUBDOMAIN_UNFORMATTED" | sed -r 's/[\/|\.]+/\-/g'`
DEPLOY_DOMAIN=http://${DEPLOY_SUBDOMAIN}.${REPO_NAME}.surge.sh
surge --project ${DEPLOY_PATH} --domain $DEPLOY_DOMAIN;
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
GITHUB_STATUS_COMMENT=https://api.github.com/repos/${TRAVIS_REPO_SLUG}/statuses/${TRAVIS_PULL_REQUEST_SHA}
curl -H "Authorization: token ${GITHUB_API_TOKEN}" --request POST ${GITHUB_STATUS_COMMENT} --data '{"state": "success", "target_url": "'${DEPLOY_DOMAIN}'", "description": "Pull Request Deployed!", "context": "CollectiveDynamicDeploy"}'
# GITHUB_PR_COMMENTS=https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments
# curl -H "Authorization: token ${GITHUB_API_TOKEN}" --request POST ${GITHUB_PR_COMMENTS} --data '{"body":"Pull Request Deployed at: '${DEPLOY_DOMAIN}'"}'
# Slack Integration
curl -X POST --data-urlencode "payload={\"username\": \"CollectiveDeployBot\",\"text\": \"Pull Request '${TRAVIS_PULL_REQUEST_BRANCH}' of '${REPO_NAME}' deployed at ${DEPLOY_DOMAIN}\", \"icon_emoji\": \":monkey_face:\"}" https://hooks.slack.com/services/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
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment