Skip to content

Commit 0a3a1e0

Browse files
committed
WIP2
1 parent 8ac169d commit 0a3a1e0

File tree

15 files changed

+217
-142
lines changed

15 files changed

+217
-142
lines changed

.controlplane/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN bundle config set without 'development test' && \
1313
bundle config set with 'staging production' && \
1414
bundle install --jobs=3 --retry=3
1515

16-
COPY package.json .
16+
COPY package.json yarn.lock .
1717
RUN yarn install
1818

1919
COPY Gemfile* config.ru Rakefile babel.config.js ./
@@ -29,7 +29,7 @@ ENV RAILS_ENV=production
2929
ENV NODE_ENV=production
3030
ENV SECRET_KEY_BASE=123
3131

32-
RUN rake react_on_rails:locale && rake assets:precompile
32+
RUN rails react_on_rails:locale && rails assets:precompile
3333

3434
COPY .controlplane/entrypoint.sh ./
3535

.controlplane/build

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
SCRIPT_PATH=$(dirname $(realpath $0))
4+
export $(cat $SCRIPT_PATH/env_defaults | grep "^[^#]" | xargs)
5+
6+
# VERSION=$(date +%s)
7+
VERSION=latest
8+
IMAGE=$CPLN_GVC:${VERSION}
9+
10+
cpln image build \
11+
--name ${IMAGE} \
12+
--dockerfile "$SCRIPT_PATH/Dockerfile" \
13+
--dir .. \
14+
--push
15+
16+
# NOTE: atm, updating only app container with default workload name
17+
cpln workload update ${CPLN_APP_WORKLOAD} \
18+
--set spec.containers.${CPLN_APP_WORKLOAD}.image=/org/${CPLN_ORG}/image/${IMAGE} \
19+
--gvc ${CPLN_GVC}
20+
21+
if [ "$VERSION" == "latest" ]; then
22+
cpln workload force-redeployment ${CPLN_APP_WORKLOAD} --gvc ${CPLN_GVC}
23+
fi

.controlplane/build.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

.controlplane/env_defaults

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
CPLN_ORG=shakacode-staging
4+
5+
# default location
6+
CPLN_LOCATION=aws-us-east-2
7+
8+
# default gvc (default app name)
9+
CPLN_GVC=ror-tutorial
10+
11+
# main workload name
12+
CPLN_APP_WORKLOAD=rails

.controlplane/readme.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Some notes for furhter editing...
2+
3+
Initial steps:
4+
- fill `env_defaults`
5+
- run `./setup gvc postgres redis rails` to setup infrastructure
6+
- run `./build` to build and push latest image
7+
8+
env_defaults:
9+
- need to fill values before any execution of other commands
10+
11+
setup:
12+
- use to apply yaml templates for the app (and substitute envs in them)
13+
- templates are in `.controlplane/templates/...`
14+
- can apply single or multiple templates by name - e.g. `./setup gvc postgres redis`
15+
16+
build:
17+
- builds CPLN's Dockerfile and pushes it to CPLN repo
18+
- image name is suffixed by ':latest' for simplicity, no versioning
19+
- force restart workload after build
20+
21+
entrypoint.sh:
22+
- waits for postgres and redis to be available
23+
- runs `rails db:prepare` to create&seed or migrate database
24+
25+
run:
26+
- analogue of `heroku run` one-off dynos
27+
- creates a clone of app workload, connects to it, executes whatever and deletes workload
28+
- opens interactive shell when called w/o args, e.g.: `./run`
29+
- executes provided command and exists when called with args, e.g.: `./run rails db:migrate:status`
30+
- limitation: atm, there is no way to exectute command with args from `cpln` cli, so it uses some scripting workarounds
31+
- limitation: when called as `./run rails c` it will not open interactive shell, but will execute command and timeout. To open as interactive, do 1) `./run` to start bash interactive shell 2) type `rails c` manually

.controlplane/run

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
SCRIPT_PATH=$(dirname $(realpath $0))
4+
export $(cat $SCRIPT_PATH/env_defaults | grep "^[^#]" | xargs)
5+
6+
ONEOFF_NAME=$CPLN_APP_WORKLOAD$(date +%s)
7+
8+
function finish {
9+
# TODO: check if workload exists before deleting
10+
echo "- Deleting workload"
11+
cpln workload delete $ONEOFF_NAME --gvc $CPLN_GVC 2> /dev/null
12+
}
13+
trap finish EXIT
14+
trap finish ERR
15+
16+
echo "- Cloning workload"
17+
cpln workload clone $CPLN_APP_WORKLOAD --name $ONEOFF_NAME --gvc $CPLN_GVC > /dev/null
18+
19+
echo "- Wait for replica to be running"
20+
until cpln workload get-replicas $ONEOFF_NAME --location $CPLN_LOCATION --gvc $CPLN_GVC 2> /dev/null | grep -q $ONEOFF_NAME; do
21+
echo "waiting..."
22+
sleep 1
23+
done
24+
25+
if [ -z "$1" ]; then
26+
echo "- Interactive replica ready, connecting"
27+
28+
cpln workload connect $ONEOFF_NAME --gvc $CPLN_GVC --location $CPLN_LOCATION
29+
else
30+
echo "- Non-interactive replica ready, executing command"
31+
32+
expect <<EOF
33+
set timeout 600
34+
spawn -noecho cpln workload connect $ONEOFF_NAME --gvc $CPLN_GVC --location $CPLN_LOCATION
35+
expect "root@$ONEOFF_NAME-"
36+
send "$@\n"
37+
expect "root@$ONEOFF_NAME-"
38+
EOF
39+
40+
echo
41+
fi

.controlplane/run.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

.controlplane/setup

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
SCRIPT_PATH=$(dirname $(realpath $0))
4+
export $(cat $SCRIPT_PATH/env_defaults | grep "^[^#]" | xargs)
5+
6+
IMAGE=$CPLN_GVC:latest
7+
8+
for arg in "$@"; do
9+
TEMPLATE="$SCRIPT_PATH/templates/$arg.yaml"
10+
11+
if [ -f "$TEMPLATE" ]; then
12+
cat "$TEMPLATE" |
13+
sed "s/APP_GVC/$CPLN_GVC/" |
14+
sed "s/APP_LOCATION/$CPLN_LOCATION/" |
15+
sed "s/APP_ORG/$CPLN_ORG/" |
16+
sed "s/APP_IMAGE/$IMAGE/" |
17+
cpln apply --gvc $CPLN_GVC --file -
18+
else
19+
echo "Can't find template for '$arg' at $TEMPLATE"
20+
exit -1
21+
fi
22+
done

.controlplane/setup.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

.controlplane/setup.yaml

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)