Class: Mobilis::RackProject

Inherits:
GenericProject show all
Defined in:
lib/mobilis/rack_project.rb

Instance Method Summary collapse

Methods inherited from GenericProject

#child_env_vars, #children, #display, #docker_image_name, #env_vars, #generate_build_sh, #git_commit_all, #initialize, #linked_to_rails_project, #links, #options, #parents, #set_links, #type

Methods included from ActionsProjectsTake

#append_line, #oblivious_run_command, #run_command, #run_docker, #set_file_contents, #set_second_line, #write_file

Constructor Details

This class inherits a constructor from Mobilis::GenericProject

Instance Method Details

#generateObject



13
14
15
16
17
18
19
20
21
# File 'lib/mobilis/rack_project.rb', line 13

def generate
  Dir.mkdir name
  Dir.chdir name do
    generate_config_ru
    generate_Gemfile
    generate_Gemfile_lock
    generate_Dockerfile
  end
end

#generate_config_ruObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mobilis/rack_project.rb', line 23

def generate_config_ru
  set_file_contents "config.ru", <<CONFIG_RU
# config.ru
app = Proc.new {
  [
    200,
    { "content-type" => "text/html" },
    ["Hello, Rack"]
  ]
}
run app
CONFIG_RU
end

#generate_DockerfileObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mobilis/rack_project.rb', line 74

def generate_Dockerfile
  set_file_contents "Dockerfile", <<DOCKER_END
FROM ruby:latest
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp

# Add a script to be executed every time the container starts.
ENTRYPOINT ["rackup", "-o", "#{ name }"]
EXPOSE 9292
DOCKER_END
end

#generate_GemfileObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mobilis/rack_project.rb', line 37

def generate_Gemfile
  set_file_contents "Gemfile", <<GEMFILE
# frozen_string_literal: true

source "https://rubygems.org"

# gem "rails"

gem "rack", "= 3.0.0.beta1"

gem "rackup", "~> 0.2.2"
GEMFILE
end

#generate_Gemfile_lockObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mobilis/rack_project.rb', line 51

def generate_Gemfile_lock
  set_file_contents "Gemfile.lock", <<GEMFILE_LOCK
GEM
  remote: https://rubygems.org/
  specs:
    rack (3.0.0.beta1)
    rackup (0.2.2)
      rack (>= 3.0.0.beta1)
      webrick
    webrick (1.7.0)

PLATFORMS
  x64-mingw-ucrt

DEPENDENCIES
  rack (= 3.0.0.beta1)
  rackup (~> 0.2.2)

BUNDLED WITH
   2.3.16
GEMFILE_LOCK
end

#nameObject



9
10
11
# File 'lib/mobilis/rack_project.rb', line 9

def name
  @data[:name]
end