Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make environments generic #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,36 @@ Add the following to your CircleCI configuration:
version: 2.1

orbs:
opsworks: nebulab/opsworks-deployment
opsworks: nebulab/opsworks-deployment@6.0.0

workflows:
build-and-deploy:
jobs:
- build
- opsworks/deploy-staging:
- opsworks/deploy:
name: deploy-staging
app_id: your-staging-opsworks-app-id
stack_id: your-staging-opsworks-stack-id
github_repo: myorg/myrepo
slack_hook_url: https://your.slack.hook.url
current_env: staging
next_env: production
requires:
- build
filters:
branches:
only: master
- approve-production:
requires:
- opsworks/deploy-staging
- deploy-staging
type: approval
filters:
branches:
only: master
- opsworks/deploy-production:
- opsworks/deploy:
name: deploy-production
app_id: your-staging-opsworks-app-id
stack_id: your-staging-opsworks-stack-id
github_repo: myorg/myrepo
slack_hook_url: https://your.slack.hook.url
current_env: production
requires:
- approve-production

Expand Down
16 changes: 9 additions & 7 deletions src/examples/trunk-based-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,36 @@ usage:
version: 2.1

orbs:
opsworks: nebulab/opsworks-deployment
opsworks: nebulab/opsworks-deployment@6.0.0

workflows:
build-and-deploy:
jobs:
- build
- opsworks/deploy-staging:
- opsworks/deploy:
name: deploy-staging
app_id: your-staging-opsworks-app-id
stack_id: your-staging-opsworks-stack-id
github_repo: myorg/myrepo
slack_hook_url: https://your.slack.hook.url
current_env: staging
next_env: production
requires:
- build
filters:
branches:
only: master
- approve-production:
requires:
- opsworks/deploy-staging
- deploy-staging
type: approval
filters:
branches:
only: master
- opsworks/deploy-production:
- opsworks/deploy:
name: deploy-production
app_id: your-staging-opsworks-app-id
stack_id: your-staging-opsworks-stack-id
github_repo: myorg/myrepo
slack_hook_url: https://your.slack.hook.url
current_env: production
requires:
- approve-production

Expand Down
60 changes: 0 additions & 60 deletions src/jobs/deploy-production.yml

This file was deleted.

79 changes: 0 additions & 79 deletions src/jobs/deploy-staging.yml

This file was deleted.

109 changes: 109 additions & 0 deletions src/jobs/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
executor: default

parameters:
app_id:
type: string
description: The ID of the OpsWorks app to deploy.
stack_id:
type: string
description: The ID of the OpsWorks stack to deploy.
github_repo:
type: string
description: The path of your GitHub repo (org/name).
slack_hook_url:
type: string
description: The URL of the Slack hook to notify.
current_env:
type: string
description: The name of the environment currently being deployed.
next_env:
type: string
description: The next of the next environment to deploy.
default: ~

steps:
- checkout
- run:
name: Install awscli
command: pip install awscli --user
- deploy:
name: Deploy to <<parameters.current_env>>
command: |
~/.local/bin/aws opsworks update-app --app-id <<parameters.app_id>> --app-source Revision=$CIRCLE_SHA1
~/.local/bin/aws opsworks wait deployment-successful --deployment-ids `~/.local/bin/aws opsworks create-deployment --stack-id <<parameters.stack_id>> --app-id <<parameters.app_id>> --command "{\"Name\":\"deploy\"}" | awk '{print $2}' | sed 's/"//g'`
- run:
name: Remember Last Deploy Ref
command: echo $CIRCLE_SHA1 > .last_deploy_<<parameters.current_env>>
- save_cache:
key: last-head-v2-{{ epoch }}
paths: .last_deploy
- when:
condition: <<parameters.next_env>>
steps:
- run:
name: Notify Successful Deploy
command: |
cat \<<- EOF > notification.json
{
"attachments": [{
"title": "Deploy",
"color": "good",
"text": "The application has been deployed to *<<parameters.current_env>>*.\nApproving the workflow will deploy to *<<parameters.next_env>>*.\nChanges are from last *<<parameters.next_env>>* deploy.",
"fields": [{
"title": "<<parameters.current_env>> Ref",
"short": true,
"value": "<https://github.com/<<parameters.github_repo>>/commit/$CIRCLE_SHA1|`echo $CIRCLE_SHA1 | cut -c1-8`>"
}, {
"title": "<<parameters.next_env>> Ref",
"short": true,
"value": "<https://github.com/<<parameters.github_repo>>/commit/`cat .last_deploy_<<parameters.next_env>>`|`cat .last_deploy | cut -c1-8`>"
}
],
"actions": [{
"type": "button",
"text": "See Changes :octocat:",
"style": "primary",
"url": "https://github.com/<<parameters.github_repo>>/compare/`cat .last_deploy_<<parameters.next_env>>`...$CIRCLE_SHA1"
}, {
"type": "button",
"style": "danger",
"text": "Approve Workflow :shipit:",
"url": "https://circleci.com/workflow-run/$CIRCLE_WORKFLOW_ID"
}
]
}]
}
EOF
curl -X POST -H 'Content-type: application/json' --data '@notification.json' <<parameters.slack_hook_url>>
when: on_success
- unless:
condition: <<parameters.next_env>>
steps:
- run:
name: Notify Successful Deploy
command: |
cat \<<- EOF > notification.json
{
"attachments": [{
"title": "Deploy",
"color": "good",
"text": "<https://github.com/<<parameters.github_repo>>/commit/$CIRCLE_SHA1|`echo $CIRCLE_SHA1 | cut -c1-8`> has been deployed to *<<parameters.current_env>>*!"
}]
}
EOF
curl -X POST -H 'Content-type: application/json' --data '@notification.json' <<parameters.slack_hook_url>>
when: on_success
- run:
name: Notify Failed Deploy
command: |
cat \<<- EOF > notification.json
{
"attachments": [{
"title": "Deploy",
"color": "danger",
"text": "<https://github.com/<<parameters.github_repo>>/commit/$CIRCLE_SHA1|`echo $CIRCLE_SHA1 | cut -c1-8`> failed being deployed to *<<parameters.current_env>>*!"
}]
}
EOF
curl -X POST -H 'Content-type: application/json' --data '@notification.json' <<parameters.slack_hook_url>>
when: on_fail