vps 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/VERSION +1 -1
- data/lib/vps/cli.rb +1 -0
- data/lib/vps/cli/upstream.rb +24 -18
- data/lib/vps/core_ext/ostruct.rb +17 -0
- data/lib/vps/version.rb +1 -1
- data/playbooks/deploy/docker.yml +2 -2
- data/templates/docker/data/nginx/app.conf.erb +16 -3
- data/templates/docker/docker-compose.yml.erb +14 -12
- data/templates/docker/upstream/Dockerfile.phoenix.erb +1 -1
- data/templates/docker/upstream/Dockerfile.plug.erb +1 -1
- data/templates/docker/upstream/Dockerfile.rack.erb +3 -2
- data/templates/docker/upstream/Dockerfile.rails.erb +4 -1
- data/templates/docker/upstream/init-letsencrypt.sh.erb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 591e2f6174b369e271f23bc60b9d9492045259f3
|
4
|
+
data.tar.gz: 5b325e542fbacd8a0cf33df939c58db68c17995b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07edf2782cd06c64ad79478dfc51c168552822530083f3170dd702fc46aec3f61600390abb8846cfe1ce7de021f48e5f27a39f1530cfd2cca75ef859c42ce67e
|
7
|
+
data.tar.gz: 7b59c311ae6fda27227c2128c4dbf26338b6a2e8f4740e49b05cb321b24eb28f2d78d45eaf53e58c28b8d3360abeaf02a5d3cfc2c64572af81ed8bb3cd136f0d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## VPS CHANGELOG
|
2
2
|
|
3
|
+
### Version 0.1.2 (September 29, 2019)
|
4
|
+
|
5
|
+
* Run postload tasks at the end of deployment
|
6
|
+
* Fix generating Rails and Rack Dockerfile (installing the correct Bundler version)
|
7
|
+
* Include configured :services in the generated docker-compose.yml file
|
8
|
+
|
3
9
|
### Version 0.1.1 (August 12, 2019)
|
4
10
|
|
5
11
|
* Initial release
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/vps/cli.rb
CHANGED
data/lib/vps/cli/upstream.rb
CHANGED
@@ -9,18 +9,15 @@ module VPS
|
|
9
9
|
path = File.expand_path(path)
|
10
10
|
|
11
11
|
unless config[:upstreams].any?{|upstream| upstream[:name] == name}
|
12
|
-
|
13
|
-
|
12
|
+
spec = derive_upstream(path)
|
13
|
+
spec[:nginx] ||= nil
|
14
|
+
config[:upstreams].push(spec.merge({
|
14
15
|
:name => name || File.basename(path),
|
15
16
|
:path => path,
|
16
|
-
:type => type,
|
17
|
-
:tool_version => tool_version,
|
18
|
-
:port => port,
|
19
17
|
:domains => [],
|
20
18
|
:email => nil,
|
21
|
-
:compose => nil
|
22
|
-
|
23
|
-
})
|
19
|
+
:compose => nil
|
20
|
+
}))
|
24
21
|
VPS.write_config(host, config)
|
25
22
|
end
|
26
23
|
end
|
@@ -65,19 +62,28 @@ module VPS
|
|
65
62
|
|> IO.puts()
|
66
63
|
ELIXIR
|
67
64
|
type = `cd #{path} && mix run -e "#{elixir.strip.gsub(/\n\s+/, " ")}" | tail -n 1`.strip
|
68
|
-
|
69
|
-
type,
|
70
|
-
`cd #{path} && mix run -e "System.version() |> IO.puts()" | tail -n 1`.strip,
|
71
|
-
(type == "phoenix") ? 4000 : `cd #{path} && mix run -e ":ranch.info |> hd() |> elem(0) |> :ranch.get_port() |> IO.puts()" | tail -n 1`.strip.to_i
|
72
|
-
|
65
|
+
{
|
66
|
+
type: type,
|
67
|
+
elixir_version: `cd #{path} && mix run -e "System.version() |> IO.puts()" | tail -n 1`.strip,
|
68
|
+
port: (type == "phoenix") ? 4000 : `cd #{path} && mix run -e ":ranch.info |> hd() |> elem(0) |> :ranch.get_port() |> IO.puts()" | tail -n 1`.strip.to_i
|
69
|
+
}
|
73
70
|
elsif Dir["#{path}/Gemfile"].any?
|
74
71
|
lines = `cd #{path} && BUNDLE_GEMFILE=#{path}/Gemfile bundle list`.split("\n")
|
75
72
|
type = %w(rails rack).detect{|gem| lines.any?{|line| line.include?("* #{gem} (")}}
|
76
|
-
|
77
|
-
type,
|
78
|
-
`$SHELL -l -c 'cd #{path} && ruby -e "puts RUBY_VERSION"'`.strip,
|
79
|
-
|
80
|
-
|
73
|
+
{
|
74
|
+
type: type,
|
75
|
+
ruby_version: `$SHELL -l -c 'cd #{path} && ruby -e "puts RUBY_VERSION"'`.strip,
|
76
|
+
bundler_version: `$SHELL -l -c 'cd #{path} && bundle -v'`.split.last,
|
77
|
+
port: (type == "rails" ? 3000 : 9292) # :'(
|
78
|
+
}.tap do |spec|
|
79
|
+
if type == "rails"
|
80
|
+
spec[:nginx] = {
|
81
|
+
root: "/opt/app/public",
|
82
|
+
try_files: true,
|
83
|
+
proxy_redirect: "off"
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class OpenStruct
|
2
|
+
def self.to_hash(object, hash = {})
|
3
|
+
case object
|
4
|
+
when OpenStruct then
|
5
|
+
object.each_pair do |key, value|
|
6
|
+
hash[key.to_s] = to_hash(value)
|
7
|
+
end
|
8
|
+
hash
|
9
|
+
when Array then
|
10
|
+
object.collect do |value|
|
11
|
+
to_hash(value)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
object
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/vps/version.rb
CHANGED
data/playbooks/deploy/docker.yml
CHANGED
@@ -86,11 +86,11 @@ tasks:
|
|
86
86
|
command:
|
87
87
|
- chmod +x {{ release_path }}/init-letsencrypt/{{ upstream.name }}.sh
|
88
88
|
- cd {{ release_path }} && if [ ! -d "data/certbot/conf/live/{{ domain:upstream }}" ]; then yes Y | sudo ./init-letsencrypt/{{ upstream.name }}.sh; fi
|
89
|
-
- task: run_tasks
|
90
|
-
tasks: << postload >>
|
91
89
|
- description: Starting containers
|
92
90
|
task: remote_execute
|
93
91
|
command: cd {{ release_path }} && docker-compose up {{ up }} -d
|
94
92
|
- description: Checking running docker images
|
95
93
|
task: remote_execute
|
96
94
|
command: docker ps
|
95
|
+
- task: run_tasks
|
96
|
+
tasks: << postload >>
|
@@ -8,14 +8,17 @@ upstream <%= upstream[:name] %> {
|
|
8
8
|
https = domains.first.include?("https://")
|
9
9
|
domains = domains.collect{|domain| domain.gsub(/https?:\/\//, "")}.join(" ")
|
10
10
|
domain = domains.split(" ")[0]
|
11
|
+
nginx = upstream[:nginx] || {}
|
11
12
|
proxy_pass = "http://#{ upstream[:name] }"
|
12
13
|
%>
|
13
14
|
|
14
15
|
server {
|
16
|
+
<%- unless domains.empty? %>
|
15
17
|
listen 80;
|
16
18
|
server_name <%= domains %>;
|
17
19
|
server_tokens off;
|
18
20
|
|
21
|
+
<%- end %>
|
19
22
|
<%- if https %>
|
20
23
|
location /.well-known/acme-challenge/ {
|
21
24
|
root /var/www/certbot;
|
@@ -37,15 +40,25 @@ server {
|
|
37
40
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
38
41
|
|
39
42
|
<%- end %>
|
40
|
-
<%- if
|
41
|
-
<%=
|
43
|
+
<%- if nginx[:root] %>
|
44
|
+
root <%= nginx[:root] %>;
|
45
|
+
<%- end %>
|
46
|
+
<%- if nginx[:try_files] %>
|
47
|
+
try_files $uri @app;
|
42
48
|
|
43
49
|
<%- end %>
|
44
|
-
|
50
|
+
<%- if nginx[:config] %>
|
51
|
+
<%= nginx[:config].gsub("PROXY_PASS", proxy_pass).indent(2) %>
|
52
|
+
|
53
|
+
<%- end %>
|
54
|
+
location <%= nginx[:try_files] ? "@app" : "/" %> {
|
45
55
|
proxy_pass <%= proxy_pass %>;
|
46
56
|
proxy_set_header Host $http_host;
|
47
57
|
proxy_set_header X-Real-IP $remote_addr;
|
48
58
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
59
|
+
<%- if nginx[:proxy_redirect] %>
|
60
|
+
proxy_redirect <%= nginx[:proxy_redirect] %>;
|
61
|
+
<%- end %>
|
49
62
|
}
|
50
63
|
}
|
51
64
|
<%- end %>
|
@@ -1,10 +1,5 @@
|
|
1
1
|
version: "3"
|
2
|
-
<%
|
3
|
-
https = upstreams.any?{|upstream| upstream[:domains].any?{|domain| domain.include?("https://")}}
|
4
|
-
to_yaml = proc do |struct|
|
5
|
-
struct.to_h.inject({}){|h, (k, v)| h[k.to_s] = v; h}.to_yaml
|
6
|
-
end
|
7
|
-
%>
|
2
|
+
<% https = upstreams.any?{|upstream| upstream[:domains].any?{|domain| domain.include?("https://")}} %>
|
8
3
|
services:
|
9
4
|
|
10
5
|
nginx:
|
@@ -28,7 +23,7 @@ services:
|
|
28
23
|
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
|
29
24
|
|
30
25
|
certbot:
|
31
|
-
image: certbot/certbot
|
26
|
+
image: certbot/certbot:v0.27.1
|
32
27
|
container_name: certbot
|
33
28
|
restart: unless-stopped
|
34
29
|
volumes:
|
@@ -36,6 +31,11 @@ services:
|
|
36
31
|
- ./data/certbot/www:/var/www/certbot
|
37
32
|
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
|
38
33
|
<%- end %>
|
34
|
+
<%- services.to_h.each do |name, spec| %>
|
35
|
+
|
36
|
+
<%= name %>:
|
37
|
+
<%= OpenStruct.to_hash(spec).to_yaml.sub(/^.*?\n/, "").indent(4) %>
|
38
|
+
<%- end %>
|
39
39
|
<%- upstreams.each do |upstream| %>
|
40
40
|
|
41
41
|
<%= upstream.name %>:
|
@@ -46,11 +46,13 @@ services:
|
|
46
46
|
- <%= upstream.port %>
|
47
47
|
<%- end %>
|
48
48
|
<%- if upstream[:compose] %>
|
49
|
-
<%=
|
49
|
+
<%= OpenStruct.to_hash(upstream[:compose]).to_yaml.sub(/^.*?\n/, "").indent(4) %>
|
50
50
|
<%- end %>
|
51
51
|
<%- end %>
|
52
|
-
|
52
|
+
<%- unless (volumes || []).empty? %>
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
volumes:
|
55
|
+
<%- volumes.each do |volume| %>
|
56
|
+
<%= volume %>:
|
57
|
+
<%- end %>
|
58
|
+
<%- end %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:<%= upstream.
|
1
|
+
FROM ruby:<%= upstream.ruby_version %>-alpine
|
2
2
|
|
3
3
|
RUN apk update \
|
4
4
|
&& apk --no-cache --update add \
|
@@ -11,5 +11,6 @@ WORKDIR /opt/app
|
|
11
11
|
COPY . .
|
12
12
|
|
13
13
|
ENV RACK_ENV=production
|
14
|
+
RUN gem install bundler -v <%= upstream.bundler_version %>
|
14
15
|
RUN bundle install --without development test
|
15
|
-
CMD ["rackup", "config.ru", "-o", "0.0.0.0"]
|
16
|
+
CMD ["bundle", "exec", "rackup", "config.ru", "-o", "0.0.0.0"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:<%= upstream.
|
1
|
+
FROM ruby:<%= upstream.ruby_version %>-alpine
|
2
2
|
|
3
3
|
RUN apk update \
|
4
4
|
&& apk --no-cache --update add \
|
@@ -11,5 +11,8 @@ WORKDIR /opt/app
|
|
11
11
|
COPY . .
|
12
12
|
|
13
13
|
ENV RAILS_ENV=production
|
14
|
+
EXPOSE <%= upstream.port %>
|
15
|
+
RUN gem install bundler -v <%= upstream.bundler_version %>
|
14
16
|
RUN bundle install --without development test
|
17
|
+
CMD ["rm", "-f", "tmp/pids/server.pid"]
|
15
18
|
CMD ["rails", "server", "-b", "0.0.0.0"]
|
@@ -17,8 +17,8 @@ fi
|
|
17
17
|
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
|
18
18
|
echo "### Downloading recommended TLS parameters ..."
|
19
19
|
mkdir -p "$data_path/conf"
|
20
|
-
curl -s https://raw.githubusercontent.com/certbot/certbot/
|
21
|
-
curl -s https://raw.githubusercontent.com/certbot/certbot/
|
20
|
+
curl -s https://raw.githubusercontent.com/certbot/certbot/v0.40.1/certbot-nginx/certbot_nginx/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
|
21
|
+
curl -s https://raw.githubusercontent.com/certbot/certbot/v0.40.1/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
|
22
22
|
echo
|
23
23
|
fi
|
24
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Engel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/vps/cli/playbook/tasks.rb
|
163
163
|
- lib/vps/cli/service.rb
|
164
164
|
- lib/vps/cli/upstream.rb
|
165
|
+
- lib/vps/core_ext/ostruct.rb
|
165
166
|
- lib/vps/core_ext/string.rb
|
166
167
|
- lib/vps/version.rb
|
167
168
|
- playbooks/deploy.yml
|