Skip to content

Commit

Permalink
🐳 docker image and deploy script (#84)
Browse files Browse the repository at this point in the history
* Working dockerfile for environment
* Ignore keys
* Basic CLI for deployments
* Pass envs with -e ENV format
* Add help text for deploy script
* Adds CD auto building action
  • Loading branch information
mrharpo authored Dec 3, 2024
1 parent fbf2b71 commit 8ff0c60
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 24 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 🪂 Deploy

on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types: [published, edited, prereleased]
workflow_dispatch:

jobs:
build:
name: 🔨 Build and deploy docker image
uses: WGBH-MLA/.github/.github/workflows/build.yml@main
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.capistrano
stuff
.DS_Store
.DS_Store
*.pem
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ruby:3.1
WORKDIR /root

COPY Gemfile Gemfile.lock ./

RUN bundle install

CMD bundle exec cap aws deploy
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'capistrano', '~> 3.3.5'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-passenger'
Expand Down
34 changes: 18 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
GEM
remote: https://rubygems.org/
specs:
capistrano (3.3.5)
capistrano-stats (~> 1.1.0)
airbrussh (1.5.0)
sshkit (>= 1.6.1, != 1.7.0)
capistrano (3.18.0)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
capistrano-bundler (1.1.4)
sshkit (>= 1.9.0)
capistrano-bundler (2.1.0)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-passenger (0.2.0)
capistrano-passenger (0.2.1)
capistrano (~> 3.0)
capistrano-rails (1.1.6)
capistrano-rails (1.6.3)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-stats (1.1.1)
i18n (0.7.0)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.0.2)
rake (10.5.0)
sshkit (1.21.0)
capistrano-bundler (>= 1.1, < 3)
concurrent-ruby (1.2.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-ssh (7.2.0)
rake (13.1.0)
sshkit (1.21.6)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)

PLATFORMS
ruby

DEPENDENCIES
capistrano (~> 3.3.5)
capistrano
capistrano-bundler
capistrano-passenger
capistrano-rails
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Before deploying, ensure the following:
From the root directory of your cloned repo, run the capistrano command for the `aws` stage. This step could take a few minutes.

```
bundle exec cap aws deploy OV_HOST=1.2.3.4 OV_SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem
bundle exec cap aws deploy SSH_HOST=1.2.3.4 SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem
```

If there were no errors, then you should be able to see the Open Vault website running in a web browser, at the target host's IP address.
Expand All @@ -66,7 +66,7 @@ If there were errors, or if you can't see the running website, then please [file
To ingest into a server which is already up and running.

```
bundle exec cap aws ingest OV_HOST=1.2.3.4 OV_SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem OV_PBCORE=fm-export.zip
bundle exec cap aws ingest SSH_HOST=1.2.3.4 SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem OV_PBCORE=fm-export.zip
```

## Solr index
Expand All @@ -84,7 +84,7 @@ In special circumstances however, you may want to replace an existing Solr repos
operation cannot be undone. Normally you shouldn't have to do this.

```
bundle exec cap aws jetty:uninstall OV_HOST=1.2.3.4 OV_SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem
bundle exec cap aws jetty:uninstall SSH_HOST=1.2.3.4 SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem
```

#### Install a new Solr index
Expand All @@ -95,7 +95,7 @@ have to do this, but you may if you removed your existing Solr index using the
steps above.

```
bundle exec cap aws jetty:install OV_HOST=1.2.3.4 OV_SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem
bundle exec cap aws jetty:install SSH_HOST=1.2.3.4 SSH_KEY=~/.ssh/xyz.wgbh-mla.org.pem
```


Expand Down
2 changes: 0 additions & 2 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# For more options, see http://capistranorb.com/documentation/getting-started/configuration/#
# config valid only for current version of Capistrano
lock '3.3.5'

# 'openvault' or 'AAPB'
set :application, ENV['APP_NAME']
Expand Down
42 changes: 42 additions & 0 deletions deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
HELP="deploy script for AAPB and OpenVault3 \n\n
USAGE \n
./deploy COMMAND [ARGS] \n\n
COMMANDS \n
b | build \t\t Build the deployer image \n
deploy \t\t Run the deployer with environment vars passed in \n
h | help \t\t Show this message \n\n
Requires a local SSH_KEY. \n
All environment variables must be exported in the current session, \n
or passed in on the command line."

IMAGE_NAME=aapb-deploy

VOLUME_MOUNT="-v `pwd`:/root/"
DOCKER_ARGS="docker run -it $VOLUME_MOUNT"


if [ $1 = "build" -o $1 = "b" ]; then
shift
# build the docker image
docker build -t $IMAGE_NAME . "$@"

elif [ $1 = "deploy" ]; then
shift
# deploy AAPB or OpenVault
$DOCKER_ARGS \
-e BRANCH \
-e APP_NAME \
-e REPO_URL \
-e SSH_HOST \
-e SSH_KEY \
$IMAGE_NAME "$@"

else
echo "command not recognized: $@"
echo -e $HELP
fi

0 comments on commit 8ff0c60

Please sign in to comment.