From fca1a2acc9226285542f01d5ba2876c6ea34f44b Mon Sep 17 00:00:00 2001 From: "Timothy J. Aveni" Date: Fri, 8 Sep 2023 09:31:35 -0700 Subject: [PATCH 1/2] Dockerize heroku-apps script --- scripts/heroku-apps/Dockerfile | 12 ++++++++ scripts/heroku-apps/Gemfile | 2 ++ scripts/heroku-apps/README.md | 28 +++++++++++++++++++ .../{heroku-apps => heroku-apps.rb} | 0 4 files changed, 42 insertions(+) create mode 100644 scripts/heroku-apps/Dockerfile rename scripts/heroku-apps/{heroku-apps => heroku-apps.rb} (100%) diff --git a/scripts/heroku-apps/Dockerfile b/scripts/heroku-apps/Dockerfile new file mode 100644 index 0000000..bf73d74 --- /dev/null +++ b/scripts/heroku-apps/Dockerfile @@ -0,0 +1,12 @@ +FROM ruby:2.7.7-bullseye + +WORKDIR /app + +COPY ["Gemfile", "/app/Gemfile"] +COPY ["Gemfile.lock", "/app/Gemfile.lock"] + +run bundle install + +COPY ["heroku-apps.rb", "/app/heroku-apps.rb"] + +ENTRYPOINT ["ruby", "heroku-apps.rb"] diff --git a/scripts/heroku-apps/Gemfile b/scripts/heroku-apps/Gemfile index 2e1cf7c..50d0069 100644 --- a/scripts/heroku-apps/Gemfile +++ b/scripts/heroku-apps/Gemfile @@ -1,3 +1,5 @@ +source 'https://rubygems.org' + ruby '< 3.0' gem 'platform-api' diff --git a/scripts/heroku-apps/README.md b/scripts/heroku-apps/README.md index 488e1cc..8307f07 100644 --- a/scripts/heroku-apps/README.md +++ b/scripts/heroku-apps/README.md @@ -72,3 +72,31 @@ Deletes all apps beginning with the common app prefix. Remove from the Heroku team all team members whose emails appear in the CSV file. (This allows for leaving team members who are course staff, e.g.) + +## Running with Docker + +Instead of switching to the right Ruby version manually, you can also build and use a Docker image to run this script. + +### To build + +To create the Docker image, clone this repository, cd into the script directory, and run: + +``` +docker build -t saasbook-script-heroku-apps . +``` + +### To run + +Run the following, replacing the appropriate parameters. + +If using Windows, you may need to change the `` `pwd` `` mount. Files in the working directory will be available to the container at `/app/files`, e.g. `-c /app/files/team-info.csv`. + +``` +docker run \ + -it \ + -v `pwd`:/app/files \ + -e HEROKU_API_KEY=[your_key] \ + saasbook-script-heroku-apps \ + [args] \ + [command] +``` diff --git a/scripts/heroku-apps/heroku-apps b/scripts/heroku-apps/heroku-apps.rb similarity index 100% rename from scripts/heroku-apps/heroku-apps rename to scripts/heroku-apps/heroku-apps.rb From 55f2656c128b4d8c11b136676492ce882a826000 Mon Sep 17 00:00:00 2001 From: "Timothy J. Aveni" Date: Fri, 8 Sep 2023 09:36:18 -0700 Subject: [PATCH 2/2] Auto-hyphenate prefix in heroku apps script --- scripts/heroku-apps/heroku-apps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/heroku-apps/heroku-apps.rb b/scripts/heroku-apps/heroku-apps.rb index 4ed4a73..a0c5efe 100755 --- a/scripts/heroku-apps/heroku-apps.rb +++ b/scripts/heroku-apps/heroku-apps.rb @@ -20,7 +20,7 @@ def main() h.heroku_team = team end opt.on('-pPREFIX', '--prefix=PREFIX', 'App name prefix, eg "fa23" gives apps "fa23-01", "fa23-02", etc.') do |pfx| - h.app_prefix = pfx + h.app_prefix = if pfx.end_with? '-' then pfx else "#{pfx}-" end end opt.on('-xEMAILS' '--extra-users=EMAILS', 'Comma-separated list of emails that should also be collaborators on apps') do |extra_users| h.extra_users = extra_users.split(/,/)