rails-push-and-migrate 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80f769a120b772970dec4d945595d01372cc8938
4
+ data.tar.gz: 326419190fd6ce55a9d63d2466753b76df2f3391
5
+ SHA512:
6
+ metadata.gz: 2fde1ee5eca35e7ea6fafb1a2fe88c2f4e124cc211fa29aa7868e766209668161d232b270a86f594c83a76efa19d7bcce8e71aa9eedbd63522bc9e85e8ad12e7
7
+ data.tar.gz: a7182ad7543151abdc2ad3fdae5c0895935c829c2deebf84dbc4c350d60df16f9d8538b55af24d81657fca78f042ac9441530a17de6a4c5828f1bf45bcecbaf7
@@ -0,0 +1,8 @@
1
+ profiles/
2
+ .capistrano/
3
+ TODO
4
+ tags
5
+ .s3config
6
+ tmp/
7
+ .redislab.yml
8
+ chrome_debug.log
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails-push-and-migrate (0.0.1)
5
+ thor
6
+
7
+ GEM
8
+ specs:
9
+ byebug (5.0.0)
10
+ columnize (= 0.9.0)
11
+ columnize (0.9.0)
12
+ diff-lcs (1.3)
13
+ rspec (3.5.0)
14
+ rspec-core (~> 3.5.0)
15
+ rspec-expectations (~> 3.5.0)
16
+ rspec-mocks (~> 3.5.0)
17
+ rspec-core (3.5.4)
18
+ rspec-support (~> 3.5.0)
19
+ rspec-expectations (3.5.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.5.0)
22
+ rspec-mocks (3.5.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.5.0)
25
+ rspec-support (3.5.0)
26
+ thor (0.19.4)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ byebug
33
+ rails-push-and-migrate!
34
+ rspec
35
+
36
+ BUNDLED WITH
37
+ 1.12.3
@@ -0,0 +1,11 @@
1
+ rails-push-and-migrate
2
+ ==========
3
+
4
+ Help you to quickly push and migrate your app from ci server
5
+ Ready with 2 flavors: heroku and dokku
6
+
7
+ For heroku:
8
+ rapam heroku your-heroku-app your-branch
9
+
10
+ For dokku:
11
+ rapam dokku ssh://your-dokku:dokku your-branch
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env bash
2
+ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3
+ export DOKKU_PORT=${DOKKU_PORT:=22}
4
+ export DOKKU_HOST=${DOKKU_HOST:=}
5
+
6
+ fn-random-number() {
7
+ [[ -n "$1" ]] && RANGE="$1"
8
+ if [[ -n "$RANGE" ]]; then
9
+ number=$RANDOM
10
+ let "number %= $RANGE"
11
+ else
12
+ number=$RANDOM
13
+ fi
14
+ echo $number
15
+ }
16
+
17
+ fn-random-name() {
18
+ local NUM1 NUM2 NUM3 UPPER_APPNAME lower_appname
19
+ local MOVES=(ABLE ABNORMA AGAIN AIREXPL ANG ANGER ASAIL ATTACK AURORA AWL BAN BAND BARE BEAT BEATED BELLY BIND BITE BLOC BLOOD BODY BOOK BREATH BUMP CAST CHAM CLAMP CLAP CLAW CLEAR CLI CLIP CLOUD CONTRO CONVY COOLHIT CRASH CRY CUT DESCRI D-FIGHT DIG DITCH DIV DOZ DRE DUL DU-PIN DYE EARTH EDU EG-BOMB EGG ELEGY ELE-HIT EMBODY EMPLI ENGL ERUPT EVENS EXPLOR EYES FALL FAST F-CAR F-DANCE FEARS F-FIGHT FIGHT FIR FIRE FIREHIT FLAME FLAP FLASH FLEW FORCE FRA FREEZE FROG G-BIRD GENKISS GIFT G-KISS G-MOUSE GRADE GROW HAMMER HARD HAT HATE H-BOMB HELL-R HEMP HINT HIT HU HUNT HYPNOSI INHA IRO IRONBAR IR-WING J-GUN KEE KICK KNIF KNIFE KNOCK LEVEL LIGH LIGHHIT LIGHT LIVE L-WALL MAD MAJUS MEL MELO MESS MILK MIMI MISS MIXING MOVE MUD NI-BED NOISY NOONLI NULL N-WAVE PAT PEACE PIN PLAN PLANE POIS POL POWDE POWE POWER PRIZE PROTECT PROUD RAGE RECOR REFLAC REFREC REGR RELIV RENEW R-FIGHT RING RKICK ROCK ROUND RUS RUSH SAND SAW SCISSOR SCRA SCRIPT SEEN SERVER SHADOW SHELL SHINE SHO SIGHT SIN SMALL SMELT SMOK SNAKE SNO SNOW SOU SO-WAVE SPAR SPEC SPID S-PIN SPRA STAM STARE STEA STONE STORM STRU STRUG STUDEN SUBS SUCID SUN-LIG SUNRIS SUPLY S-WAVE TAILS TANGL TASTE TELLI THANK TONKICK TOOTH TORL TRAIN TRIKICK TUNGE VOLT WA-GUN WATCH WAVE W-BOMB WFALL WFING WHIP WHIRL WIND WOLF WOOD WOR YUJA)
20
+ local NAMES=(SEED GRASS FLOWE SHAD CABR SNAKE GOLD COW GUIKI PEDAL DELAN B-FLY BIDE KEYU FORK LAP PIGE PIJIA CAML LAT BIRD BABOO VIV ABOKE PIKAQ RYE SAN BREAD LIDEL LIDE PIP PIKEX ROK JUGEN PUD BUDE ZHIB GELU GRAS FLOW LAFUL ATH BALA CORN MOLUF DESP DAKED MIMI BOLUX KODA GELUD MONK SUMOY GEDI WENDI NILEM NILE NILEC KEZI YONGL HUDE WANLI GELI GUAIL MADAQ WUCI WUCI MUJEF JELLY SICIB GELU NELUO BOLI JIALE YED YEDE CLO SCARE AOCO DEDE DEDEI BAWU JIUG BADEB BADEB HOLE BALUX GES FANT QUAR YIHE SWAB SLIPP CLU DEPOS BILIY YUANO SOME NO YELA EMPT ZECUN XIAHE BOLEL DEJI MACID XIHON XITO LUCK MENJI GELU DECI XIDE DASAJ DONGN RICUL MINXI BALIY ZENDA LUZEL HELE5 0FENB KAIL JIAND CARP JINDE LAPU MUDE YIFU LINLI SANDI HUSI JINC OUMU OUMUX CAP KUIZA PUD TIAO FRMAN CLAU SPARK DRAGO BOLIU GUAIL MIYOU MIY QIAOK BEIL MUKEI RIDED MADAM BAGEP CROC ALIGE OUDAL OUD DADA HEHE YEDEA NUXI NUXIN ROUY ALIAD STICK QIANG LAAND PIQI PI PUPI DEKE DEKEJ NADI NADIO MALI PEA ELECT FLOWE MAL MALI HUSHU NILEE YUZI POPOZ DUZI HEBA XIAN SHAN YEYEA WUY LUO KEFE HULA CROW YADEH MOW ANNAN SUONI KYLI HULU HUDEL YEHE GULAE YEHE BLU GELAN BOAT NIP POIT HELAK XINL BEAR LINB MAGEH MAGEJ WULI YIDE RIVE FISH AOGU DELIE MANTE KONMU DELU HELU HUAN HUMA DONGF JINCA HEDE DEFU LIBY JIAPA MEJI HELE BUHU MILK HABI THUN GARD DON YANGQ SANAQ BANQ LUJ PHIX SIEI EGG)
21
+
22
+ NUM1=$(fn-random-number ${#MOVES[@]})
23
+ NUM2=$(fn-random-number ${#MOVES[@]})
24
+ NUM3=$(fn-random-number ${#NAMES[@]})
25
+
26
+ UPPER_APPNAME="${MOVES[${NUM1}]}-${MOVES[${NUM2}]}-${NAMES[${NUM3}]}"
27
+
28
+ [[ "$BASH_VERSION" =~ 4.* ]] && lower_appname=${UPPER_APPNAME,,}
29
+ [[ -z "$lower_appname" ]] && lower_appname=$(echo "$UPPER_APPNAME" | tr '[:upper:]' '[:lower:]')
30
+ echo "$lower_appname"
31
+ }
32
+
33
+ fn-client-help-msg() {
34
+ echo "==> Configure the DOKKU_HOST environment variable or run $0 from a repository with a git remote named dokku" 1>&2
35
+ echo "--> i.e. git remote add dokku dokku@<dokku-host>:<app-name>" 1>&2
36
+ exit 20 # exit with specific status. only used in units tests for now
37
+ }
38
+
39
+ fn-is-git-repo() {
40
+ git rev-parse &>/dev/null
41
+ }
42
+
43
+ fn-has-dokku-remote() {
44
+ git remote show | grep -E "^${DOKKU_GIT_REMOTE}\s"
45
+ }
46
+
47
+ fn-dokku-host() {
48
+ declare DOKKU_GIT_REMOTE="$1" DOKKU_HOST="$2"
49
+
50
+ if [[ -z "$DOKKU_HOST" ]]; then
51
+ if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then
52
+ DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null || true)
53
+ fi
54
+ fi
55
+
56
+ if [[ -z "$DOKKU_HOST" ]]; then
57
+ fn-client-help-msg
58
+ fi
59
+
60
+ echo "$DOKKU_HOST"
61
+ }
62
+
63
+ main() {
64
+ declare CMD="$1" APP_ARG="$2"
65
+ local APP="" DOKKU_GIT_REMOTE="dokku" DOKKU_REMOTE_HOST=""
66
+ local cmd_set=false next_index=1 skip=false args=("$@")
67
+
68
+ for arg in "$@"; do
69
+ if [[ "$skip" == "true" ]]; then
70
+ next_index=$(( next_index + 1 ))
71
+ skip=false
72
+ continue
73
+ fi
74
+
75
+ if [[ "$arg" == "--app" ]]; then
76
+ APP=${args[$next_index]}
77
+ skip=true
78
+ shift 2
79
+ elif [[ "$arg" == "--remote" ]]; then
80
+ DOKKU_GIT_REMOTE=${args[$next_index]}
81
+ skip=true
82
+ shift 2
83
+ elif [[ "$arg" =~ ^--.* ]]; then
84
+ [[ "$cmd_set" == "true" ]] && APP_ARG="$arg" && break
85
+ [[ "$arg" == "--trace" ]] && export DOKKU_TRACE=1 && set -x
86
+ else
87
+ if [[ "$cmd_set" == "true" ]]; then
88
+ APP_ARG="$arg"
89
+ break
90
+ else
91
+ CMD="$arg"
92
+ cmd_set=true
93
+ fi
94
+ fi
95
+ next_index=$(( next_index + 1 ))
96
+ done
97
+
98
+ DOKKU_REMOTE_HOST="$(fn-dokku-host "$DOKKU_GIT_REMOTE" "$DOKKU_HOST")"
99
+
100
+ if [[ -z "$APP" ]]; then
101
+ if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then
102
+ set +e
103
+ APP=$(git remote -v 2>/dev/null | grep -Ei "dokku@$DOKKU_REMOTE_HOST" | head -n 1 | cut -f2 -d'@' | cut -f1 -d' ' | cut -f2 -d':' 2>/dev/null)
104
+ set -e
105
+ else
106
+ echo "This is not a git repository"
107
+ fi
108
+ fi
109
+
110
+ case "$CMD" in
111
+ apps:create)
112
+ if [[ -z "$APP_ARG" ]]; then
113
+ APP=$(fn-random-name)
114
+ counter=0
115
+ while ssh -p "$DOKKU_PORT" "dokku@$DOKKU_REMOTE_HOST" apps 2>/dev/null| grep -q "$APP"; do
116
+ if [[ $counter -ge 100 ]]; then
117
+ echo "Error: could not reasonably generate a new app name. try cleaning up some apps..."
118
+ ssh -p "$DOKKU_PORT" "dokku@$DOKKU_REMOTE_HOST" apps
119
+ exit 1
120
+ else
121
+ APP=$(random_name)
122
+ counter=$((counter+1))
123
+ fi
124
+ done
125
+ else
126
+ APP="$APP_ARG"
127
+ fi
128
+ if git remote add "$DOKKU_GIT_REMOTE" "dokku@$DOKKU_REMOTE_HOST:$APP"; then
129
+ echo "-----> Dokku remote added at ${DOKKU_REMOTE_HOST} called ${DOKKU_GIT_REMOTE}"
130
+ echo "-----> Application name is ${APP}"
131
+ else
132
+ echo "! Dokku remote not added! Do you already have a dokku remote?"
133
+ return
134
+ fi
135
+ ;;
136
+ apps:destroy)
137
+ fn-is-git-repo && fn-has-dokku-remote && git remote remove "$DOKKU_GIT_REMOTE"
138
+ ;;
139
+ esac
140
+
141
+ [[ " apps certs help ls nginx shell storage trace version " == *" $CMD "* ]] && unset APP
142
+ [[ " certs:chain domains:add-global domains:remove-global domains:set-global ps:rebuildall ps:restartall ps:restore " == *" $CMD "* ]] && unset APP
143
+ [[ "$CMD" =~ events*|plugin*|ssh-keys* ]] && unset APP
144
+ [[ -n "$APP_ARG" ]] && [[ "$APP_ARG" == "--global" ]] && unset APP
145
+ [[ -n "$@" ]] && [[ -n "$APP" ]] && app_arg="--app $APP"
146
+ # echo "ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_REMOTE_HOST -- $app_arg $@"
147
+ # shellcheck disable=SC2068,SC2086
148
+ ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_REMOTE_HOST -- $app_arg $@
149
+ }
150
+
151
+ if [[ "$0" == "dokku" ]] || [[ "$0" == *dokku_client.sh ]] || [[ "$0" == $(which dokku) ]]; then
152
+ main "$@"
153
+ exit $?
154
+ fi
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'rails-push-and-migrate'
5
+
6
+ class RapamCLI < Thor
7
+ desc "heroku APP BRANCH", "Deploy to heroku APP using BRANCH (default master)"
8
+ def heroku(app, branch = "master")
9
+ RailsPushAndMigrate::Heroku.new(app, branch).run
10
+ end
11
+
12
+ desc "dokku REMOTE BRANCH", "Deploy to dokku REMOTE using BRANCH (default master)"
13
+ def dokku(remote, branch = "master")
14
+ RailsPushAndMigrate::Dokku.new(remote, branch).run
15
+ end
16
+ end
17
+
18
+ RapamCLI.start
@@ -0,0 +1,7 @@
1
+ module RailsPushAndMigrate
2
+ end
3
+
4
+ require 'rails-push-and-migrate/version'
5
+ require 'rails-push-and-migrate/base'
6
+ require 'rails-push-and-migrate/heroku'
7
+ require 'rails-push-and-migrate/dokku'
@@ -0,0 +1,62 @@
1
+ module RailsPushAndMigrate
2
+ class Base
3
+ attr_accessor :branch, :remote
4
+ def initialize(remote, branch)
5
+ @branch = branch
6
+ @remote = remote
7
+ end
8
+
9
+ def remote_branch
10
+ "master"
11
+ end
12
+
13
+ def diff_files
14
+ @diff_files ||= (
15
+ with_named_repo do |repo_name|
16
+ puts "Execute git diff #{repo_name}/#{remote_branch}..#{branch} --name-only"
17
+ `git diff #{repo_name}/#{remote_branch}..#{branch} --name-only`.split("\n")
18
+ end
19
+ )
20
+ end
21
+
22
+ def with_named_repo
23
+ system "git remote add auto-push-repo #{remote}"
24
+ system "git remote update auto-push-repo"
25
+ result = yield "auto-push-repo"
26
+ system "git remote rm auto-push-repo"
27
+ result
28
+ end
29
+
30
+ def has_migration?
31
+ diff_files.include?("db/schema.rb")
32
+ end
33
+
34
+ def assets_changed?
35
+ diff_files.select {|f| f.include? "app/assets"}.any?
36
+ end
37
+
38
+ def git_push_cmd
39
+ "git push #{remote} #{branch}:#{remote_branch}"
40
+ end
41
+
42
+ def migrate_cmd
43
+ raise NotImplementedError
44
+ end
45
+
46
+ def print_and_execute(cmd)
47
+ puts "Executing #{cmd}"
48
+ system cmd
49
+ end
50
+
51
+ def print_and_execute!(cmd)
52
+ unless print_and_execute(cmd)
53
+ raise "Failed to execute #{cmd}"
54
+ end
55
+ end
56
+
57
+ def run
58
+ print_and_execute! git_push_cmd
59
+ print_and_execute!(migrate_cmd) if has_migration?
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'base'
2
+
3
+ module RailsPushAndMigrate
4
+ class Dokku < Base
5
+ def dokku_path
6
+ File.expand_path("../../../bin/dokku_client.sh", __FILE__)
7
+ end
8
+
9
+ def migrate_cmd
10
+ cmds = [
11
+ "git remote add dokku #{remote}",
12
+ "#{dokku_path} run rake db:migrate"
13
+ ].join(" && ")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'base'
2
+
3
+ module RailsPushAndMigrate
4
+ class Heroku < Base
5
+ attr_accessor :app
6
+ def initialize(app, branch)
7
+ @branch = branch
8
+ @app = app
9
+ end
10
+
11
+ def remote
12
+ "https://git.heroku.com/#{app}.git"
13
+ end
14
+
15
+ def migrate_cmd
16
+ "heroku run rake db:migrate -a #{app}"
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ module RailsPushAndMigrate
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails-push-and-migrate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-push-and-migrate"
8
+ spec.version = RailsPushAndMigrate::VERSION
9
+ spec.authors = ["Phuong Nguyen"]
10
+ spec.email = ["phuongnd08@gmail.com"]
11
+ spec.summary = %q{Library to help push and then run migration for rails if necessary}
12
+ spec.description = %q{Library to help push and then run migration for rails if necessary}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_development_dependency "byebug"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-push-and-migrate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Phuong Nguyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Library to help push and then run migration for rails if necessary
56
+ email:
57
+ - phuongnd08@gmail.com
58
+ executables:
59
+ - dokku_client.sh
60
+ - rapam
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".ruby-version"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.md
69
+ - bin/dokku_client.sh
70
+ - bin/rapam
71
+ - lib/rails-push-and-migrate.rb
72
+ - lib/rails-push-and-migrate/base.rb
73
+ - lib/rails-push-and-migrate/dokku.rb
74
+ - lib/rails-push-and-migrate/heroku.rb
75
+ - lib/rails-push-and-migrate/version.rb
76
+ - rails-push-and-migrate.gemspec
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Library to help push and then run migration for rails if necessary
101
+ test_files: []