middleman-rackspace 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f57344325ea2d681868c5cc1fbcb7e292507a2c8
4
+ data.tar.gz: 226e861fdfe46ebacc13206789a37529a6103a6c
5
+ SHA512:
6
+ metadata.gz: d14cb7e8a21197b4be875ccd135c3ccf0757e503942ef6eeba854feca493f271079f6a611c72da9a943a6bb428c17a8a3955f75d8ca605c56487f0b290dcb6d4
7
+ data.tar.gz: b9b8a4db17f8bc1123439b92665c911bd34f2b99c4be025da43b3e940149b50d47f2d93076b2601d292367987413f420f53072950dda23cedfd60cdcd6d1a149
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2015-11-02)
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-rackspace.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rake'
8
+ gem 'rdoc'
9
+ gem 'yard'
10
+ end
11
+
12
+ group :test do
13
+ gem 'cucumber'
14
+ gem 'aruba'
15
+ gem 'rspec'
16
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 David Cristofaro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Middleman Rackspace
2
+
3
+ Deploy your [Middleman](https://middlemanapp.com/) site to [Rackspace Cloud Files](http://www.rackspace.com/cloud/files).
4
+
5
+ # Usage
6
+
7
+ Add the following to the `Gemfile` for you Middleman project and perform a `bundle install`.
8
+
9
+ ```ruby
10
+ gem 'middleman-rackspace'
11
+ ```
12
+
13
+ After configuration, you can deploy to the configured region and container with:
14
+
15
+ ```
16
+ $ middleman rackspace
17
+ ```
18
+
19
+ An archive `build_TIMESTAMP.tar.gz` is created for your current build and pushed to Rackspace. A new container will automatically be configured if needed. If there is an existing container with the same name, **data will be overwritten**.
20
+
21
+ # Configuration
22
+
23
+ Activate and configure middleman-rackspace by adding an `activate :rackspace` block to `config.rb`. For example:
24
+
25
+ ```ruby
26
+ # Example configuration
27
+ activate :rackspace do |config|
28
+ config.rackspace_username = 'username'
29
+ config.rackspace_api_key = 'a99c75008c3f4ccd31ce67a0674db356'
30
+ config.rackspace_region = :syd
31
+ config.container_name = 'example-site'
32
+ config.build_before = true
33
+ end
34
+ ```
35
+
36
+ Here is a list of all configuration options available with their default values.
37
+
38
+ ```ruby
39
+ # Default configuration
40
+ activate :rackspace do |config|
41
+ # Rackspace credentials
42
+ config.rackspace_username = ENV['RACKSPACE_USERNAME']
43
+ config.rackspace_api_key = ENV['RACKSPACE_API_KEY']
44
+ # The Rackspace region to deploy to
45
+ config.rackspace_region = :dfw
46
+ # The target container on Rackspace
47
+ config.container_name = nil
48
+ # Root page filename
49
+ config.index_file = 'index.html'
50
+ # Error page filename prefix, translates to 401.html and 404.html
51
+ config.error_file_prefix = '.html'
52
+ # Run `middleman build` before the deploy step
53
+ config.build_before = false
54
+ end
55
+ ```
56
+
57
+ 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).
58
+
59
+ # Todo
60
+
61
+ * On deploy, delete files on the server that have been removed from the build.
62
+ * Invalidate cache after deploy.
63
+ * Integrate with git to deploy from a branch.
64
+ * Improve CLI to deploy from a pre-built `build_TIMESTAMP.tar.gz`.
65
+ * Improve error handling.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = "--color --tags ~@wip --strict"
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require 'middleman-core'
3
+ require 'middleman-core/step_definitions'
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-rackspace')
@@ -0,0 +1,41 @@
1
+ require 'middleman-core/cli'
2
+
3
+ module Middleman
4
+ module Cli
5
+ class Rackspace < Thor::Group
6
+ include Thor::Actions
7
+
8
+ check_unknown_options!
9
+
10
+ namespace :rackspace
11
+
12
+ class_option :build_before,
13
+ aliases: '-b',
14
+ type: :boolean,
15
+ #default: false,
16
+ desc: 'Run `middleman build` before the deploy step'
17
+
18
+ # Tell Thor to exit with a non-zero exit code on failure
19
+ def self.exit_on_failure?
20
+ true
21
+ end
22
+
23
+ def rackspace
24
+ # Instantiate Middleman and load config
25
+ app = Middleman::Application.server.inst
26
+
27
+ # Run `middleman build` if specified with '-b' or in 'config.rb'
28
+ build_enabled = options[:build_before] || app.extensions[:rackspace].options.build_before
29
+ if build_enabled
30
+ run('middleman build') || exit(1)
31
+ end
32
+
33
+ # Deploy the built website
34
+ Middleman::Rackspace.deploy(app)
35
+ end
36
+ end
37
+
38
+ # Register 'rackspace' as a Middleman CLI extention
39
+ Base.register(Middleman::Cli::Rackspace, 'rackspace', 'rackspace [options]', Middleman::Rackspace::TAGLINE)
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ require 'fog'
2
+ require 'typhoeus'
3
+
4
+ module Middleman
5
+ module Rackspace
6
+ module_function
7
+
8
+ def deploy(app)
9
+ config = app.extensions[:rackspace].options
10
+ container_name = config.container_name
11
+
12
+ # build_TIMESTAMP.tar.gz
13
+ archive_name = "build_#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.tar.gz"
14
+ puts "Creating archive: #{archive_name}"
15
+
16
+ # Compress /build directory into build_TIMESTAMP.tar.gz
17
+ system("cd ./build && tar -zcvf ../#{archive_name} .")
18
+
19
+ # Configure Fog
20
+ service = Fog::Storage.new({
21
+ provider: 'Rackspace',
22
+ rackspace_username: config.rackspace_username,
23
+ rackspace_api_key: config.rackspace_api_key,
24
+ rackspace_region: config.rackspace_region,
25
+ connection_options: {}
26
+ })
27
+
28
+ # Get or create container
29
+ root_directory = service.directories.get(container_name)
30
+ unless root_directory
31
+ puts "Creating container: #{container_name}"
32
+ # Create the new container
33
+ root_directory = service.directories.create(key: container_name, public: true)
34
+ # Configure container for static site hosting
35
+ # https://developer.rackspace.com/docs/cloud-files/v1/developer-guide/#create-a-static-website
36
+ Typhoeus.post("#{service.endpoint_uri.to_s}/#{container_name}",
37
+ headers: {'X-Auth-Token' => service.send(:auth_token),
38
+ 'X-Container-Meta-Web-Index' => config.index_file,
39
+ 'X-Container-Meta-Web-Error' => config.error_file_prefix})
40
+ end
41
+
42
+ puts "Updating container: #{root_directory.key}"
43
+
44
+ # Upload and extract tar.gz on Rackspace
45
+ # https://developer.rackspace.com/docs/cloud-files/v1/developer-guide/#extracting-archive-files
46
+ service.extract_archive(container_name, File.open(archive_name, 'r'), 'tar.gz')
47
+
48
+ puts "Website live at: #{root_directory.public_url}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ require 'middleman-core'
2
+
3
+ module Middleman
4
+ module Rackspace
5
+ class Extension < Middleman::Extension
6
+ option :rackspace_username, ENV['RACKSPACE_USERNAME'], 'Rackspace username'
7
+ option :rackspace_api_key, ENV['RACKSPACE_API_KEY'], 'Rackspace API key'
8
+ option :rackspace_region, :dfw, 'Rackspace region'
9
+ option :container_name, nil, 'The target container on Rackspace'
10
+ option :index_file, 'index.html', 'Index filename configuration'
11
+ option :error_file_prefix, '.html', 'Error filename configuration'
12
+ option :build_before, false, 'Run `middleman build` before the deploy step'
13
+
14
+ def initialize(app, options_hash={}, &block)
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Middleman
2
+ module Rackspace
3
+ PACKAGE = 'middleman-rackspace'
4
+ VERSION = '0.1.0'
5
+ TAGLINE = 'Deploy your Middleman site to Rackspace Cloud Files'
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'middleman-core'
2
+ require 'middleman-rackspace/pkg-info'
3
+ require 'middleman-rackspace/deploy'
4
+ require 'middleman-rackspace/cli'
5
+ require 'middleman-rackspace/extension'
6
+
7
+ Middleman::Extensions.register(:rackspace) do
8
+ Middleman::Rackspace::Extension
9
+ end
@@ -0,0 +1 @@
1
+ require 'middleman-rackspace'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-rackspace/pkg-info'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = Middleman::Rackspace::PACKAGE
8
+ s.version = Middleman::Rackspace::VERSION
9
+ s.authors = ['David Cristofaro']
10
+ s.homepage = 'https://github.com/dtcristo/middleman-rackspace'
11
+ s.summary = Middleman::Rackspace::TAGLINE
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_path = 'lib'
18
+
19
+ s.add_runtime_dependency 'middleman-core', '~> 3.4'
20
+ s.add_runtime_dependency 'fog', '~> 1.35'
21
+ s.add_runtime_dependency 'typhoeus', '~> 0.8'
22
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-rackspace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Cristofaro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.35'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.35'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ description:
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - CHANGELOG.md
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - features/support/env.rb
68
+ - lib/middleman-rackspace.rb
69
+ - lib/middleman-rackspace/cli.rb
70
+ - lib/middleman-rackspace/deploy.rb
71
+ - lib/middleman-rackspace/extension.rb
72
+ - lib/middleman-rackspace/pkg-info.rb
73
+ - lib/middleman_extension.rb
74
+ - middleman-rackspace.gemspec
75
+ homepage: https://github.com/dtcristo/middleman-rackspace
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Deploy your Middleman site to Rackspace Cloud Files
99
+ test_files:
100
+ - features/support/env.rb
101
+ has_rdoc: