Class: Chagall::Settings
- Inherits:
-
Object
- Object
- Chagall::Settings
- Includes:
- Singleton
- Defined in:
- lib/chagall/settings.rb
Constant Summary collapse
- CHAGALL_PROJECTS_FOLDER =
"~/projects"- OPTIONS =
[ { key: :log_level, flags: [ "--log-level" ], description: "Log level", type: :string, default: "info", environment_variable: "CHAGALL_LOG_LEVEL" }, { key: :skip_uncommit, flags: [ "--skip-uncommit" ], description: "Skip uncommitted changes check", type: :boolean, default: false, environment_variable: "CHAGALL_SKIP_UNCOMMIT" }, { key: :server, flags: [ "-s", "--server" ], description: "Server to deploy to", type: :string, required: true, environment_variable: "CHAGALL_SERVER" }, { key: :name, flags: [ "-n", "--name" ], description: "Project name", type: :string, default: Pathname.new(Dir.pwd).basename.to_s, environment_variable: "CHAGALL_NAME" }, { key: :release, flags: [ "--release" ], description: "Release tag", required: true, default: `git rev-parse --short HEAD`.strip, type: :string, environment_variable: "CHAGALL_RELEASE" }, { key: :dry_run, type: :boolean, default: false, flags: [ "-d", "--dry-run" ], environment_variable: "CHAGALL_DRY_RUN", description: "Dry run" }, { key: :remote, flags: [ "-r", "--remote" ], description: "Deploy remotely (build on remote server)", type: :boolean, default: false, environment_variable: "CHAGALL_REMOTE" }, { key: :compose_files, flags: [ "-c", "--compose-files" ], description: "Comma separated list of compose files", type: :array, required: true, environment_variable: "CHAGALL_COMPOSE_FILES", proc: ->(value) { value.split(",") } }, { key: :target, type: :string, default: "production", flags: [ "--target" ], environment_variable: "CHAGALL_TARGET", description: "Target" }, { key: :dockerfile, type: :string, flags: [ "-f", "--dockerfile" ], default: "Dockerfile", environment_variable: "CHAGALL_DOCKERFILE", description: "Dockerfile" }, { key: :projects_folder, type: :string, default: CHAGALL_PROJECTS_FOLDER, flags: [ "-p", "--projects-folder" ], environment_variable: "CHAGALL_PROJECTS_FOLDER", description: "Projects folder" }, { key: :cache_from, type: :string, default: "tmp/.buildx-cache", flags: [ "--cache-from" ], environment_variable: "CHAGALL_CACHE_FROM", description: "Cache from" }, { key: :cache_to, type: :string, default: "tmp/.buildx-cache-new", flags: [ "--cache-to" ], environment_variable: "CHAGALL_CACHE_TO", description: "Cache to" }, { key: :keep_releases, type: :integer, default: 3, flags: [ "-k", "--keep-releases" ], environment_variable: "CHAGALL_KEEP_RELEASES", description: "Keep releases", proc: ->(value) { Integer(value) } }, { key: :ssh_args, type: :string, default: "-o StrictHostKeyChecking=no", environment_variable: "CHAGALL_SSH_ARGS", flags: [ "--ssh-args" ], description: "SSH arguments" }, { key: :docker_context, type: :string, flags: [ "--docker-context" ], environment_variable: "CHAGALL_DOCKER_CONTEXT", default: ".", description: "Docker context" }, { key: :platform, type: :string, flags: [ "--platform" ], environment_variable: "CHAGALL_PLATFORM", default: "linux/x86_64", description: "Platform" } ].freeze
Instance Attribute Summary collapse
-
#missing_compose_files ⇒ Object
Returns the value of attribute missing_compose_files.
-
#missing_options ⇒ Object
Returns the value of attribute missing_options.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #configure(parsed_options) ⇒ Object
- #image_tag ⇒ Object
- #project_folder_path ⇒ Object
- #validate_options ⇒ Object
Instance Attribute Details
#missing_compose_files ⇒ Object
Returns the value of attribute missing_compose_files.
10 11 12 |
# File 'lib/chagall/settings.rb', line 10 def missing_compose_files @missing_compose_files end |
#missing_options ⇒ Object
Returns the value of attribute missing_options.
10 11 12 |
# File 'lib/chagall/settings.rb', line 10 def @missing_options end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/chagall/settings.rb', line 10 def @options end |
Class Method Details
.[](key) ⇒ Object
159 160 161 |
# File 'lib/chagall/settings.rb', line 159 def [](key) instance.[key] end |
.configure(argv) ⇒ Object
155 156 157 |
# File 'lib/chagall/settings.rb', line 155 def configure(argv) instance.configure(argv) end |
Instance Method Details
#configure(parsed_options) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/chagall/settings.rb', line 164 def configure() @options = @missing_options = [] @missing_compose_files = [] end |
#image_tag ⇒ Object
203 204 205 |
# File 'lib/chagall/settings.rb', line 203 def image_tag @image_tag ||= "#{[:name]}:#{[:release]}" end |
#project_folder_path ⇒ Object
207 208 209 |
# File 'lib/chagall/settings.rb', line 207 def project_folder_path @project_folder_path ||= "#{[:projects_folder]}/#{[:name]}" end |
#validate_options ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/chagall/settings.rb', line 172 def = "\n" OPTIONS.each do |option| @missing_options << option if option[:required] && @options[option[:key]].to_s.empty? end if @missing_options.any? += " Missing required options: #{@missing_options.map { |o| o[:key] }.join(', ')}\n" += " These can be set via:\n" += " - CLI arguments (#{@missing_options.map { |o| o[:flags] }.join(', ')})\n" += " - Environment variables (#{@missing_options.map do |o| o[:environment_variable] || o[:env_name] end.join(', ')})\n" += " - chagall.yml file\n" end if @options[:compose_files] @options[:compose_files].each do |file| unless File.exist?(file) @missing_compose_files << file += " Missing compose file: #{file}\n" end end end return unless @missing_options.any? || @missing_compose_files.any? raise Chagall::SettingsError, unless @options[:dry_run] end |