middleman-rackspace 0.2.0 → 0.3.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: 9d2b3ba6bea685835c35fd38eb6abe198e0d9e96
4
- data.tar.gz: 603e40a365c56cd9ea78fdca7dcf2667ba1c4322
3
+ metadata.gz: df865b2a6e1983e6c2bac0f9a142842d6ae42ded
4
+ data.tar.gz: 855183429f07852b80185dbe0bef863b76232394
5
5
  SHA512:
6
- metadata.gz: 5ae9639c5361faac4caa49dd7fd7d701cf9aada4cbf62907f5c618f19788c2910a75f3595b1ccbf0b08b7714c570920918168f4a18c0deecc830fa02a1b6c222
7
- data.tar.gz: 1f7acb829b61b80a0ad3ebb4ebe70a87f521169cc10097690b5f1ed8c6b862a1c1d86b285b6dffa91eb82d2f2d5e40c879282829827e83d4f00d3bd7f3bf2084
6
+ metadata.gz: af6601a6de2cb65e9bd28e9a2f7ed1134a2fee0fad8404d61415d51ef69ca1506ef4e0608d6d75da99cacba57f68df7ad5f6ff9cef80b82deddd41dc04d62cfa
7
+ data.tar.gz: 8e86e75d70596ae918db635a428d04feaa96ab7b08c13235abab084adb4cb60197e0d6967ebc8af223cb8ab53e99270a45c63ab49759af4cfc85dc8b55996705
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2015-11-12)
4
+
5
+ * Add support to checkout git branch before build.
6
+ * Clean up console logging.
7
+
3
8
  ## 0.2.0 (2015-11-10)
4
9
 
5
10
  * Add support for 'production' and 'staging' containers.
6
11
 
7
12
  ## 0.1.0 (2015-11-02)
8
13
 
9
- * Initial release
14
+ * Initial release.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Deploy your [Middleman](https://middlemanapp.com/) site to [Rackspace Cloud Files](http://www.rackspace.com/cloud/files).
4
4
 
5
- # Usage
5
+ ## Usage
6
6
 
7
7
  Add the following to the `Gemfile` for you Middleman project and perform a `bundle install`.
8
8
 
@@ -24,7 +24,20 @@ $ middleman rackspace staging
24
24
 
25
25
  An archive `build_ENVIRONMENT_TIMESTAMP.tar.gz` is created for your current build and pushed to Rackspace. A new container will automatically be configured on the specified region. If there is an existing container with the same name, **data will be overwritten**.
26
26
 
27
- # Configuration
27
+ ## Git support
28
+
29
+ To enable git support, set `config.git` to `true` or pass `--git` on the CLI. When enabled, the `middleman rackspace` command will automatically switch to the git branch corresponding to the environment you are deploying.
30
+
31
+ Default branch mappings:
32
+
33
+ * `staging` environment maps to `staging` branch.
34
+ * `production` environment maps to `master` branch.
35
+
36
+ Both of these can be changed in the configuration.
37
+
38
+ The git support will automatically stash any changes you have in your working tree before switching branch. After a successful build and deploy, these changes will be restored.
39
+
40
+ ## Configuration
28
41
 
29
42
  Activate and configure middleman-rackspace by adding an `activate :rackspace` block to `config.rb`. For example:
30
43
 
@@ -36,7 +49,8 @@ activate :rackspace do |config|
36
49
  config.rackspace_region = :syd
37
50
  config.container_staging = 'example-container-staging'
38
51
  config.container_production = 'example-container'
39
- config.build_before = true
52
+ config.git = true
53
+ config.build = true
40
54
  end
41
55
  ```
42
56
 
@@ -50,25 +64,28 @@ activate :rackspace do |config|
50
64
  config.rackspace_api_key = ENV['RACKSPACE_API_KEY']
51
65
  # The Rackspace region to deploy to
52
66
  config.rackspace_region = :dfw
53
- # The target container on Rackspace for staging
67
+ # The target Rackspace container for each environment
54
68
  config.container_staging = nil
55
- # The target container on Rackspace for production
56
69
  config.container_production = nil
70
+ # Git branch for each environment
71
+ config.branch_staging = 'staging'
72
+ config.branch_production = 'master'
73
+ # Checkout environment branch before the build/deploy step
74
+ config.git = false
75
+ # Run `middleman build` before the deploy step
76
+ config.build = false
57
77
  # Root page filename
58
78
  config.index_file = 'index.html'
59
79
  # Error page filename prefix, translates to 401.html and 404.html
60
80
  config.error_file_prefix = '.html'
61
- # Run `middleman build` before the deploy step
62
- config.build_before = false
63
81
  end
64
82
  ```
65
83
 
66
84
  For a list of available regions see [http://www.rackspace.com/knowledge_center/article/about-regions](http://www.rackspace.com/knowledge_center/article/about-regions).
67
85
 
68
- # Todo
86
+ ## Todo
69
87
 
70
88
  * On deploy, delete files on the server that have been removed from the build.
71
89
  * Invalidate cache after deploy.
72
- * Integrate with git to deploy from a branch.
73
90
  * Improve CLI to deploy from a pre-built `build_ENVIRONMENT_TIMESTAMP.tar.gz`.
74
91
  * Improve error handling.
@@ -11,10 +11,14 @@ module Middleman
11
11
 
12
12
  desc 'rackspace ENVIRONMENT [options]', 'Deploy to Rackspace container for ENVIRONMENT'
13
13
 
14
- class_option :build_before,
14
+ class_option :git,
15
+ aliases: '-g',
16
+ type: :boolean,
17
+ desc: 'Checkout environment branch before the build/deploy step'
18
+
19
+ class_option :build,
15
20
  aliases: '-b',
16
21
  type: :boolean,
17
- #default: false,
18
22
  desc: 'Run `middleman build` before the deploy step'
19
23
 
20
24
  # Tell Thor to exit with a non-zero exit code on failure
@@ -30,14 +34,72 @@ module Middleman
30
34
  # Instantiate Middleman and load config
31
35
  app = Middleman::Application.server.inst
32
36
 
33
- # Run `middleman build` if specified with '-b' or in 'config.rb'
34
- build_enabled = options[:build_before] || app.extensions[:rackspace].options.build_before
35
- if build_enabled
37
+ # Pull the Rackspace config out of 'app'
38
+ config = app.extensions[:rackspace].options
39
+
40
+ # Use git if specified with '--git' or in 'config.rb'
41
+ git_enabled = options[:git] || config.git
42
+ original_branch = ''
43
+ switching = false
44
+ stash = ''
45
+ if git_enabled
46
+ original_branch = `git rev-parse --abbrev-ref HEAD`.chomp
47
+ branch = case environment
48
+ when 'staging'
49
+ config.branch_staging
50
+ when 'production'
51
+ config.branch_production
52
+ end
53
+ switching = original_branch != branch
54
+
55
+ stash = `git stash create`
56
+ unless stash.empty?
57
+ puts ''
58
+ puts 'Working changes have been stashed. On failure, manually restore with:'
59
+ puts ''
60
+ puts " git stash apply #{stash}"
61
+ end
62
+
63
+ # Switch branch if needed and have a clean working tree
64
+ if switching
65
+ puts ''
66
+ puts "Checking out '#{branch}' branch."
67
+ run("git checkout #{branch} --force") || exit(1)
68
+ elsif !stash.empty?
69
+ puts ''
70
+ puts 'Cleaning working tree.'
71
+ run('git reset --hard') || exit(1)
72
+ end
73
+
74
+ # Do a 'git pull' to update the branch from the remote
75
+ puts ''
76
+ puts 'Updating branch from remote.'
77
+ run('git pull') || exit(1)
78
+ end
79
+
80
+ # Run `middleman build` if specified with '--build' or in 'config.rb'
81
+ if options[:build] || config.build
82
+ puts ''
83
+ puts 'Building site.'
36
84
  run('middleman build') || exit(1)
37
85
  end
38
86
 
39
87
  # Deploy the built website
40
88
  Middleman::Rackspace.deploy(app, environment)
89
+
90
+ # Change back to original branch and restore any saved stash
91
+ if git_enabled
92
+ if switching
93
+ puts ''
94
+ puts "Switching back to '#{original_branch}' branch."
95
+ run("git checkout #{original_branch}") || exit(1)
96
+ end
97
+ unless stash.empty?
98
+ puts ''
99
+ puts "Restoring working changes."
100
+ run("git stash apply #{stash}") || exit(1)
101
+ end
102
+ end
41
103
  end
42
104
  end
43
105
  end
@@ -15,11 +15,10 @@ module Middleman
15
15
  config.container_production
16
16
  end
17
17
 
18
- puts "Deploying for #{environment} to '#{container_name}'"
19
-
20
18
  # build_ENVIRONMENT_TIMESTAMP.tar.gz
21
19
  archive_name = "build_#{environment}_#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.tar.gz"
22
- puts "Creating archive: #{archive_name}"
20
+ puts ''
21
+ puts "Creating archive '#{archive_name}'."
23
22
 
24
23
  # Compress /build directory into build_ENVIRONMENT_TIMESTAMP.tar.gz
25
24
  system("cd ./build && tar -zcvf ../#{archive_name} .")
@@ -36,7 +35,8 @@ module Middleman
36
35
  # Get or create container
37
36
  root_directory = service.directories.get(container_name)
38
37
  unless root_directory
39
- puts "Creating container: #{container_name}"
38
+ puts ''
39
+ puts "Creating container '#{container_name}'."
40
40
  # Create the new container
41
41
  root_directory = service.directories.create(key: container_name, public: true)
42
42
  # Configure container for static site hosting
@@ -47,13 +47,15 @@ module Middleman
47
47
  'X-Container-Meta-Web-Error' => config.error_file_prefix})
48
48
  end
49
49
 
50
- puts "Updating container: #{root_directory.key}"
50
+ puts ''
51
+ puts "Updating container '#{container_name}'."
51
52
 
52
53
  # Upload and extract tar.gz on Rackspace
53
54
  # https://developer.rackspace.com/docs/cloud-files/v1/developer-guide/#extracting-archive-files
54
55
  service.extract_archive(container_name, File.open(archive_name, 'r'), 'tar.gz')
55
56
 
56
- puts "Website live at: #{root_directory.public_url}"
57
+ puts ''
58
+ puts "Container '#{container_name}' live at:\n#{root_directory.public_url}"
57
59
  end
58
60
  end
59
61
  end
@@ -6,11 +6,14 @@ module Middleman
6
6
  option :rackspace_username, ENV['RACKSPACE_USERNAME'], 'Rackspace username'
7
7
  option :rackspace_api_key, ENV['RACKSPACE_API_KEY'], 'Rackspace API key'
8
8
  option :rackspace_region, :dfw, 'Rackspace region'
9
- option :container_staging, nil, 'The target container on Rackspace for staging'
10
- option :container_production, nil, 'The target container on Rackspace for production'
9
+ option :container_staging, nil, 'The target Rackspace container for staging'
10
+ option :container_production, nil, 'The target Rackspace container for production'
11
+ option :branch_staging, 'staging', 'Git branch for staging'
12
+ option :branch_production, 'master', 'Git branch for production'
13
+ option :git, false, 'Checkout environment branch before the build/deploy step'
14
+ option :build, false, 'Run `middleman build` before the deploy step'
11
15
  option :index_file, 'index.html', 'Index filename configuration'
12
16
  option :error_file_prefix, '.html', 'Error filename configuration'
13
- option :build_before, false, 'Run `middleman build` before the deploy step'
14
17
 
15
18
  def initialize(app, options_hash={}, &block)
16
19
  super
@@ -1,7 +1,7 @@
1
1
  module Middleman
2
2
  module Rackspace
3
3
  PACKAGE = 'middleman-rackspace'
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  TAGLINE = 'Deploy your Middleman site to Rackspace Cloud Files'
6
6
  end
7
7
  end
@@ -6,7 +6,7 @@ require 'middleman-rackspace/pkg-info'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = Middleman::Rackspace::PACKAGE
8
8
  s.version = Middleman::Rackspace::VERSION
9
- s.authors = ['David Cristofaro']
9
+ s.author = 'David Cristofaro'
10
10
  s.homepage = 'https://github.com/dtcristo/middleman-rackspace'
11
11
  s.summary = Middleman::Rackspace::TAGLINE
12
12
  s.license = 'MIT'
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_path = 'lib'
18
18
 
19
+ s.required_ruby_version = '>= 2.0'
20
+
19
21
  s.add_runtime_dependency 'middleman-core', '~> 3.4'
20
22
  s.add_runtime_dependency 'fog', '~> 1.35'
21
23
  s.add_runtime_dependency 'typhoeus', '~> 0.8'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-rackspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cristofaro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: '2.0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="