stan 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ddab58e2d2b7e52c03e69bc75f8599b012aeea2
4
+ data.tar.gz: 7301bcca851f713cbee175ce44f2fdda32eac4d0
5
+ SHA512:
6
+ metadata.gz: fdbc2eb87fd2c1f331aa66809e533252c9780ad19a3378e9542ebb0145358c5fee3c92a9e2e47a14ac77f0e3514003530d725c9ea87bf5c1440c8807e409cf74
7
+ data.tar.gz: 15de19404ade622aa4cfc42aba47193865c0ded5d5e882a9c4c98a78973e98bc39f53a12b834532d4739479ec49a8c783568a09d36174f24a34d99a80a716764
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in roland.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Flipez
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Stan
2
+
3
+ Stan is a little tool that helps you to deploy static sites to a centralized host.
4
+
5
+ ## Installation
6
+ Install Stan with
7
+
8
+ $ gem install stan
9
+
10
+ In order to build the dependencies please make sure you installed the ruby headers.
11
+
12
+ $ apt install ruby-dev
13
+
14
+ ## Usage
15
+
16
+ ```
17
+ Commands:
18
+ stan compress DIRECTORY # compress given directory
19
+ stan deploy DIRECTORY NAME # deploys given directory to stan server
20
+ stan help [COMMAND] # Describe available commands or one specific command
21
+ stan server # start the server to receive and serve pages
22
+ stan version # display the stan version
23
+ ```
24
+
25
+ There are a few variables you have to set:
26
+
27
+ ### Server
28
+
29
+ `STAN_UPLOAD_DIR=/tmp/stan/upload` is the directory where Stan will temporarly store sites before deploying them.
30
+ `STAN_PUBLIC_DIR=/srv/stan` is the directory where the final site will be deployed.
31
+
32
+ Please note that Stan will create a public directory and a directory for each deployed site within that folder.
33
+ The final site will then be deployed to `/srv/stan/public/my-site` for example.
34
+
35
+ ### Client
36
+
37
+ `STAN_SERVER=pages.example.com` is the URL of the remote Stan server which must expose the `/upload` route. Define ports like usual.
38
+ `STAN_TEMP_DIR=/tmp/stan` is the directory where Stan will store the site after compressing it. The archive will be removed after upload.
39
+
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Flipez/static-stan.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "roland"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/stan ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require_relative '../lib/stan'
4
+ require_relative '../lib/stan/cli'
5
+ Stan::Cli.start(ARGV)
data/lib/stan/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Stan
2
+ class Cli < Thor
3
+ desc 'version', 'display the stan version'
4
+ def version
5
+ puts('Stan version ' + Stan::VERSION.to_s)
6
+ end
7
+
8
+ desc 'compress DIRECTORY', 'compress given directory'
9
+ def compress(dir)
10
+ c = Stan::Compressor.new(dir)
11
+ c.compress
12
+ end
13
+
14
+ desc 'server', 'start the server to receive and serve pages'
15
+ def server
16
+ Stan::Server.run!
17
+ end
18
+
19
+ desc 'deploy DIRECTORY NAME', 'deploys given directory to stan server'
20
+ def deploy(dir, name)
21
+ c = Stan::Compressor.new(dir)
22
+ c.compress
23
+ file = c.output
24
+ Stan::Deployer.deploy(file, name)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ module Stan
2
+ class Compressor
3
+ attr_reader :path, :output, :size
4
+
5
+ def initialize(dir)
6
+ @tempdir = ENV.fetch('STAN_TEMP_DIR')
7
+ @path = File.path(dir)
8
+ end
9
+
10
+ def compress
11
+ FileUtils.mkdir_p(@tempdir)
12
+ date = DateTime.now.strftime('%Y%m%d%H%M%S')
13
+ @output = "#{@tempdir}/#{date}.tar.gz"
14
+
15
+ Dir.chdir(path) do
16
+ `tar -czf #{output} .`
17
+ end
18
+
19
+ @size = File.size(output) / 2**20
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'typhoeus'
2
+ module Stan
3
+ class Deployer
4
+ def self.deploy(source, name, keep: false)
5
+ url = ENV.fetch('STAN_SERVER')
6
+ Typhoeus.post(
7
+ "#{url}/upload",
8
+ body: {
9
+ name: name,
10
+ file: File.open(source,"r")
11
+ }
12
+ )
13
+ FileUtils.rm(source) unless keep
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ require 'sinatra'
2
+ module Stan
3
+ class Server < Sinatra::Base
4
+ upload_dir = ENV.fetch('STAN_UPLOAD_DIR')
5
+ public_dir = ENV.fetch('STAN_PUBLIC_DIR')
6
+ post '/upload' do
7
+ name = params['name']
8
+ filename = params['file']['filename']
9
+ tempfile = params['file']['tempfile']
10
+ FileUtils.mkdir_p(upload_dir)
11
+ filepath = "#{upload_dir}/#{filename}"
12
+ while blk = tempfile.read(65536)
13
+ File.open(filepath, 'wb') do |f|
14
+ f.write(blk)
15
+ end
16
+ end
17
+ FileUtils.mkdir_p("#{public_dir}/#{name}")
18
+ Dir.chdir("#{public_dir}/#{name}") do
19
+ `tar -xzf #{filepath} .`
20
+ end
21
+ FileUtils.rm(filepath)
22
+ "Upload complete"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Stan
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/stan.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'stan/version'
2
+ module Stan
3
+ autoload :Server, 'stan/server'
4
+ autoload :Compressor, 'stan/compressor'
5
+ autoload :Deployer, 'stan/deployer'
6
+ end
data/stan.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stan'
8
+ spec.version = Stan::VERSION
9
+ spec.authors = ['Flipez']
10
+ spec.email = ['code@brauser.io']
11
+
12
+ spec.summary = 'Static Site Deployment'
13
+ spec.description = 'Deploy your static sites easy with Stan'
14
+ spec.homepage = 'https://github.com/Flipez/static-stan'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'typhoeus'
25
+ spec.add_dependency 'thor'
26
+ spec.add_dependency 'sinatra'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.13'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Flipez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
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: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Deploy your static sites easy with Stan
84
+ email:
85
+ - code@brauser.io
86
+ executables:
87
+ - stan
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - exe/stan
99
+ - lib/stan.rb
100
+ - lib/stan/cli.rb
101
+ - lib/stan/compressor.rb
102
+ - lib/stan/deployer.rb
103
+ - lib/stan/server.rb
104
+ - lib/stan/version.rb
105
+ - stan.gemspec
106
+ homepage: https://github.com/Flipez/static-stan
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Static Site Deployment
130
+ test_files: []