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

#add_cockroach_adapterObject



112
113
114
115
116
117
118
# File 'lib/kuby/plugins/rails_app/generators/kuby.rb', line 112

def add_cockroach_adapter
  if Rails::VERSION::STRING > '5.2'
    gem 'activerecord-cockroachdb-adapter', version: '~> 6.0'
  else
    gem 'activerecord-cockroachdb-adapter', version: '~> 5.2'
  end
end

#create_config_fileObject



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
# File 'lib/kuby/plugins/rails_app/generators/kuby.rb', line 17

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('#{app_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

            # 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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/kuby/plugins/rails_app/generators/kuby.rb', line 72

def create_dockerignore
  create_file(
    '.dockerignore',
    <<~END
      .git/

      # Ignore bundler config.
      .bundle

      # Ignore all logfiles and tempfiles.
      log/*
      tmp/*
      !log/.keep
      !tmp/.keep

      # Ignore pidfiles, but keep the directory.
      tmp/pids/*
      !tmp/pids/
      !tmp/pids/.keep

      # Ignore uploaded files in development.
      storage/*
      !storage/.keep

      public/assets
      **/.byebug_history

      # Ignore master key for decrypting credentials and more.
      config/master.key

      public/packs
      public/packs-test
      node_modules
      yarn-error.log
      **/yarn-debug.log*
      **/.yarn-integrity
    END
  )
end

#create_initializer_fileObject



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

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