Skip to content

Commit

Permalink
Updates for ControlPlane deploy (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha authored Oct 26, 2023
1 parent d3eddb6 commit 94d1179
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 71 deletions.
13 changes: 3 additions & 10 deletions .controlplane/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@ RUN bundle config set without 'development test' && \
bundle install --jobs=3 --retry=3

# install node packages
COPY package.json yarn.lock .
COPY package.json yarn.lock ./
RUN yarn install

# pick necessary app files
COPY Gemfile* config.ru Rakefile babel.config.js ./
COPY app ./app
COPY bin ./bin
COPY client ./client
COPY config ./config
COPY db ./db
COPY lib ./lib
COPY public ./public
COPY . ./

ENV RAILS_ENV=production
ENV NODE_ENV=production

# compiling assets requires any value for ENV of SECRET_KEY_BASE
ENV SECRET_KEY_BASE=NOT_USED_NON_BLANK

RUN rails react_on_rails:locale
RUN rails assets:precompile

# add entrypoint
Expand Down
12 changes: 8 additions & 4 deletions .controlplane/controlplane.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# 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.
cpln_org: shakacode-demo
# Change `shakacode-staging` to your-org-name-for-staging
# Org for staging and QA apps is typically set as an alias
# Production apps will use a different org than staging for security.
# Change this value to your org name
# or set ENV value to CPLN_ORG as that will override whatever is used here for all cpl commands
# cpln_org: shakacode-open-source-examples

# Example apps use only location. CPLN offers the ability to use multiple locations.
default_location: aws-us-east-2
# Configure the workload name used as a template for one-off scripts, like a Heroku one-off dyno.
Expand All @@ -13,10 +15,12 @@ aliases:
# and the application image updates.
app_workloads:
- rails
- daily-task
# Like Heroku add-ons
additional_workloads:
- redis
- postgres
- daily-task

apps:
react-webpack-rails-tutorial:
Expand Down
62 changes: 44 additions & 18 deletions .controlplane/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,63 @@ You can see the definition of Postgres and Redis in the `.controlplane/templates
## Prerequisites

1. Ensure your [Control Plane](https://controlplane.com) account is set up.
You should have an `organization` `<your-org>` for testing in that account.
You will modify value for `aliases.common.cpln_org` in `.controlplane/controlplane.yml`.
If you need an organization, please [contact Shakacode](mailto:[email protected]).

2. Set up an `organization` for testing in that account and modify `aliases.common.cpln_org` in `.controlplane/controlplane.yml` .
2. Run `cpln image docker-login --org <your-org>` to ensure that you have access to the Control Plane Docker registry.

3. Install Control Plane CLI (and configure access) [docs here](https://docs.controlplane.com/quickstart/quick-start-3-cli#getting-started-with-the-cli). You can update the `cpln` command line with the same command as installation, `npm install -g @controlplane/cli`. Then run `cpln login` to ensure access.
3. Install Control Plane CLI (and configure access) using `npm install -g @controlplane/cli`.
You can update the `cpln` command line with `npm update -g @controlplane/cli`.
Then run `cpln login` to ensure access.
For more informatation check out the
[docs here](https://docs.controlplane.com/quickstart/quick-start-3-cli#getting-started-with-the-cli).

4. Install [Heroku to Control Plane](https://github.com/shakacode/heroku-to-control-plane) playbook CLI [`cpl` gem](https://rubygems.org/gems/cpl) on your project's Gemfile or globally.
4. Install the latest version of
[`cpl` gem](https://rubygems.org/gems/cpl)
on your project's Gemfile or globally.
For more information check out
[Heroku to Control Plane](https://github.com/shakacode/heroku-to-control-plane).

5. This project has a `Dockerfile` for Control Plane in this directory. You can use it as an example for your project. Ensure that you have Docker running.
5. This project has a `Dockerfile` for Control Plane in `.controlplane` directory.
You can use it as an example for your project.
Ensure that you have Docker running.

## Tips
Do not confuse the `cpl` CLI with the `cpln` CLI. The `cpl` CLI is the Heroku to Control Plane playbook CLI. The `cpln` CLI is the Control Plane CLI.
### Tips
Do not confuse the `cpl` CLI with the `cpln` CLI.
The `cpl` CLI is the Heroku to Control Plane playbook CLI.
The `cpln` CLI is the Control Plane CLI.

## Project Configuration
See the filese in the `./controlplane` directory.

1. `/templates`: defines the objects created with the `cpl setup` command.
2. `/controlplane.yml`: defines the organization, location, and app name.
These YAML files are the same as used by the `cpln apply` command.
2. `/controlplane.yml`: defines your application, including the organization, location, and app name.
3. `Dockerfile`: defines the Docker image used to run the app on Control Plane.
4. `entrypoint.sh`: defines the entrypoint script used to run the app on Control Plane.

## Setup and run

Check if the Control Plane organization and location are correct in `.controlplane/controlplane.yml`. You should be able to see this information in the Control Plane UI.
Check if the Control Plane organization and location are correct in `.controlplane/controlplane.yml`.
You should be able to see this information in the Control Plane UI.

```sh
# Note, below commands use `cpl` which is the Heroku to Control Plane playbook script.
**Note:** The below commands use `cpl` which is the Heroku to Control Plane playbook gem,
and not `cpln` which is the Control Plane CLI.

```sh
# Provision all infrastructure on Control Plane.
# app tutorial-app will be created per definition in .controlplane/controlplane.yml
cpl setup gvc postgres redis rails -a tutorial-app
cpl apply-template gvc postgres redis rails -a tutorial-app

# Build and push docker image to Control Plane repository
# Note, may take many minutes. Be patient.
# Check for error messages, such as forgetting to run `cpln image docker-login --org <your-org>`
cpl build-image -a tutorial-app

# Promote image to app after running `cpl build-image command`
# Note, the UX of images may not show the image for up to 5 minutes.
# However, it's ready.
cpl deploy-image -a tutorial-app

# See how app is starting up
Expand All @@ -56,25 +77,30 @@ cpl logs -a tutorial-app
cpl open -a tutorial-app
```

## Promoting code upgrades
### Promoting code updates

After committing code, you will update your deployment of `tutorial-app` with the following commands:

```sh
# Build and push new image with sequential image tagging, e.g. 'ror-tutorial_123'
# Build and push new image with sequential image tagging, e.g. 'tutorial-app:1', then 'tutorial-app:2', etc.
cpl build-image -a tutorial-app

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

# 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 tutorial-app --image latest

# Pomote latest image to app
# Pomote latest image to app after migrations run
cpl deploy-image -a tutorial-app
```

If you needed to push a new image with a specific commit SHA, you can run the following command:

```sh
# Build and push with sequential image tagging and commit SHA, e.g. 'tutorial-app:123_ABCD'
cpl build-image -a tutorial-app --commit ABCD
```

## Other notes

### `entrypoint.sh`
Expand Down
36 changes: 36 additions & 0 deletions .controlplane/templates/daily-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
kind: workload
name: daily-task
spec:
# https://docs.controlplane.com/reference/workload#cron-configuration
type: cron
job:
activeDeadlineSeconds: 3600
concurrencyPolicy: Forbid
historyLimit: 5
restartPolicy: Never
# daily. See cron docs
schedule: 0 0 * * *
containers:
- name: daily-task
cpu: 50m
memory: 256Mi
args:
- bundle
- exec
- rails
- db:reset
env:
- name: DISABLE_DATABASE_ENVIRONMENT_CHECK #To allow db:reset in production environment
value: "1"
inheritEnv: true
image: "/org/APP_ORG/image/APP_IMAGE"
defaultOptions:
autoscaling:
minScale: 1
maxScale: 1
capacityAI: false
firewallConfig:
external:
outboundAllowCIDR:
- 0.0.0.0/0
identityLink: /org/APP_ORG/gvc/APP_GVC/identity/postgres-poc-identity
2 changes: 1 addition & 1 deletion .controlplane/templates/gvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
# Password does not matter because host postgres.APP_GVC.cpln.local can only be accessed
# locally within CPLN GVC, and postgres running on a CPLN workload is something only for a
# test app that lacks persistence.
value: 'postgres://postgres:password123@postgres.APP_GVC.cpln.local:5432/APP_GVC'
value: 'postgres://the_user:the_password@postgres.APP_GVC.cpln.local:5432/APP_GVC'
- name: RAILS_ENV
value: production
- name: NODE_ENV
Expand Down
Loading

0 comments on commit 94d1179

Please sign in to comment.