fly.io-rails 0.0.1-x64-mingw32 → 0.0.2-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fly.io-rails/utils.rb +36 -0
- data/lib/fly.io-rails/version.rb +1 -1
- data/lib/fly.io-rails.rb +1 -0
- data/lib/generators/templates/Dockerfile.erb +114 -0
- data/lib/generators/templates/dockerignore.erb +16 -0
- data/lib/generators/templates/fly.rake.erb +23 -0
- data/lib/generators/templates/main.tf.erb +42 -0
- data/lib/generators/terraform_generator.rb +44 -0
- data/lib/tasks/fly.rake +12 -18
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3c28e311b358c82924ee67fbeaa41563ae947e8f7ab678cd92e669dce1af22d
|
4
|
+
data.tar.gz: 3a102a8f1b388dd6369ebbb58545fac05a6fc4b20e7d51713c14043ec35dda39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573b5e778a7001e80a60c73e29ed18fa31d85f58e1b91c2156d9c85cb5fc1dd5cf5049ac038d6bb2428cb5ec3624d754a44567a4721c8b924f3a74443ad71d14
|
7
|
+
data.tar.gz: b0816c934088d44aec1c90384cb2d2e324e062c7a7cc6ef1840919228d2731a6f08e97051eff630271a16230de0bda9815bb97a2a76e8aa2fecdcb88532a4c1b
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module FlyIoRails
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
def tee cmd
|
7
|
+
say_status :run, cmd
|
8
|
+
FlyIoRails::Utils.tee cmd
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.tee cmd
|
12
|
+
data = {:out => [], :err => []}
|
13
|
+
|
14
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
|
15
|
+
{ out: stdout, err: stderr }.each do |key, stream|
|
16
|
+
Thread.new do
|
17
|
+
until (raw_line = stream.gets).nil? do
|
18
|
+
data[key].push raw_line
|
19
|
+
|
20
|
+
if key == :out
|
21
|
+
STDOUT.print raw_line
|
22
|
+
else
|
23
|
+
STDERR.print raw_line
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
thread.join
|
30
|
+
end
|
31
|
+
|
32
|
+
[data[:out].join, data[:err].join]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/fly.io-rails/version.rb
CHANGED
data/lib/fly.io-rails.rb
CHANGED
@@ -0,0 +1,114 @@
|
|
1
|
+
# syntax = docker/dockerfile:experimental
|
2
|
+
|
3
|
+
# Dockerfile used to build a deployable image for a Rails application.
|
4
|
+
# Adjust as required.
|
5
|
+
#
|
6
|
+
# Common adjustments you may need to make over time:
|
7
|
+
# * Modify version numbers for Ruby, Bundler, and other products.
|
8
|
+
# * Add library packages needed at build time for your gems, node modules.
|
9
|
+
# * Add deployment packages needed by your application
|
10
|
+
# * Add (often fake) secrets needed to compile your assets
|
11
|
+
|
12
|
+
#######################################################################
|
13
|
+
|
14
|
+
# Learn more about the chosen Ruby stack, Fullstaq Ruby, here:
|
15
|
+
# https://github.com/evilmartians/fullstaq-ruby-docker.
|
16
|
+
#
|
17
|
+
# We recommend using the highest patch level for better security and
|
18
|
+
# performance.
|
19
|
+
|
20
|
+
ARG RUBY_VERSION=<%= @ruby_version %>
|
21
|
+
ARG VARIANT=jemalloc-slim
|
22
|
+
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base
|
23
|
+
|
24
|
+
ARG BUNDLER_VERSION=<%= @bundler_version %>
|
25
|
+
|
26
|
+
ARG RAILS_ENV=production
|
27
|
+
ENV RAILS_ENV=${RAILS_ENV}
|
28
|
+
|
29
|
+
ENV RAILS_SERVE_STATIC_FILES true
|
30
|
+
ENV RAILS_LOG_TO_STDOUT true
|
31
|
+
|
32
|
+
ARG BUNDLE_WITHOUT=development:test
|
33
|
+
ARG BUNDLE_PATH=vendor/bundle
|
34
|
+
ENV BUNDLE_PATH ${BUNDLE_PATH}
|
35
|
+
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
|
36
|
+
|
37
|
+
RUN mkdir /app
|
38
|
+
WORKDIR /app
|
39
|
+
RUN mkdir -p tmp/pids
|
40
|
+
|
41
|
+
#######################################################################
|
42
|
+
|
43
|
+
# install packages only needed at build time
|
44
|
+
|
45
|
+
FROM base as build_deps
|
46
|
+
|
47
|
+
ARG BUILD_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
|
48
|
+
ENV BUILD_PACKAGES ${BUILD_PACKAGES}
|
49
|
+
|
50
|
+
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
|
51
|
+
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
|
52
|
+
apt-get update -qq && \
|
53
|
+
apt-get install --no-install-recommends -y ${BUILD_PACKAGES} \
|
54
|
+
&& rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
55
|
+
|
56
|
+
#######################################################################
|
57
|
+
|
58
|
+
# install gems
|
59
|
+
|
60
|
+
FROM build_deps as gems
|
61
|
+
|
62
|
+
RUN gem update --system --no-document && \
|
63
|
+
gem install -N bundler -v ${BUNDLER_VERSION}
|
64
|
+
|
65
|
+
COPY Gemfile* ./
|
66
|
+
RUN bundle install && rm -rf vendor/bundle/ruby/*/cache
|
67
|
+
|
68
|
+
#######################################################################
|
69
|
+
|
70
|
+
# install deployment packages
|
71
|
+
|
72
|
+
FROM base
|
73
|
+
|
74
|
+
ARG DEPLOY_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0"
|
75
|
+
ENV DEPLOY_PACKAGES=${DEPLOY_PACKAGES}
|
76
|
+
|
77
|
+
RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
|
78
|
+
--mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
|
79
|
+
apt-get update -qq && \
|
80
|
+
apt-get install --no-install-recommends -y \
|
81
|
+
${DEPLOY_PACKAGES} \
|
82
|
+
&& rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
83
|
+
|
84
|
+
# copy installed gems
|
85
|
+
COPY --from=gems /app /app
|
86
|
+
COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions
|
87
|
+
COPY --from=gems /usr/local/bundle /usr/local/bundle
|
88
|
+
|
89
|
+
#######################################################################
|
90
|
+
|
91
|
+
# Deploy your application
|
92
|
+
COPY . .
|
93
|
+
|
94
|
+
# Adjust binstubs to run on Linux and set current working directory
|
95
|
+
RUN chmod +x /app/bin/* && \
|
96
|
+
sed -i 's/ruby.exe/ruby/' /app/bin/* && \
|
97
|
+
sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*
|
98
|
+
|
99
|
+
# The following enable assets to precompile on the build server. Adjust
|
100
|
+
# as necessary. If no combination works for you, see:
|
101
|
+
# https://fly.io/docs/rails/getting-started/existing/#access-to-environment-variables-at-build-time
|
102
|
+
ENV SECRET_KEY_BASE 1
|
103
|
+
# ENV AWS_ACCESS_KEY_ID=1
|
104
|
+
# ENV AWS_SECRET_ACCESS_KEY=1
|
105
|
+
|
106
|
+
# Run build task defined in lib/tasks/fly.rake
|
107
|
+
ARG BUILD_COMMAND="bin/rails fly:build"
|
108
|
+
RUN ${BUILD_COMMAND}
|
109
|
+
|
110
|
+
# Default server start instructions. Generally Overridden by fly.toml.
|
111
|
+
ENV PORT 8080
|
112
|
+
ARG SERVER_COMMAND="bin/rails fly:server"
|
113
|
+
ENV SERVER_COMMAND ${SERVER_COMMAND}
|
114
|
+
CMD ${SERVER_COMMAND}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# commands used to deploy a Rails application
|
2
|
+
namespace :fly do
|
3
|
+
# BUILD step:
|
4
|
+
# - changes to the filesystem made here DO get deployed
|
5
|
+
# - NO access to secrets, volumes, databases
|
6
|
+
# - Failures here prevent deployment
|
7
|
+
task :build => 'assets:precompile'
|
8
|
+
|
9
|
+
# RELEASE step:
|
10
|
+
# - changes to the filesystem made here are DISCARDED
|
11
|
+
# - full access to secrets, databases
|
12
|
+
# - failures here prevent deployment
|
13
|
+
task :release => 'db:migrate'
|
14
|
+
|
15
|
+
# SERVER step:
|
16
|
+
# - changes to the filesystem made here are deployed
|
17
|
+
# - full access to secrets, databases
|
18
|
+
# - failures here result in VM being stated, shutdown, and rolled back
|
19
|
+
# to last successful deploy (if any).
|
20
|
+
task :server do
|
21
|
+
sh 'bin/rails server'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
terraform {
|
2
|
+
required_providers {
|
3
|
+
fly = {
|
4
|
+
source = "fly-apps/fly"
|
5
|
+
version = "0.0.10"
|
6
|
+
}
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
resource "fly_ip" "<%= @appName %>Ipv4" {
|
11
|
+
app = <%= @app.inspect %>
|
12
|
+
type = "v4"
|
13
|
+
}
|
14
|
+
|
15
|
+
resource "fly_ip" "<%= @appName %>Ipv6" {
|
16
|
+
app = <%= @app.inspect %>
|
17
|
+
type = "v6"
|
18
|
+
}
|
19
|
+
|
20
|
+
resource "fly_machine" "<%= @appName %>Machine" {
|
21
|
+
for_each = toset(<%= @regions.inspect %>)
|
22
|
+
app = <%= @app.inspect %>
|
23
|
+
region = each.value
|
24
|
+
name = "<%= @app %>-${each.value}"
|
25
|
+
image = "quay.io/evl.ms/fullstaq-ruby:<%= @ruby_version %>-jemalloc-slim"
|
26
|
+
services = [
|
27
|
+
{
|
28
|
+
ports = [
|
29
|
+
{
|
30
|
+
port = 443
|
31
|
+
handlers = ["tls", "http"]
|
32
|
+
},
|
33
|
+
{
|
34
|
+
port = 80
|
35
|
+
handlers = ["http"]
|
36
|
+
}
|
37
|
+
]
|
38
|
+
"protocol" : "tcp",
|
39
|
+
"internal_port" : 8080
|
40
|
+
},
|
41
|
+
]
|
42
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
class TerraformGenerator < Rails::Generators::Base
|
4
|
+
include FlyIoRails::Utils
|
5
|
+
|
6
|
+
class_option :name, type: :string, required: false
|
7
|
+
class_option :org, type: :string, default: 'personal'
|
8
|
+
class_option :region, type: :array, repeatable: true, default: []
|
9
|
+
|
10
|
+
def terraform
|
11
|
+
cmd = if options[:name]
|
12
|
+
"flyctl apps create #{options[:name].inspect} --org #{options[:org].inspect}"
|
13
|
+
else
|
14
|
+
"flyctl apps create --generate-name --org #{options[:org].inspect}"
|
15
|
+
end
|
16
|
+
|
17
|
+
output, error = tee cmd
|
18
|
+
exit 1 unless output =~ /^New app created: /
|
19
|
+
|
20
|
+
@app = output.split.last
|
21
|
+
create_file 'fly.toml', "app = #{@app.inspect}\n"
|
22
|
+
|
23
|
+
if options[:region].empty?
|
24
|
+
@regions = JSON.parse(`flyctl regions list --json`)['Regions'].
|
25
|
+
map {|region| region['Code']}
|
26
|
+
else
|
27
|
+
@regions = options[:regions].flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
source_paths.push File.expand_path('./templates', __dir__)
|
31
|
+
|
32
|
+
@ruby_version = RUBY_VERSION
|
33
|
+
@bundler_version = Bundler::VERSION
|
34
|
+
@appName = @app.gsub('-', '_').camelcase(:lower)
|
35
|
+
template 'Dockerfile.erb', 'Dockerfile'
|
36
|
+
template 'dockerignore.erb', '.dockerignore'
|
37
|
+
template 'main.tf.erb', 'main.tf'
|
38
|
+
template 'fly.rake.erb', 'lib/tasks/fly.rake'
|
39
|
+
|
40
|
+
ENV['FLY_API_TOKEN'] = `flyctl auth token`
|
41
|
+
tee 'terraform init'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/tasks/fly.rake
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
namespace :fly do
|
2
|
-
desc 'Launch a new app'
|
3
|
-
task :launch do
|
4
|
-
sh 'flyctl launch'
|
5
|
-
|
6
|
-
# note: Rake task argument syntax isn't particularly user friendy,
|
7
|
-
# but Rake is a Ruby program and we have full access to ARGV,
|
8
|
-
# meaning we can do our own thing with OptionParser or whatever.
|
9
|
-
# The only real caveat if we do so is that we need to exit the
|
10
|
-
# program at the completion of the task lest Rails tries to interpet
|
11
|
-
# the next argument as the name of the next task to execute.
|
12
|
-
|
13
|
-
Rake.rake_output_message 'Customizing Dockerfile...'
|
14
|
-
|
15
|
-
exit
|
16
|
-
end
|
17
|
-
|
18
2
|
desc 'Deploy fly application'
|
19
3
|
task :deploy do
|
20
|
-
|
4
|
+
out, err = FlyIoRails::Utils.tee 'fly deploy --build-only --push'
|
5
|
+
image = err[/image:\s+(.*)/, 1]
|
6
|
+
|
7
|
+
if image
|
8
|
+
tf = IO.read('main.tf')
|
9
|
+
tf[/^\s*image\s*=\s*"(.*?)"/, 1] = image
|
10
|
+
IO.write 'main.tf', tf
|
11
|
+
|
12
|
+
ENV['FLY_API_TOKEN'] = `flyctl auth token`
|
13
|
+
FlyIoRails::Utils.tee 'terraform apply -auto-approve'
|
14
|
+
end
|
21
15
|
end
|
22
16
|
end
|
23
17
|
|
24
18
|
# Alias, for convenience
|
25
19
|
desc 'Deploy fly application'
|
26
|
-
task deploy: 'fly:deploy'
|
20
|
+
task deploy: 'fly:deploy'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fly.io-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: x64-mingw32
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fly-ruby
|
@@ -40,7 +40,13 @@ files:
|
|
40
40
|
- lib/fly.io-rails.rb
|
41
41
|
- lib/fly.io-rails/generators.rb
|
42
42
|
- lib/fly.io-rails/platforms.rb
|
43
|
+
- lib/fly.io-rails/utils.rb
|
43
44
|
- lib/fly.io-rails/version.rb
|
45
|
+
- lib/generators/templates/Dockerfile.erb
|
46
|
+
- lib/generators/templates/dockerignore.erb
|
47
|
+
- lib/generators/templates/fly.rake.erb
|
48
|
+
- lib/generators/templates/main.tf.erb
|
49
|
+
- lib/generators/terraform_generator.rb
|
44
50
|
- lib/tasks/fly.rake
|
45
51
|
homepage: https://github.com/rubys/fly-io.rails
|
46
52
|
licenses:
|
@@ -62,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
68
|
- !ruby/object:Gem::Version
|
63
69
|
version: '0'
|
64
70
|
requirements: []
|
65
|
-
rubygems_version: 3.3.
|
71
|
+
rubygems_version: 3.3.11
|
66
72
|
signing_key:
|
67
73
|
specification_version: 4
|
68
74
|
summary: Rails support for Fly-io
|