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

Updates to docs and cpln #514

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
WIP
  • Loading branch information
justin808 committed Jan 12, 2023
commit 9fda7bcd1761997cdbbe2e364272464308159331
40 changes: 38 additions & 2 deletions .controlplane/controlplane.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# Configuration for "Heroku to CPLN playbook" custom scripts
aliases:
common: &common
# Change this to your org name for staging. Production apps will use a different org
# for security.
# Org name for staging. (customize to your needs)
# Production apps will use a different Control Plane org, specified below, for security.
# keys beginning with CPLN correspond to your settings in Control Plane
cpln_org: shakacode-staging
org: shakacode-staging

# Change `shakacode-staging` to your-org-name-for-staging
# Example apps use only location. CPLN offers the ability to use multiple locations.
# TODO -- allow specfication of multiple locations
default_location: aws-us-east-2

# TODO -- remove
location: aws-us-east-2
# Configure the workload name used as a template for one-off scripts, like a Heroku one-off dyno.
one_off_workload: rails
Expand All @@ -20,9 +27,38 @@ aliases:

apps:
ror-tutorial:
# Use the values from the common section above
<<: *common
react-webpack-rails-tutorial:
<<: *common
ror-tutorial-review:
<<: *common
# if app_name_glob == true, then use this config for app names beginning, like ror-tutorial-review-pr123
# In this case, there is no customization beyond the common
# New:
match_if_app_name_starts_with: true

# Old
prefix: true
ror-tutorial-qa:
<<: *common
# Use a different org for production
org: shakacode-staging
ror-tutorial-staging:
<<: *common
# Use a different org for production
org: shakacode-production

ror-tutorial-production:
<<: *common
# Allows running command 'cpl pipeline-promote ror-tutorial-staging' to promote the staging app to production
# https://devcenter.heroku.com/articles/pipelines#promoting-from-the-heroku-cli
upstream: ror-tutorial-staging
release_script: ./production-release-script
# Use a different org for production
org: shakacode-production

# App that leverages permissions on the org to control running of code that promotes staging to production
ror-tutorial-production-deployment-manager:
<<: *common
org: shakacode-production
58 changes: 47 additions & 11 deletions .controlplane/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,75 @@ cpl setup gvc postgres redis rails -a ror-tutorial

# Build and push docker image to Control Plane repository
# Note, may take many minutes. Be patient.
cpl build -a ror-tutorial
cpl build-image -a ror-tutorial

# Promote image to app after running `cpl build command`
cpl promote -a ror-tutorial
# Promote image to app after running `cpl build command`.
# Promotion may take several minutes before the app is "live" the first time.
# TODO
cpl promote-image -a ror-tutorial

# See how app is starting up
# Put the release phase command after building and then promote the image.
# Note, uses the latest image, not the currently running image
alias release_phase "cpl runner 'LOG_LEVEL=warn rails db:migrate' -a ror-tutorial --image latest"
cpl build -a ror-tutorial && release_phase && cpl promote -a ror-tutorial

# See how app is starting up.
# Monitor the logs to determine when app has finished started up.
cpl logs -a ror-tutorial

# Open app in browser (once it has started up)
cpl open -a ror-tutorial
```

## Promoting code upgrades
## Staging Deployment - Deploying Code Updates

```sh
# Build and push new image with sequential image tagging, e.g. 'ror-tutorial_123'
cpl build -a ror-tutorial
# TODO renamed build to build-image
cpl build-image -a ror-tutorial-staging

# OR
# Build and push with sequential image tagging and commit SHA, e.g. 'ror-tutorial_123_ABCD'
cpl build -a ror-tutorial --commit ABCD
# Build and push with sequential image tagging and commit SHA, e.g. 'ror-tutorial-staging_123_ABCD'
cpl build-image -a ror-tutorial-staging --commit ABCD

# cpl run:detached allows disconnection. Does not allow input.
# Run database migrations (or other release tasks) with latest image,
# while app is still running on previous image.
# This is analogous to the release phase.
cpl runner rails db:migrate -a ror-tutorial --image latest
# TODO - renamed runner to run:detached
cpl run:detached rails db:migrate -a ror-tutorial-staging --image latest


# Alternatively, can run command interactively. Network disconnect or Ctrl-c stop the task.
cpl run rails console -a ror-tutorial-staging --image latest

# Promote latest image to app
cpl promote-image -a ror-tutorial-staging
```


### Production Deployment
Just like a [Heroku Pipeline](https://devcenter.heroku.com/articles/pipelines#promoting-from-the-heroku-cli).

# Pomote latest image to app
promote -a ror-tutorial
```sh
# promote-app uses the `upstream` definition, in this case ror-tutorial-staging
cpl promote-app -a ror-tutorial-production

# or specify upstream app
cpl promote-app ror-tutorial-staging -a ror-tutorial-production
```

Manually, this roughly runs:
```sh
# TODO - create this script
copy-staging-image-to-production
cpl run:detached some-release-script.sh -a ror-tutorial-production --image latest
cpl promote-image -a ror-tutorial-production
```

## Other notes

### `entrypoint.sh`
- Docker concept, runs before the Dockerfile's CMD
- waits for Postgres and Redis to be available
- runs `rails db:prepare` to create/seed or migrate the database