Class: KubyGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/kuby/plugins/rails_app/generators/kuby.rb

Instance Method Summary collapse

Instance Method Details

#create_config_fileObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kuby/plugins/rails_app/generators/kuby.rb', line 16

def create_config_file
  create_file(
    'kuby.rb',
    <<~END
      require 'active_support/core_ext'
      require 'active_support/encrypted_configuration'

      # Define a production Kuby deploy environment
      Kuby.define('#{Rails.application.class.module_parent_name}') do
        environment(:production) do
          # Because the Rails environment isn't always loaded when
          # your Kuby config is loaded, provide access to Rails
          # credentials manually.
          app_creds = ActiveSupport::EncryptedConfiguration.new(
            config_path: File.join('config', 'credentials.yml.enc'),
            key_path: File.join('config', 'master.key'),
            env_key: 'RAILS_MASTER_KEY',
            raise_if_missing_key: true
          )

          docker do
            # Configure your Docker registry credentials here. Add them to your
            # Rails credentials file by running `bundle exec rake credentials:edit`.
            credentials do
              username app_creds[:KUBY_DOCKER_USERNAME]
              password app_creds[:KUBY_DOCKER_PASSWORD]
              email app_creds[:KUBY_DOCKER_EMAIL]
            end

            # Configure the URL to your Docker image here, eg:
            # image_url 'foo.bar.com/me/myproject'
            #
            # If you're using Gitlab's Docker registry, try something like this:
            # image_url 'registry.gitlab.com/<username>/<repo>'
          end

          kubernetes do
            # Add a plugin that facilitates deploying a Rails app.
            add_plugin :rails_app do
              # configure database credentials
              database do
                user app_creds[:KUBY_DB_USER]
                password app_creds[:KUBY_DB_PASSWORD]
              end
            end

            # Use Docker Desktop as the provider.
            # See: https://www.docker.com/products/docker-desktop
            #
            # Note: you will likely want to use a different provider when deploying
            # your application into a production environment. To configure a different
            # provider, add the corresponding gem to your gemfile and update the
            # following line according to the provider gem's README.
            provider :docker_desktop
          end
        end
      end
    END
  )
end

#create_dockerignoreObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kuby/plugins/rails_app/generators/kuby.rb', line 77

def create_dockerignore
  create_file(
    '.dockerignore',
    <<~END
      .bundle/
      vendor/bundle
      node_modules/
      .node_modules/
      **/.git*
      tmp/
      log/
      engines/**/log/
      engines/**/tmp/
      public/assets
    END
  )
end

#create_initializer_fileObject



6
7
8
9
10
11
12
13
14
# File 'lib/kuby/plugins/rails_app/generators/kuby.rb', line 6

def create_initializer_file
  create_file(
    File.join(*%w(config initializers kuby.rb)),
    <<~END
      require 'kuby'
      Kuby.load!
    END
  )
end