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

🐳 docker image and deploy script #84

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this getting in the way? Seems like removing it opens up a new risk of incompatibility between the Capistrano version and our config

Copy link
Contributor Author

@mrharpo mrharpo May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added with e75758b

Upgrades to ruby3.2, capistrano 3.18

Seems to be working fine with the upgraded capistrano version, so I'm fine continuing with the latest for now, until it becomes a problem, when we can lock it.


# '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
41 changes: 41 additions & 0 deletions deployer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
###
# Command line tool for managing AAPB and OpenVault deployments
###
from os.path import realpath
from subprocess import PIPE, STDOUT
from subprocess import run as sub_run

import click

GITHUB_URL = 'https://github.com/WGBH-MLA/'
DOCKER_IMAGE = 'ghcr.io/wgbh-mla/openvault3_deploy:pr-84'


def run_interactive(cmd: str):
"""Run a shell command in an interactive terminal"""
return sub_run(cmd, shell=True, capture_output=True, check=True).stdout.decode()


@click.command()
@click.argument(
"context",
required=True,
type=click.Choice(["aapb", "aapb-demo", "openvault", "openvault-demo"]),
)
@click.argument(
"branch",
required=True,
)
def deploy(context, branch):
"""Deploy AAPB or OpenVault instance"""

click.echo(f"Deploying: { context }")
click.echo(f"Branch: { branch }")
cmd = f"""docker run -it -v {realpath('')}:/root/ {DOCKER_IMAGE}"""

sub_run(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrharpo how does context and branch inform the docker run command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about this file. This was a secondary attempt after the ./deploy script, which is what I've been using to deploy things.

Not sure why I would prefer this over the env var approach. We can probably delete this file, since the regular bash version is sufficient.



if __name__ == "__main__":
deploy()