mina 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67b4c29c103a5a281be9c76e900b060da586a293
4
- data.tar.gz: 9580cbbd7dd3c27313b35a7457a9578e5fc87e32
3
+ metadata.gz: 4f9c9b88688f477223d4b4577352b3441a198af7
4
+ data.tar.gz: c7d171c49d110f4c2ee46807f55984a85e26cb1c
5
5
  SHA512:
6
- metadata.gz: 8fe517b01c18aaf896fb487dae32d7ac3f5ed1c4524ede2847e76a1f92c5bb879050ded1a53a91e9df7a58e15c9e2bce489723398874e3fea9f4b1a824a61b00
7
- data.tar.gz: 22c0cfe800c09189c70970b3ae168df494ff6532ba0d381c9c11c00717e11135c16e4dbbc55e2e6ecae84ae439c4401c5b80c76653221c9ef00e7daff89d3524
6
+ metadata.gz: ae78879652cf2772c088ecbe03cd894ad1beaea25fc6d55a0cb077d7bc6fa5af6e086a2fc3a2cac0934aa21050181f5a3742865fdcf186cbe7d42705c30150f5
7
+ data.tar.gz: d194d278203c87d51c086dbdb6c4ad9fde980fb3fb268bb92283696b582b04760a6d43025b37c5fed6b40c10f0bdc42ebb2bd339264bb707ddc5d892fcf434b9
@@ -1,8 +1,7 @@
1
1
  # Change Log
2
2
 
3
- ## [Unreleased](https://github.com/mina-deploy/mina/tree/HEAD)
4
-
5
- [Full Changelog](https://github.com/mina-deploy/mina/compare/v1.0.6...HEAD)
3
+ ## [v1.0.7](https://github.com/mina-deploy/mina/tree/v1.0.7) (2017-09-08)
4
+ [Full Changelog](https://github.com/mina-deploy/mina/compare/v1.0.6...v1.0.7)
6
5
 
7
6
  **Closed issues:**
8
7
 
data/Readme.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Build Status](https://semaphoreci.com/api/v1/d4be4st/mina/branches/master/shields_badge.svg)](https://semaphoreci.com/d4be4st/mina)
6
6
  [![Gem Version](https://badge.fury.io/rb/mina.svg)](https://badge.fury.io/rb/mina)
7
7
 
8
- ![mina](https://assets.infinum.co/attachments/ad98b5e667facece8bb0b790f3cafe5bcb2dc469/store/limit/1000/1000/291724d19624f688957cebb5a0549abb6ea07113bdac11026ad2d5a6d29f/Mina_Icon.png)
8
+ ![mina](https://photos.infinum.co/store/5273935c5deeabda0e98c943db2a7ade)
9
9
 
10
10
  Really fast deployer and server automation tool.
11
11
 
@@ -51,4 +51,4 @@ Mina is maintained and sponsored by [Infinum](https://infinum.co).
51
51
 
52
52
  You can reach us on twitter [Stef](https://twitter.com/_Beast_) & [Infinum](https://twitter.com/infinumco)
53
53
 
54
- ![](https://assets.infinum.co/assets/brand-logo-9e079bfa1875e17c8c1f71d1fee49cf0.svg) © 2016 Infinum.
54
+ ![](https://assets.infinum.co/assets/brand-logo-9e079bfa1875e17c8c1f71d1fee49cf0.svg) © 2016 Infinum.
@@ -20,8 +20,10 @@ set :branch, 'master'
20
20
  # set :port, '30000' # SSH port number.
21
21
  # set :forward_agent, true # SSH forward_agent.
22
22
 
23
- # shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step.
24
- # set :shared_dirs, fetch(:shared_dirs, []).push('somedir')
23
+ # Shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step.
24
+ # Some plugins already add folders to shared_dirs like `mina/rails` add `public/assets`, `vendor/bundle` and many more
25
+ # run `mina -d` to see all folders and files already included in `shared_dirs` and `shared_files`
26
+ # set :shared_dirs, fetch(:shared_dirs, []).push('public/assets')
25
27
  # set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')
26
28
 
27
29
  # This task is the environment that is loaded for all remote run commands, such as
@@ -38,7 +40,7 @@ end
38
40
  # Put any custom commands you need to run at setup
39
41
  # All paths in `shared_dirs` and `shared_paths` will be created on their own.
40
42
  task :setup do
41
- # command %{rbenv install 2.3.0}
43
+ # command %{rbenv install 2.3.0 --skip-existing}
42
44
  end
43
45
 
44
46
  desc "Deploys the current version to the server."
@@ -1,5 +1,4 @@
1
- 3rd party modules
2
- ------
1
+ # 3rd party modules
3
2
 
4
3
  **Many are not updated to mina 1.x**
5
4
 
@@ -34,4 +33,4 @@
34
33
  * [mina-tail](https://github.com/modomoto/mina-tail)
35
34
  * [mina-unicorn](https://github.com/openteam/mina-unicorn)
36
35
  * [mina-whenever](https://github.com/mina-deploy/mina-whenever)
37
- * [mina-lock] (https://github.com/lorenzosinisi/mina-lock)
36
+ * [mina-lock](https://github.com/lorenzosinisi/mina-lock)
@@ -1,10 +1,13 @@
1
1
  # Mina Documentations
2
2
 
3
+ Mina is a tool that exstends rake (think ruby's make) in order to create bash scripts which are then run on your servers.
4
+
3
5
  * [Getting started](getting_started.md)
6
+ * [How Mina Works](how_mina_works.md)
4
7
  * [Migrating from 0.3.x to 1.0](migrating.md)
8
+ * [Default Plugins](default_plugins.md)
5
9
  * [Deploying](deploying.md)
6
10
  * [Writing your own tasks](writing_your_own_tasks.md)
7
- * [Command line options](command_line_options.md)
8
11
  * [FAQ](faq.md)
9
12
  * [Cookbook](cookbook.md)
10
13
  * [3rd party plugins](3rd_party_plugins.md)
@@ -1,7 +1,6 @@
1
- Cookbook
2
- --------------------
1
+ # Cookbook
3
2
 
4
- # Multi environment deploy
3
+ ## Multi environment deploy
5
4
 
6
5
  ``` ruby
7
6
  # deploy.rb
@@ -30,6 +29,38 @@ $ mina staging deploy
30
29
  $ mina production deploy
31
30
  ```
32
31
 
32
+ ## Copy `config/application.yml` to your server
33
33
 
34
+ ```
35
+ task :deploy do
36
+ run(:local) do
37
+ comamnd "scp config/application.yml #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:shared_path)}/config/application.yml"
38
+ end
39
+
40
+ deploy do
41
+ invoke ...
42
+ end
43
+ end
44
+ ```
45
+
46
+ ## Deploy plain HTML websites
47
+ ```
48
+ require 'mina/git'
49
+ require 'mina/deploy'
50
+ ...
51
+ desc "Deploys the current version to the server."
52
+ task :deploy do
53
+ deploy do
54
+ invoke :'git:clone'
55
+ invoke :'deploy:cleanup'
56
+
57
+ on :launch do
58
+ in_path(fetch(:current_path)) do
59
+ command %{npm install}
60
+ end
61
+ end
62
+ end
63
+ end
64
+ ```
34
65
  -------------------------------
35
66
  \* *feel free to add your own recipes*
@@ -0,0 +1,190 @@
1
+ # Default Plugins
2
+
3
+ `mina` comes with a variaty of plugins for you to use out of the box. As `mina` is primarely written in ruby and for rails, it has
4
+ ruby plugins, but it can be used to deploy any other application (static, js, php, etc)
5
+
6
+ To use a plugin you only need to require it in your `deploy.rb`. Most of the plugins come with a set of their
7
+ own variables which are usable, chengable and overwritable.
8
+
9
+ Example:
10
+
11
+ ``` ruby
12
+ require 'mina/rails'
13
+
14
+ set :rails_env, 'staging'
15
+ ```
16
+
17
+ You can also override a variable from command line like:
18
+
19
+ ``` sh
20
+ $ mina deploy rails_env=development
21
+ ```
22
+
23
+ ## Default
24
+
25
+ ``` ruby
26
+ require 'mina/default'
27
+ ```
28
+
29
+ ### Variables
30
+ ``` ruby
31
+ :repository #=> nil
32
+ :domain #=> nil
33
+ :port #=> 22
34
+ :deploy_to #=> nil
35
+ :execution_mode #=> :pretty ## Can be [:exec, :pretty, :pritner, :system]
36
+ ```
37
+
38
+ ### Execution mode
39
+ See [Execution mode](how_mina_works.md#execution-modes-runners)
40
+
41
+ ### Tasks
42
+ ``` ruby
43
+ local_environment #=> Task to be run before all local tasks
44
+ remote_environment #=> Task to be run before all remote tasks
45
+ ssh_keyscan_domain #=> Adds repository host to the known hosts
46
+ ssh_keyscan_repo #=> Adds domain to the known hosts
47
+ run #=> Runs a command on the server; Example: `$ mina 'run[rake db:migrate]'`
48
+ ssh #=> Open an ssh session to the server and cd to deploy_to folder
49
+ ```
50
+
51
+ ## Deploy
52
+ ``` ruby
53
+ require 'mina/deploy'
54
+ ```
55
+
56
+ loads:
57
+ - `mina/default`
58
+
59
+ ### Variables
60
+
61
+ ``` ruby
62
+ :releases_path #=> "#{fetch(:deploy_to)}/releases"
63
+ :shared_path #=> "#{fetch(:deploy_to)}/shared"
64
+ :current_path #=> "#{fetch(:deploy_to)}/current"
65
+ :lock_file #=> 'deploy.lock'
66
+ :deploy_script #=> 'data/deploy.sh.erb'
67
+ :keep_releases #=> 5
68
+ :version_scheme #=> :sequence ## Can be [:sequence, :datetime]
69
+ :shared_dirs #=> []
70
+ :shared_fiels #=> []
71
+ ```
72
+
73
+ ### Tasks
74
+ ``` ruby
75
+ # deploy:* tasks are not meant to be run outside `deploy do` block
76
+ deploy:force_unlock #=> Removes .force_unlock file
77
+ deploy:link_shared_paths #=> Link paths set in `:shared_dirs` and `:shared_files`
78
+ deploy:cleanup #=> Cleans up old releases
79
+
80
+ rollback #=> Rollbacks the latest release; does not rollback database
81
+ setup #=> Sets up the site
82
+ ```
83
+
84
+ #### Version scheme
85
+
86
+ `:version_scheme` variable sets the naming for your release folders.
87
+
88
+ ``` sh
89
+ # :sequence
90
+ .
91
+ ├── releases
92
+ │   ├── 87
93
+ │   ├── 88
94
+ │   ├── 89
95
+ │   ├── 90
96
+ │   ├── 91
97
+ │   └── 92
98
+
99
+ # :datetime
100
+ .
101
+ ├── releases
102
+ │   ├── 20170701123242
103
+ │   ├── 20170704131253
104
+ │   ├── 20170708032142
105
+ │   ├── 20170710082353
106
+ │   └── 20170720012031
107
+ ```
108
+
109
+ ## Git
110
+ ``` ruby
111
+ require 'mina/git'
112
+ ```
113
+ loads:
114
+ - `mina/default`
115
+
116
+ ### Variables
117
+ ``` ruby
118
+ :branch #=> 'master'
119
+ :remove_git_dir #=> true
120
+ :remote #=> 'origin'
121
+ :git_not_pushed_message #=> "Your branch #{fetch(:branch)} needs to be pushed to #{fetch(:remote)} before deploying"
122
+ ```
123
+
124
+ ### Tasks
125
+ ``` ruby
126
+ # git:clone is not meant to be run outside `deploy do` block
127
+ git:clone #=> Clones the Gir repository to the current path
128
+ git:revision #=> Prints out current revision
129
+ git:ensure_pushed #=> Ensures local repository is pushed to remote
130
+ ```
131
+
132
+ ## Bunlder
133
+ ``` ruby
134
+ require 'mina/bunlder'
135
+ ```
136
+ loads:
137
+ - `mina/default`
138
+
139
+ ### Variables
140
+ ``` ruby
141
+ :bundle_bin #=> 'bundle'
142
+ :bundle_path #=> 'vendor/bundle'
143
+ :bundle_withouts #=> 'development test'
144
+ :bundle_options #=> "--without #{fetch(:bundle_withouts)} --path "#{fetch(:bundle_path)}" --deployment"
145
+ :shared_dirs #=> fetch(:shared_dirs, []).push(fetch(:bundle_path)) ## Add `bundle_path` to `shared_dirs`
146
+ ```
147
+
148
+ ### Tasks
149
+
150
+ ``` ruby
151
+ bundle:install #=> Install gem dependencies using Bundler
152
+ bundle:clean #=> Cleans up unused gems in your bundler directory
153
+ ```
154
+
155
+ ## Rails
156
+ ``` ruby
157
+ require 'mina/rails'
158
+ ```
159
+ loads:
160
+ - `mina/deploy`
161
+ - `mina/bundler`
162
+
163
+ ### Variables
164
+ ``` ruby
165
+ :rails_env #=> 'production'
166
+ :bundle_prefix #=> %{RAILS_ENV="#{fetch(:rails_env)}" #{fetch(:bundle_bin)} exec}
167
+ :rake #=> "#{fetch(:bundle_prefix)} rake"
168
+ :rails #=> "#{fetch(:bundle_prefix)} rails"
169
+ :compiled_asset_path #=> 'public/assets'
170
+ :asset_dirs #=> ['vendor/assets/', 'app/assets/']
171
+ :migration_dirs #=> ['db/migrate']
172
+ :force_migrate #=> false
173
+ :force_asset_precompile #=> false
174
+ ```
175
+
176
+ ### Tasks
177
+ ``` ruby
178
+ console #=> Starts and interactive console
179
+ log #=> Tail log from server
180
+ rails[command] #=> Runs rails command; example `$ mina 'rails[console]'`
181
+ rake[command] #=> Runs rake command; example `$ mina 'rake[db:migrate]'`
182
+
183
+ # rails:* tasks are not meant to be run outside of `deploy do` block. Please use the tasks above.
184
+ rails:db_migrate #=> Checks for changes in `:migration_dirs` and runs `db:migrate` if needed. Can be forced with `:force_migrate` variable
185
+ rails:assets_precompile #=> Checks for changes in `:asset_dirs` and runs `assets:precomile` if needed. Can be fored with `:force_asset_precompile` variable
186
+ rails:db_create #=> Runs `db:create`
187
+ rails:db_rollback #=> Runs `db:rollback`
188
+ rails:assets_clean #=> Runs `assets:clean`
189
+ rails:db_schema_load #=> Runs `db:schema:load`
190
+ ```
@@ -1,5 +1,4 @@
1
- Deploying
2
- --------------------
1
+ # Deploying
3
2
 
4
3
  Mina provides the `deploy` command which runs your commands on remote backend.
5
4
 
@@ -1,5 +1,4 @@
1
- Frequently Asked Questions
2
- --------------------
1
+ # Frequently Asked Questions
3
2
 
4
3
  ## - `command not found: bundle`
5
4
 
@@ -7,13 +6,22 @@ You need to setup your server correctly [getting started](getting_started.md#ste
7
6
 
8
7
  gem install bundler
9
8
 
10
- ## - ruby version not found, but is already installed
9
+ ## - `my_program` not found, but is already installed
11
10
 
12
11
  Mina is running in a non-interactive ssh mode. That means that your full profile will not be loaded: ![ssh](http://capistranorb.com/images/BashStartupFiles1.png)
13
12
 
14
- if you setup your server correctly and you are using a ruby environment manager please ensure that:
15
- - you are using a mina plugin for that manager or
16
- - the lines that load up your manager are at the top of your .bashrc file: http://stackoverflow.com/a/216204/1339894
13
+ There is a line at the top in most `.bashrc` files:
14
+ ```
15
+ # If not running interactively, don't do anything
16
+ case $- in
17
+ *i*) ;;
18
+ *) return;;
19
+ esac
20
+ ```
21
+ this means that all lines below this will not be executed when using mina.
22
+
23
+ The easiest way to fix this is to move all your `export` and `source` lines to the top of your `.bashrc` file.
24
+ More info at: http://stackoverflow.com/a/216204/1339894
17
25
 
18
26
  ## - Mina hangs after i type my password in
19
27
 
@@ -1,9 +1,8 @@
1
- Setting up a project
2
- --------------------
1
+ # Setting up a project
3
2
 
4
3
  Let's deploy a project using Mina.
5
4
 
6
- ### Step 0: Configure server
5
+ ## Step 0: Configure server
7
6
 
8
7
  Your server needs to be properly configured for mina to work. Requirements for mina 1.0 to work:
9
8
  - SSH public/private key pair set up
@@ -12,7 +11,7 @@ Your server needs to be properly configured for mina to work. Requirements for m
12
11
  - installed ruby (some ruby manager recommended rbenv/rvm/chruby)
13
12
  - installed bundler
14
13
 
15
- ### Step 1: Create a config/deploy.rb
14
+ ## Step 1: Create a config/deploy.rb
16
15
 
17
16
  In your project, type `mina init` to create a sample of this file.
18
17
 
@@ -53,7 +52,7 @@ end
53
52
  ...
54
53
  ```
55
54
 
56
- ### Step 2: Run 'mina setup'
55
+ ## Step 2: Run 'mina setup'
57
56
 
58
57
  Back at your computer, do `mina setup` to set up the folder structure in `deploy_to` path.
59
58
  This will connect to your server via SSH and create the right directories.
@@ -61,9 +60,7 @@ This will connect to your server via SSH and create the right directories.
61
60
  $ mina setup
62
61
  -----> Creating folders... done.
63
62
 
64
- See [directory structure](https://github.com/mina-deploy/mina/wiki/Directory-structure) for more info.
65
-
66
- ### Step 3: Deploy!
63
+ ## Step 3: Deploy!
67
64
 
68
65
  Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
69
66
 
@@ -73,3 +70,7 @@ Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
73
70
  Lots of things happening...
74
71
  ...
75
72
  -----> Done.
73
+
74
+ ## Step 4: Considerations after first deploy
75
+
76
+ If you changed `shared_files` and `shared_dirs` in your `deploy.rb` you have to run `mina setup` again. This ensures all needed folders are created.
@@ -0,0 +1,193 @@
1
+ # How Mina Works?
2
+
3
+ ## The Idea
4
+
5
+ The idea behind `mina` is to have one (or more) config file which contains all the information about your server. Domain info, deploy user info, where will your application live, etc.
6
+ With that information `mina` creates a bash script that deploys your application. `mina` connects to your server over ssh and runs the generated bash script.
7
+
8
+ Example of generated deploy script
9
+
10
+ ``` sh
11
+ $ mina deploy
12
+ #!/usr/bin/env bash
13
+ # Executing the following via 'ssh deploy@example.com -p 22 -tt':
14
+ #
15
+ #!/usr/bin/env bash
16
+
17
+ # Go to the deploy path
18
+ ...
19
+
20
+ # Checks
21
+ ...
22
+
23
+ # Bootstrap script (in deployer)
24
+ echo "-----> Creating a temporary build path"
25
+ touch "deploy.lock" &&
26
+ mkdir -p "$build_path" &&
27
+ cd "$build_path" &&
28
+ ...
29
+ echo "-----> Deploy finished"
30
+ #
31
+ # Build
32
+ echo "-----> Building"
33
+ ...
34
+ #
35
+ # Launching
36
+ # Rename to the real release path, then symlink 'current'
37
+ echo "-----> Launching"
38
+ ...
39
+
40
+ # ============================
41
+ # === Start up server => (in deployer)
42
+ ...
43
+
44
+ # ============================
45
+ # === Complete & unlock
46
+ rm -f "deploy.lock"
47
+ echo "-----> Done. Deployed version $version"
48
+
49
+ # ============================
50
+ # === Failed deployment
51
+ echo "! ERROR: Deploy failed."
52
+ ...
53
+
54
+ # Unlock
55
+ rm -f "deploy.lock"
56
+ echo "OK"
57
+ exit 19
58
+ )
59
+
60
+
61
+ Elapsed time: 0.00 seconds
62
+
63
+ ```
64
+
65
+ This script is then run on your server over ssh. Example:
66
+
67
+ ```
68
+ ssh deploy@example.com -p 22 -tt --- "#!/usr/bin/env/bash\n #Go to the deploy path\n ...."
69
+ ```
70
+
71
+ ## The CLI
72
+
73
+ Basic usage:
74
+
75
+ $ mina [OPTIONS] [TASKS] [VAR1=val VAR2=val ...]
76
+
77
+ ### Options
78
+
79
+ Beside normal rake options mina added some of its own:
80
+
81
+ * `-v` / `--verbose` - This will show commands being done on the server. Off by
82
+ default.
83
+
84
+ * `-s` / `--simulate` - This will not run any commands; instead, it will simply output the script it builds.
85
+
86
+ * `-V` / `--version` - Shows the current version.
87
+
88
+ * `-AT` / `--all --tasks` - Show all tasks mina can run.
89
+
90
+ * `-d` / `--debug-configuration-variables` - Display the defined config variables before runnig the tasks.
91
+
92
+ ### Tasks
93
+
94
+ A cool feautre of rake is that you run multiple tasks from one command:
95
+
96
+ ```
97
+ $ mina setup deploy
98
+ ```
99
+
100
+ This command will run both `setup` and `deploy` task consecutively.
101
+
102
+ ### Variables
103
+
104
+ You may specify additional variables in the `KEY=value` style, just like any other command line tools.
105
+ You can add as many variables as needed.
106
+
107
+ $ mina restart on=staging
108
+
109
+ # This sets the ENV['on'] variable to 'staging'.
110
+
111
+
112
+ ## Folder Structure
113
+
114
+ After `mina setup` is run, you can see this structure on your server:
115
+
116
+ ``` sh
117
+ .
118
+ ├── current -> /home/deploy/www/example.com/releases/91
119
+ ├── releases
120
+ │   ├── 86
121
+ │   ├── 87
122
+ │   ├── 88
123
+ │   ├── 89
124
+ │   ├── 90
125
+ │   └── 91
126
+ ├── scm
127
+ ├── shared
128
+ │   ├── bundle
129
+ │   ├── config
130
+ │   ├── log
131
+ │   ├── public
132
+ │   ├── tmp
133
+ │   └── vendor
134
+ └── tmp
135
+ ```
136
+
137
+ Folder | Description
138
+ -------|------
139
+ `current` | folders is a symbolic link to the current release (does not have to be the lastest one)
140
+ `releases` | folder conains your last `keep_releases` releases
141
+ `scm` | folder contains information about your version controll (git, svn, ...)
142
+ `shared` | folder cotinas folders and files that are kept between releaes (logs, uploads, configs, ...)
143
+ `tmp` | folder contains temporary build folders
144
+
145
+ ## Features
146
+
147
+ ### Execution modes (Runners)
148
+
149
+ With `set :execution_mode` you can change how your tasks are run. There are currently 4 modes:
150
+
151
+ Mode | Description
152
+ -----|------------
153
+ `:exec` | It uses [Kernel#exec](http://ruby-doc.org/core-2.4.2/Kernel.html#method-i-exec) to run your script. This means that it will execute and exit and won't run any other tasks. This is useful for tasks such as [`mina console`](https://github.com/mina-deploy/mina/blob/master/tasks/mina/rails.rb#L15)
154
+ `:system` | It uses [Kernel#system](http://ruby-doc.org/core-2.4.2/Kernel.html#method-i-system) to run your script.
155
+ `:pretty` | It uses [Open4#popen4](https://github.com/ahoward/open4/blob/master/lib/open4.rb#L33) to run your script. This mode pretty prints stdout and stderr and colors it. This the default mode for most of the default tasks.
156
+ `:printer` | It uses [Kernel#puts](http://ruby-doc.org/core-2.4.2/Kernel.html#method-i-puts) to run your script. This is used when `simulate` flag is set so it only prints out the generated script
157
+
158
+ #### WARNING
159
+ `:pretty` mode is using Popen4. In this mode STDIN is efectivly disabled. This means that any kind of inputs won't be forwarded to remote host. If you have a need for password input please use `:system` mode
160
+
161
+ ### Backends
162
+
163
+ When writing your tasks you can choose on which backend you want your scripts to run. Currently there are 2 backends:
164
+
165
+ Backend | Description
166
+ --------|---------
167
+ `:remote` | Run on your server over SSH
168
+ `:local` | Run on your machine
169
+
170
+ Choosing on which backend a particular block is ran is defined in [`run(backend) do` block](writing_your_own_tasks.rb#run)
171
+ These `run` blocks can be used however you want, you can mixandmatch them anywhich way. Only restriction is thay you can't use a `run` block inside another `run` block.
172
+
173
+ Example:
174
+
175
+ ```
176
+ task :example do
177
+ run(:local) do
178
+ comamnd "scp config/application.yml #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:shared_path)}/config/application.yml"
179
+ end
180
+
181
+ run(:remote) do
182
+ command "passenger-configure restart-app"
183
+ end
184
+
185
+ run(:local) do
186
+ command 'say "Done!"'
187
+ end
188
+ end
189
+ ```
190
+
191
+ `deploy do` block is a wrapper around `run(:backend) do` block.
192
+
193
+
@@ -1,31 +1,40 @@
1
- Migrating from 0.3.x to 1.0
2
- --------------------
3
- # DSL
1
+ # Migrating from 0.3.x to 1.0
4
2
 
5
- ## old
3
+ ## DSL
4
+
5
+ ### old
6
6
  * `queue` -> `command` # adds command to queue
7
7
  * `queue!` -> `command` # it will output the command if verbose is true
8
8
  * `to` -> `on` # changes queue name
9
9
  * `in_directory` -> `in_path` # wraps commands to be run in specified path
10
10
  * `invoke :'task[param]'` -> `invoke :task, param` # passes params to the task
11
11
 
12
- ## new
12
+ ### new
13
13
  * `run` # runs commands on a specified backend, this has replaced old before and after hooks
14
14
  * `comment` # adds a 'echo -----> #{command}' to queue
15
15
 
16
16
  **Other commands have been removed!**
17
17
 
18
- # Setting variables
18
+ Remove `:environment` dependency on all your tasks!
19
+ ```
20
+ task deploy: :environment do
21
+ ...
22
+ --->
23
+ task :deploy do
24
+ ...
25
+ ```
26
+
27
+ ## Setting variables
19
28
 
20
- ## same
29
+ ### same
21
30
  * `set` # remained for setting variables
22
31
 
23
- ## new
32
+ ### new
24
33
  * `fetch` # **ALL** variables now need to be fetched with `fetch`. Removed `method_missing`
25
34
  * `set?`
26
35
  * `ensure!`
27
36
 
28
- # Deploy variables
37
+ ## Deploy variables
29
38
 
30
39
  * `shared_paths` -> separated into `shared_dirs` & `shared_files`
31
40
 
@@ -39,7 +48,7 @@ set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/
39
48
  All `*_path` variables (`:current_path`, `:shared_path`, ...) now include `:deploy_to`
40
49
  * `#{fetch(:deploy_to)}/#{fetch(:current_path)}` -> `fetch(:current_path)`
41
50
 
42
- # Using new mina on old projects
51
+ ## Using new mina on old projects
43
52
 
44
53
  * run `mina setup`
45
54
  * if you do not want for bundle to install gems copy `current/vendor/bundle` to `/shared/vendor/bundle`
@@ -1,13 +1,12 @@
1
- Writing your own tasks
2
- --------------------
1
+ # Writing your own tasks
3
2
 
4
- # Defining tasks
3
+ ## Defining tasks
5
4
 
6
5
  The file `deploy.rb` is simply a Rakefile invoked by Rake. In fact, `mina` is
7
6
  mostly an alias that invokes Rake to load `deploy.rb`.
8
7
 
9
8
  ``` ruby
10
- # Sample config/deploy.rb
9
+ ## Sample config/deploy.rb
11
10
  set :domain, 'your.server.com'
12
11
 
13
12
  task :restart do
@@ -25,11 +24,11 @@ The `command` command queues up Bash commands to be run on the remote server.
25
24
  If you invoke `mina restart`, it will invoke the task above and run the queued
26
25
  commands on the remote server `your.server.com` via SSH.
27
26
 
28
- # DSL
27
+ ## DSL
29
28
 
30
- ## Helpers
29
+ ### Helpers
31
30
 
32
- ### invoke
31
+ #### invoke
33
32
  Invokes another Rake task.
34
33
 
35
34
  ``` ruby
@@ -37,7 +36,7 @@ invoke :'git:clone'
37
36
  invoke :restart
38
37
  ```
39
38
 
40
- ### command
39
+ #### command
41
40
  Adds a command to the command queue.
42
41
 
43
42
  This queues code to be run on the current queue name (defaults to `:default`).
@@ -48,14 +47,14 @@ By default, whitespace is stripped from the beginning and end of the command.
48
47
  command %{ls -al} # => [ls -al]
49
48
  ```
50
49
 
51
- ### comment
50
+ #### comment
52
51
  Adds a comment to the command queue.
53
52
 
54
53
  ``` ruby
55
54
  comment %{ls -al} # => [echo "-----> ls -al"]
56
55
  ```
57
56
 
58
- ### run
57
+ #### run
59
58
  Runs the given block on the defined backend (remote or local)
60
59
 
61
60
  ``` ruby
@@ -64,7 +63,7 @@ run :remote do
64
63
  end
65
64
  ```
66
65
 
67
- ### on
66
+ #### on
68
67
  Change the queue name for the given block. Use this if you have multiple places where commands need to end up. Mainly used in `deploy` task.
69
68
 
70
69
  ``` ruby
@@ -73,7 +72,7 @@ on :launch do
73
72
  end
74
73
  ```
75
74
 
76
- ### in_path
75
+ #### in_path
77
76
  Change the path the commands in the given block is run.
78
77
 
79
78
  ``` ruby
@@ -82,16 +81,16 @@ in_path('some/new/path') do
82
81
  end
83
82
  ```
84
83
 
85
- ## Configuration
84
+ ### Configuration
86
85
 
87
- ### set
86
+ #### set
88
87
  Sets configuration variable. Can a value or a proc/lambda.
89
88
 
90
89
  ``` ruby
91
90
  set :deploy_to -> '/path/to/deploy'
92
91
  ```
93
92
 
94
- ### fetch
93
+ #### fetch
95
94
  Gets configuration variable. Runs `.call` if callable.
96
95
  Returns nil if not set. If default parameter is passed returns default if not set.
97
96
 
@@ -100,14 +99,14 @@ fetch(:deploy_to)
100
99
  fetch(:deploy_to, 'some_default')
101
100
  ```
102
101
 
103
- ### set?
102
+ #### set?
104
103
  Checks if a variable is set.
105
104
 
106
105
  ``` ruby
107
106
  set?(:deploy_to)
108
107
  ```
109
108
 
110
- ### ensure!
109
+ #### ensure!
111
110
  Raises an error if variable is not set
112
111
 
113
112
  ``` ruby
@@ -22,7 +22,7 @@ module Mina
22
22
  switch =~ /--#{Regexp.union(not_applicable_to_mina)}/
23
23
  end
24
24
 
25
- super.push(version, verbose, simulate, debug_configuration_variables)
25
+ super.push(version, verbose, simulate, debug_configuration_variables, no_report_time)
26
26
  end
27
27
 
28
28
  def top_level_tasks
@@ -73,5 +73,14 @@ module Mina
73
73
  end
74
74
  ]
75
75
  end
76
+
77
+ def no_report_time
78
+ ['--no-report-time', nil,
79
+ 'Skip time reporting',
80
+ lambda do |_value|
81
+ set(:skip_report_time, true)
82
+ end
83
+ ]
84
+ end
76
85
  end
77
86
  end
@@ -36,8 +36,10 @@ module Mina
36
36
  ENV.has_key?(key.to_s) || !variables.fetch(key, nil).nil?
37
37
  end
38
38
 
39
- def ensure!(key)
40
- error! "#{key} must be defined!" unless set?(key)
39
+ def ensure!(key, message: nil)
40
+ return if set?(key)
41
+ message ||= "#{key} must be defined!"
42
+ error! message
41
43
  end
42
44
 
43
45
  def reset!
@@ -24,11 +24,13 @@ module Mina
24
24
  end
25
25
 
26
26
  def run(backend)
27
- # @commands = Commands.new
28
- invoke :environment if backend == :remote
27
+ error! "Can't use run block inside another run block. #{caller[2]}" if set?(:run_bock)
28
+ set(:run_bock, true)
29
+ invoke :"#{backend}_environment"
29
30
  yield
30
31
  commands.run(backend)
31
32
  @commands = Commands.new
33
+ set(:run_bock, nil)
32
34
  end
33
35
 
34
36
  def on(stage)
@@ -47,7 +49,9 @@ module Mina
47
49
 
48
50
  def deploy(&block)
49
51
  run :remote do
52
+ set(:deploy, true)
50
53
  command deploy_script(&block), quiet: true
54
+ set(:deploy, false)
51
55
  end
52
56
  end
53
57
  end
@@ -37,7 +37,7 @@ module Mina
37
37
  def report_time
38
38
  time_start = Time.now
39
39
  output = yield
40
- print_info "Elapsed time: %.2f seconds" % [Time.now - time_start]
40
+ print_info "Elapsed time: %.2f seconds" % [Time.now - time_start] unless fetch(:skip_report_time)
41
41
  output
42
42
  end
43
43
 
@@ -1,3 +1,3 @@
1
1
  module Mina
2
- VERSION = '1.0.7'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -15,7 +15,9 @@ RSpec.describe 'rails', type: :rake do
15
15
 
16
16
  describe 'rails:db_migrate' do
17
17
  it 'rails db migrate' do
18
+ Mina::Configuration.instance.set(:deploy_block, true)
18
19
  expect { invoke_all }.to output(output_file('rails_db_migrate')).to_stdout
20
+ Mina::Configuration.instance.set(:deploy_block, false)
19
21
  end
20
22
  end
21
23
 
@@ -33,7 +35,9 @@ RSpec.describe 'rails', type: :rake do
33
35
 
34
36
  describe 'rails:assets_precompile' do
35
37
  it 'rails assets precompile' do
38
+ Mina::Configuration.instance.set(:deploy_block, true)
36
39
  expect { invoke_all }.to output(output_file('rails_assets_precompile')).to_stdout
40
+ Mina::Configuration.instance.set(:deploy_block, false)
37
41
  end
38
42
  end
39
43
 
@@ -3,6 +3,13 @@ require 'mina/install'
3
3
  set :port, 22
4
4
 
5
5
  task :environment do
6
+ print_error ':environment is DEPRECATED! Please use local_environment and remote_environment'
7
+ end
8
+
9
+ task :local_environment do
10
+ end
11
+
12
+ task :remote_environment do
6
13
  end
7
14
 
8
15
  task :default do
@@ -29,7 +36,7 @@ task :debug_configuration_variables do
29
36
  end
30
37
  end
31
38
 
32
- desc 'Adds current repo host to the known hosts'
39
+ desc 'Adds repo host to the known hosts'
33
40
  task :ssh_keyscan_repo do
34
41
  ensure!(:repository)
35
42
  repo_host = fetch(:repository).split(%r{@|://}).last.split(%r{:|\/}).first
@@ -44,7 +51,7 @@ task :ssh_keyscan_repo do
44
51
  }
45
52
  end
46
53
 
47
- desc 'Adds domain known hosts'
54
+ desc 'Adds domain to the known hosts'
48
55
  task :ssh_keyscan_domain do
49
56
  ensure!(:domain)
50
57
  ensure!(:port)
@@ -6,7 +6,7 @@ set :remote, 'origin'
6
6
  set :git_not_pushed_message, -> { "Your branch #{fetch(:branch)} needs to be pushed to #{fetch(:remote)} before deploying" }
7
7
 
8
8
  namespace :git do
9
- desc 'Clones the Git repository to the release path.'
9
+ desc 'Clones the Git repository to the current path.'
10
10
  task :clone do
11
11
  ensure!(:repository)
12
12
  ensure!(:deploy_to)
@@ -36,11 +36,13 @@ namespace :git do
36
36
  end
37
37
  end
38
38
 
39
+ desc 'Prints out current revision'
39
40
  task :revision do
40
41
  ensure!(:deploy_to)
41
42
  command %{cat #{fetch(:current_path)}/.mina_git_revision}
42
43
  end
43
44
 
45
+ desc 'Ensures local repository is pushed to remote'
44
46
  task :ensure_pushed do
45
47
  run :local do
46
48
  comment %{Ensuring everyting is pushed to git}
@@ -30,6 +30,7 @@ end
30
30
  namespace :rails do
31
31
  desc 'Migrate database'
32
32
  task :db_migrate do
33
+ ensure!(:deploy_block, message: "Can't be run outside deploy do block. Please use mina 'rake[db_migrate]' instead")
33
34
  if fetch(:force_migrate)
34
35
  comment %{Migrating database}
35
36
  command %{#{fetch(:rake)} db:migrate}
@@ -57,6 +58,7 @@ namespace :rails do
57
58
 
58
59
  desc 'Precompiles assets (skips if nothing has changed since the last release).'
59
60
  task :assets_precompile do
61
+ ensure!(:deploy_block, message: "Can't be run outside deploy do block. Please use mina 'rake[assets_precompile]' instead")
60
62
  if fetch(:force_asset_precompile)
61
63
  comment %{Precompiling asset files}
62
64
  command %{#{fetch(:rake)} assets:precompile}
@@ -70,3 +70,40 @@ task :test do
70
70
  command %{ls -al}
71
71
  end
72
72
  end
73
+
74
+ desc 'Fails test'
75
+ task :fail do
76
+ run :remote do
77
+ run :local do
78
+ command "pwd"
79
+ end
80
+ end
81
+ end
82
+
83
+ task :local_environment do
84
+ comment 'local environment run'
85
+ command 'export HERE=local'
86
+ end
87
+
88
+ task :remote_environment do
89
+ comment 'remote environment run'
90
+ command 'export HERE=remote'
91
+ end
92
+
93
+ task test_envs: :environment do
94
+ run(:local) do
95
+ command 'echo $HERE'
96
+ end
97
+
98
+ run(:remote) do
99
+ command 'echo $HERE'
100
+ end
101
+
102
+ run(:local) do
103
+ command 'echo $HERE'
104
+ end
105
+
106
+ run(:remote) do
107
+ command 'echo $HERE'
108
+ end
109
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -132,11 +132,12 @@ files:
132
132
  - data/deploy.sh.erb
133
133
  - docs/3rd_party_plugins.md
134
134
  - docs/Readme.md
135
- - docs/command_line_options.md
136
135
  - docs/cookbook.md
136
+ - docs/default_plugins.md
137
137
  - docs/deploying.md
138
138
  - docs/faq.md
139
139
  - docs/getting_started.md
140
+ - docs/how_mina_works.md
140
141
  - docs/migrating.md
141
142
  - docs/writing_your_own_tasks.md
142
143
  - lib/Minafile
@@ -1,33 +0,0 @@
1
- Command line options
2
- --------------------
3
-
4
- Basic usage:
5
-
6
- $ mina [OPTIONS] [TASKS] [VAR1=val VAR2=val ...]
7
-
8
- ### Options
9
-
10
- Beside normal rake options mina added some of its own:
11
-
12
- * `-v` / `--verbose` - This will show commands being done on the server. Off by
13
- default.
14
-
15
- * `-s` / `--simulate` - This will not run any commands; instead, it will simply output the script it builds.
16
-
17
- * `-V` / `--version` - Shows the current version.
18
-
19
- * `-d` / `--debug-configuration-variables` - Display the defined config variables before runnig the tasks.
20
-
21
- ### Tasks
22
-
23
- There are many tasks available. See the [tasks reference](https://mina-deploy.github.io/mina/tasks/), or
24
- type `mina -T`.
25
-
26
- ### Variables
27
-
28
- You may specify additional variables in the `KEY=value` style, just like any other command line tools.
29
- You can add as many variables as needed.
30
-
31
- $ mina restart on=staging
32
-
33
- # This sets the ENV['on'] variable to 'staging'.