shopify-cli 2.6.3 → 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +15 -4
  3. data/.github/workflows/shopify.yml +3 -6
  4. data/CHANGELOG.md +71 -102
  5. data/Dockerfile +12 -2
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +5 -3
  8. data/RELEASING.md +17 -30
  9. data/Rakefile +0 -5
  10. data/lib/project_types/extension/features/argo.rb +8 -2
  11. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +1 -1
  12. data/lib/project_types/extension/models/specification_handlers/checkout_ui_extension.rb +1 -1
  13. data/lib/project_types/node/commands/serve.rb +7 -16
  14. data/lib/project_types/node/messages/messages.rb +0 -5
  15. data/lib/project_types/php/commands/serve.rb +6 -9
  16. data/lib/project_types/php/messages/messages.rb +1 -4
  17. data/lib/project_types/rails/commands/serve.rb +7 -8
  18. data/lib/project_types/rails/messages/messages.rb +1 -4
  19. data/lib/project_types/script/commands/create.rb +3 -1
  20. data/lib/project_types/script/config/extension_points.yml +7 -0
  21. data/lib/project_types/script/graphql/app_script_set.graphql +2 -0
  22. data/lib/project_types/script/layers/application/build_script.rb +2 -1
  23. data/lib/project_types/script/layers/application/push_script.rb +15 -1
  24. data/lib/project_types/script/layers/domain/push_package.rb +5 -2
  25. data/lib/project_types/script/layers/infrastructure/errors.rb +17 -0
  26. data/lib/project_types/script/layers/infrastructure/languages/assemblyscript_task_runner.rb +10 -13
  27. data/lib/project_types/script/layers/infrastructure/languages/typescript_task_runner.rb +4 -13
  28. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +4 -2
  29. data/lib/project_types/script/layers/infrastructure/script_service.rb +6 -1
  30. data/lib/project_types/script/messages/messages.rb +6 -0
  31. data/lib/project_types/script/ui/error_handler.rb +16 -0
  32. data/lib/project_types/theme/commands/serve.rb +1 -0
  33. data/lib/project_types/theme/messages/messages.rb +5 -0
  34. data/lib/shopify_cli/app_type_detector.rb +32 -0
  35. data/lib/shopify_cli/command.rb +6 -1
  36. data/lib/shopify_cli/command_options/command_serve_options.rb +43 -0
  37. data/lib/shopify_cli/command_options.rb +7 -0
  38. data/lib/shopify_cli/commands/login.rb +3 -3
  39. data/lib/shopify_cli/commands/reporting.rb +38 -0
  40. data/lib/shopify_cli/commands/switch.rb +1 -1
  41. data/lib/shopify_cli/commands.rb +1 -0
  42. data/lib/shopify_cli/constants.rb +7 -3
  43. data/lib/shopify_cli/core/monorail.rb +9 -20
  44. data/lib/shopify_cli/environment.rb +15 -1
  45. data/lib/shopify_cli/exception_reporter.rb +24 -13
  46. data/lib/shopify_cli/messages/messages.rb +48 -19
  47. data/lib/shopify_cli/migrator/migration.rb +1 -1
  48. data/lib/shopify_cli/migrator/migrations/1631709766_noop.rb +1 -1
  49. data/lib/shopify_cli/migrator/migrations/1633691650_merge_reporting_configuration.rb +41 -0
  50. data/lib/shopify_cli/reporting_configuration_controller.rb +64 -0
  51. data/lib/shopify_cli/services/base_service.rb +13 -0
  52. data/lib/shopify_cli/services/reporting_service.rb +16 -0
  53. data/lib/shopify_cli/services.rb +6 -0
  54. data/lib/shopify_cli/theme/dev_server/watcher.rb +2 -2
  55. data/lib/shopify_cli/theme/dev_server.rb +2 -2
  56. data/lib/shopify_cli/version.rb +1 -1
  57. data/lib/shopify_cli.rb +4 -0
  58. data/shopify-cli.gemspec +1 -8
  59. data/utilities/docker/container.rb +76 -0
  60. data/utilities/docker.rb +44 -3
  61. metadata +14 -5
  62. data/lib/shopify_cli/exception_reporter/permission_controller.rb +0 -54
@@ -16,9 +16,6 @@ module ShopifyCLI
16
16
  attr_accessor :metadata
17
17
 
18
18
  def log(name, args, &block) # rubocop:disable Lint/UnusedMethodArgument
19
- prompt_for_consent
20
- return yield unless enabled? && consented?
21
-
22
19
  command, command_name = Commands::Registry.lookup_command(name)
23
20
  final_command = [command_name]
24
21
  if command
@@ -28,13 +25,18 @@ module ShopifyCLI
28
25
 
29
26
  start_time = now_in_milliseconds
30
27
  err = nil
28
+
31
29
  begin
32
30
  yield
33
31
  rescue Exception => e # rubocop:disable Lint/RescueException
34
32
  err = e
35
33
  raise
36
34
  ensure
37
- send_event(start_time, final_command, args - final_command, err&.message)
35
+ # If there's an error, we don't prompt from here and we let the exception
36
+ # reporter do that.
37
+ if report?(prompt: err.nil?)
38
+ send_event(start_time, final_command, args - final_command, err&.message)
39
+ end
38
40
  end
39
41
  end
40
42
 
@@ -44,22 +46,9 @@ module ShopifyCLI
44
46
  (Time.now.utc.to_f * 1000).to_i
45
47
  end
46
48
 
47
- # we only want to send Monorail events in production or when explicitly developing
48
- def enabled?
49
- (Context.new.system? || ENV["MONORAIL_REAL_EVENTS"] == "1") && !Context.new.ci?
50
- end
51
-
52
- def consented?
53
- ShopifyCLI::Config.get_bool("analytics", "enabled")
54
- end
55
-
56
- def prompt_for_consent
57
- return if Context.new.ci?
58
- return unless enabled?
59
- return if ShopifyCLI::Config.get_section("analytics").key?("enabled")
60
- msg = Context.message("core.monorail.consent_prompt")
61
- opt = CLI::UI::Prompt.confirm(msg)
62
- ShopifyCLI::Config.set("analytics", "enabled", opt)
49
+ def report?(prompt:)
50
+ return true if Environment.send_monorail_events?
51
+ ReportingConfigurationController.check_or_prompt_report_automatically(source: :usage, prompt: prompt)
63
52
  end
64
53
 
65
54
  def send_event(start_time, commands, args, err = nil)
@@ -26,7 +26,7 @@ module ShopifyCLI
26
26
  env_variable_truthy?(
27
27
  Constants::EnvironmentVariables::STACKTRACE,
28
28
  env_variables: env_variables
29
- )
29
+ ) || development?(env_variables: env_variables)
30
30
  end
31
31
 
32
32
  def self.test?(env_variables: ENV)
@@ -36,6 +36,13 @@ module ShopifyCLI
36
36
  )
37
37
  end
38
38
 
39
+ def self.acceptance_test?(env_variables: ENV)
40
+ env_variable_truthy?(
41
+ Constants::EnvironmentVariables::ACCEPTANCE_TEST,
42
+ env_variables: env_variables
43
+ )
44
+ end
45
+
39
46
  def self.print_backtrace?(env_variables: ENV)
40
47
  env_variable_truthy?(
41
48
  Constants::EnvironmentVariables::BACKTRACE,
@@ -72,6 +79,13 @@ module ShopifyCLI
72
79
  "#{spin_workspace}.#{spin_namespace}.#{spin_host}"
73
80
  end
74
81
 
82
+ def self.send_monorail_events?(env_variables: ENV)
83
+ env_variable_truthy?(
84
+ Constants::EnvironmentVariables::MONORAIL_REAL_EVENTS,
85
+ env_variables: env_variables
86
+ )
87
+ end
88
+
75
89
  def self.env_variable_truthy?(variable_name, env_variables: ENV)
76
90
  TRUTHY_ENV_VARIABLE_VALUES.include?(env_variables[variable_name.to_s])
77
91
  end
@@ -1,20 +1,23 @@
1
1
  module ShopifyCLI
2
2
  module ExceptionReporter
3
- autoload :PermissionController, "shopify_cli/exception_reporter/permission_controller"
4
-
5
3
  def self.report(error, _logs = nil, _api_key = nil, custom_metadata = {})
6
4
  context = ShopifyCLI::Context.new
7
- context.puts("\n")
8
- context.puts(context.message("core.error_reporting.unhandled_error.message"))
9
- context.puts(context.message("core.error_reporting.unhandled_error.issue_message"))
5
+
6
+ unless ShopifyCLI::Environment.development?
7
+ context.puts(context.message("core.error_reporting.unhandled_error.message"))
8
+ context.puts(context.message("core.error_reporting.unhandled_error.issue_message"))
9
+ end
10
+
11
+ # Stack trace hint
10
12
  unless ShopifyCLI::Environment.print_stacktrace?
11
13
  context.puts(context.message("core.error_reporting.unhandled_error.stacktrace_message",
12
14
  "#{ShopifyCLI::Constants::EnvironmentVariables::STACKTRACE}=1"))
13
15
  end
16
+
14
17
  context.puts("\n")
15
18
 
16
19
  return unless reportable_error?(error)
17
- return unless report?
20
+ return unless report?(context: context)
18
21
 
19
22
  ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"] = "1"
20
23
  require "bugsnag"
@@ -33,20 +36,28 @@ module ShopifyCLI
33
36
  Bugsnag.notify(error, metadata)
34
37
  end
35
38
 
36
- def self.report?
37
- return false if ShopifyCLI::Environment.development?
38
- return true if ExceptionReporter::PermissionController.automatic_reporting_prompted? &&
39
- ExceptionReporter::PermissionController.can_report_automatically?
39
+ def self.report?(context:)
40
+ return true if ReportingConfigurationController.reporting_prompted? &&
41
+ ReportingConfigurationController.check_or_prompt_report_automatically(source: :uncaught_error)
40
42
 
41
- report_error = ExceptionReporter::PermissionController.report_error?
43
+ report_error = report_error?(context: context)
42
44
 
43
- unless ExceptionReporter::PermissionController.automatic_reporting_prompted?
44
- ExceptionReporter::PermissionController.can_report_automatically?
45
+ unless ReportingConfigurationController.reporting_prompted?
46
+ ReportingConfigurationController.check_or_prompt_report_automatically(source: :uncaught_error)
45
47
  end
46
48
 
47
49
  report_error
48
50
  end
49
51
 
52
+ def self.report_error?(context:)
53
+ return false if Environment.development?
54
+
55
+ CLI::UI::Prompt.ask(context.message("core.error_reporting.report_error.question")) do |handler|
56
+ handler.option(context.message("core.error_reporting.report_error.yes")) { |_| true }
57
+ handler.option(context.message("core.error_reporting.report_error.no")) { |_| false }
58
+ end
59
+ end
60
+
50
61
  def self.reportable_error?(error)
51
62
  is_abort = error.is_a?(ShopifyCLI::Abort) || error.is_a?(ShopifyCLI::AbortSilent)
52
63
  !is_abort
@@ -14,6 +14,18 @@ module ShopifyCLI
14
14
  },
15
15
  },
16
16
  core: {
17
+ app: {
18
+ serve: {
19
+ error: {
20
+ invalid_port: "%s is not a valid port.",
21
+ host_must_be_https: "HOST must be a HTTPS url.",
22
+ },
23
+ },
24
+ help: <<~HELP,
25
+ Create and manage embedded apps
26
+ Usage: {{command:%s app [ rails | node | php ] }}
27
+ HELP
28
+ },
17
29
  error_reporting: {
18
30
  unhandled_error: {
19
31
  message: "{{x}} {{red:An unexpected error occured.}}",
@@ -21,16 +33,25 @@ module ShopifyCLI
21
33
  " include the stack trace.}}",
22
34
  stacktrace_message: "{{red:\tTo print the stack trace, add the environment variable %s.}}",
23
35
  },
24
- enable_automatic_reporting_prompt: {
25
- question: "Automatically send error reports moving forward?",
26
- yes: "Automatically send error reports to the Shopify team",
27
- no: "Don't send error reports",
28
- enabled: "Anonymized error reports will be sent to Shopify.",
29
- },
30
36
  report_error: {
31
- question: "Send an error report to Shopify?",
32
- yes: "Send report",
33
- no: "Don't send",
37
+ question: "Send an anonymized error report to Shopify?",
38
+ yes: "Yes, send",
39
+ no: "No, don't send",
40
+ },
41
+ },
42
+ analytics: {
43
+ enable_prompt: {
44
+ uncaught_error: {
45
+ question: "Automatically send reports from now on?",
46
+ yes: "Yes, automatically send anonymized reports to Shopify",
47
+ no: "No, don't send",
48
+ },
49
+ usage: {
50
+ question: "Automatically send anonymized usage and error reports to Shopify? We use these"\
51
+ " to make development on Shopify better.",
52
+ yes: "Yes, automatically send anonymized reports to Shopify",
53
+ no: "No, don't send",
54
+ },
34
55
  },
35
56
  },
36
57
  connect: {
@@ -168,15 +189,6 @@ module ShopifyCLI
168
189
  disabled_as_shopify_org: "Can't switch development stores logged in as {{green:Shopify partners org}}",
169
190
  success: "Switched development store to {{green:%s}}",
170
191
  },
171
-
172
- monorail: {
173
- consent_prompt: <<~MSG,
174
- Would you like to enable anonymous usage reporting?
175
- If you select “Yes”, we’ll collect data about which commands you use and which errors you encounter.
176
- Sharing this anonymous data helps Shopify improve this tool.
177
- MSG
178
- },
179
-
180
192
  identity_auth: {
181
193
  error: {
182
194
  timeout: "Timed out while waiting for response from Shopify",
@@ -493,7 +505,24 @@ module ShopifyCLI
493
505
 
494
506
  MESSAGE
495
507
  },
496
-
508
+ reporting: {
509
+ help: <<~HELP,
510
+ Turns anonymous reporting on or off.
511
+ Usage: {{command:%s reporting on}}
512
+ HELP
513
+ invalid_argument: <<~MESSAGE,
514
+ {{command:%s reporting %s}} is not supported. The valid values are {{command:on}} or {{command:off}}
515
+ MESSAGE
516
+ missing_argument: <<~MESSAGE,
517
+ {{command:%s reporting}} expects an argument {{command:on}} or {{command:off}}
518
+ MESSAGE
519
+ turned_on_message: <<~MESSAGE,
520
+ Anonymized reports will be sent to Shopify.
521
+ MESSAGE
522
+ turned_off_message: <<~MESSAGE,
523
+ Turn on automatic reporting later wtih {{command:%s reporting on}}.
524
+ MESSAGE
525
+ },
497
526
  whoami: {
498
527
  help: <<~HELP,
499
528
  Identifies which partner organization or store you are currently logged into.
@@ -14,7 +14,7 @@ module ShopifyCLI
14
14
 
15
15
  def run
16
16
  require(path)
17
- ShopifyCli::Migrator::Migrations.const_get(class_name).run
17
+ ShopifyCLI::Migrator::Migrations.const_get(class_name).run
18
18
  rescue StandardError
19
19
  # Continue
20
20
  end
@@ -3,7 +3,7 @@
3
3
  module ShopifyCLI
4
4
  module Migrator
5
5
  module Migrations
6
- class Base
6
+ class Noop
7
7
  def self.run
8
8
  # This is a noop migration to be used as a reference
9
9
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyCLI
4
+ module Migrator
5
+ module Migrations
6
+ # Before this migration, users configured automatic usage and error
7
+ # reporting independenty. We changed it to be a single configuration
8
+ # in the environment's configuration and therefore we need a migration
9
+ # to merge the configurations.
10
+ class MergeReportingConfiguration
11
+ def self.run
12
+ analytics_enabled = ShopifyCLI::Config.get_bool(
13
+ Constants::Config::Sections::Analytics::NAME,
14
+ Constants::Config::Sections::Analytics::Fields::ENABLED,
15
+ default: false
16
+ )
17
+ error_reporting_enabled = ShopifyCLI::Config.get_bool(
18
+ "error-tracking",
19
+ "automatic-reporting",
20
+ default: false
21
+ )
22
+ # Because we are merging configuration options, both need
23
+ # to be true to for the new flag to be true. Otherwise,
24
+ # we delete them and let the CLI prompt the user again.
25
+ should_merge_be_true = analytics_enabled && error_reporting_enabled
26
+
27
+ unless should_merge_be_true
28
+ ShopifyCLI::Config.unset(
29
+ Constants::Config::Sections::Analytics::NAME,
30
+ Constants::Config::Sections::Analytics::Fields::ENABLED
31
+ )
32
+ ShopifyCLI::Config.unset(
33
+ "error-tracking",
34
+ "automatic-reporting"
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,64 @@
1
+ module ShopifyCLI
2
+ module ReportingConfigurationController
3
+ def self.enable_reporting(enabled)
4
+ ShopifyCLI::Config.set(
5
+ Constants::Config::Sections::Analytics::NAME,
6
+ Constants::Config::Sections::Analytics::Fields::ENABLED,
7
+ enabled
8
+ )
9
+ end
10
+
11
+ def self.reporting_prompted?
12
+ ShopifyCLI::Config.get_section(Constants::Config::Sections::Analytics::NAME).key?(
13
+ Constants::Config::Sections::Analytics::Fields::ENABLED
14
+ )
15
+ end
16
+
17
+ def self.reporting_enabled?
18
+ ShopifyCLI::Config.get_bool(
19
+ Constants::Config::Sections::Analytics::NAME,
20
+ Constants::Config::Sections::Analytics::Fields::ENABLED,
21
+ default: false
22
+ )
23
+ end
24
+
25
+ def self.check_or_prompt_report_automatically(source: :usage, prompt: true, context: ShopifyCLI::Context.new)
26
+ return false if ShopifyCLI::Environment.development? || ShopifyCLI::Environment.test?
27
+
28
+ # If the terminal is not interactive we can't prompt the user.
29
+ return false unless ShopifyCLI::Environment.interactive?
30
+
31
+ if reporting_prompted?
32
+ reporting_enabled?
33
+ elsif prompt
34
+ prompt_user(context: context, source: source)
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ def self.prompt_user(context:, source:)
41
+ enable_automatic_tracking = CLI::UI::Prompt.ask(
42
+ context.message("core.analytics.enable_prompt.#{source}.question")
43
+ ) do |handler|
44
+ handler.option(context.message("core.analytics.enable_prompt.#{source}.yes")) { |_| true }
45
+ handler.option(context.message("core.analytics.enable_prompt.#{source}.no")) { |_| false }
46
+ end
47
+
48
+ ShopifyCLI::Config.set(
49
+ Constants::Config::Sections::Analytics::NAME,
50
+ Constants::Config::Sections::Analytics::Fields::ENABLED,
51
+ enable_automatic_tracking
52
+ )
53
+
54
+ message = if enable_automatic_tracking
55
+ context.message("core.reporting.turned_on_message")
56
+ else
57
+ context.message("core.reporting.turned_off_message", ShopifyCLI::TOOL_NAME)
58
+ end
59
+ context.puts(message)
60
+
61
+ enable_automatic_tracking
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ class BaseService
4
+ def self.call(*args, **kwargs, &block)
5
+ new(*args, **kwargs).call(&block)
6
+ end
7
+
8
+ def call
9
+ raise NotImplementedError
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ class ReportingService < BaseService
4
+ attr_reader :enable
5
+
6
+ def initialize(enable:)
7
+ @enable = enable
8
+ super()
9
+ end
10
+
11
+ def call
12
+ ReportingConfigurationController.enable_reporting(enable)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ module ShopifyCLI
2
+ module Services
3
+ autoload :BaseService, "shopify_cli/services/base_service"
4
+ autoload :ReportingService, "shopify_cli/services/reporting_service"
5
+ end
6
+ end
@@ -9,12 +9,12 @@ module ShopifyCLI
9
9
  class Watcher
10
10
  include Observable
11
11
 
12
- def initialize(ctx, theme:, syncer:, ignore_filter: nil)
12
+ def initialize(ctx, theme:, syncer:, ignore_filter: nil, poll: false)
13
13
  @ctx = ctx
14
14
  @theme = theme
15
15
  @syncer = syncer
16
16
  @ignore_filter = ignore_filter
17
- @listener = Listen.to(@theme.root) do |modified, added, removed|
17
+ @listener = Listen.to(@theme.root, force_polling: poll) do |modified, added, removed|
18
18
  changed
19
19
  notify_observers(modified, added, removed)
20
20
  end
@@ -20,12 +20,12 @@ module ShopifyCLI
20
20
  class << self
21
21
  attr_accessor :ctx
22
22
 
23
- def start(ctx, root, port: 9292)
23
+ def start(ctx, root, port: 9292, poll: false)
24
24
  @ctx = ctx
25
25
  theme = DevelopmentTheme.new(ctx, root: root)
26
26
  ignore_filter = IgnoreFilter.from_path(root)
27
27
  @syncer = Syncer.new(ctx, theme: theme, ignore_filter: ignore_filter)
28
- watcher = Watcher.new(ctx, theme: theme, syncer: @syncer, ignore_filter: ignore_filter)
28
+ watcher = Watcher.new(ctx, theme: theme, syncer: @syncer, ignore_filter: ignore_filter, poll: poll)
29
29
 
30
30
  # Setup the middleware stack. Mimics Rack::Builder / config.ru, but in reverse order
31
31
  @app = Proxy.new(ctx, theme: theme, syncer: @syncer)
@@ -1,3 +1,3 @@
1
1
  module ShopifyCLI
2
- VERSION = "2.6.3"
2
+ VERSION = "2.6.4"
3
3
  end
data/lib/shopify_cli.rb CHANGED
@@ -96,11 +96,13 @@ module ShopifyCLI
96
96
  )
97
97
  end
98
98
 
99
+ autoload :AppTypeDetector, "shopify_cli/app_type_detector"
99
100
  autoload :Constants, "shopify_cli/constants"
100
101
  autoload :Environment, "shopify_cli/environment"
101
102
  autoload :AdminAPI, "shopify_cli/admin_api"
102
103
  autoload :API, "shopify_cli/api"
103
104
  autoload :Command, "shopify_cli/command"
105
+ autoload :CommandOptions, "shopify_cli/command_options"
104
106
  autoload :Commands, "shopify_cli/commands"
105
107
  autoload :Connect, "shopify_cli/connect"
106
108
  autoload :Context, "shopify_cli/context"
@@ -123,9 +125,11 @@ module ShopifyCLI
123
125
  autoload :Project, "shopify_cli/project"
124
126
  autoload :ProjectCommands, "shopify_cli/project_commands"
125
127
  autoload :ProjectType, "shopify_cli/project_type"
128
+ autoload :ReportingConfigurationController, "shopify_cli/reporting_configuration_controller"
126
129
  autoload :ResolveConstant, "shopify_cli/resolve_constant"
127
130
  autoload :Resources, "shopify_cli/resources"
128
131
  autoload :Result, "shopify_cli/result"
132
+ autoload :Services, "shopify_cli/services"
129
133
  autoload :Shopifolk, "shopify_cli/shopifolk"
130
134
  autoload :SubCommand, "shopify_cli/sub_command"
131
135
  autoload :Task, "shopify_cli/task"
data/shopify-cli.gemspec CHANGED
@@ -45,12 +45,5 @@ Gem::Specification.new do |spec|
45
45
 
46
46
  spec.add_dependency("bugsnag", "~> 6.22")
47
47
  spec.add_dependency("listen", "~> 3.7.0")
48
-
49
- # Note: theme-check is _intentionally_ not specifying the third
50
- # digit. We _want_ new features to make their way into new installs
51
- # of the Shopify CLI. Otherwise updates need to be released twice.
52
- #
53
- # That is, DO USE ~> 1.X, DO NOT USE ~> 1.X.Y, this would unnecessarily
54
- # fix the feature version.
55
- spec.add_dependency("theme-check", "~> 1.7")
48
+ spec.add_dependency("theme-check", "~> 1.7.2")
56
49
  end
@@ -0,0 +1,76 @@
1
+ require "open3"
2
+
3
+ module Utilities
4
+ module Docker
5
+ class Container
6
+ SHOPIFY_BIN_PATH = "/usr/src/app/bin/shopify"
7
+
8
+ Error = Class.new(StandardError)
9
+
10
+ attr_reader :id, :env, :cwd, :xdg_config_home, :xdg_cache_home
11
+
12
+ def initialize(id:, env:, cwd:)
13
+ @id = id
14
+ @cwd = cwd
15
+ @xdg_config_home = File.join(cwd, ".config")
16
+ @xdg_cache_home = File.join(cwd, ".cache")
17
+ @env = env.merge({
18
+ "XDG_CONFIG_HOME" => @xdg_config_home,
19
+ "XDG_CACHE_HOME" => @xdg_cache_home,
20
+ })
21
+ end
22
+
23
+ def remove
24
+ _, stderr, stat = Open3.capture3(
25
+ "docker", "rm", "-f", @id
26
+ )
27
+ raise Error, stderr unless stat.success?
28
+ end
29
+
30
+ def capture_shopify(*args)
31
+ capture(*([SHOPIFY_BIN_PATH] + args))
32
+ end
33
+
34
+ def capture(*args, relative_dir: nil)
35
+ command = ["docker", "exec"]
36
+ cwd = if relative_dir.nil?
37
+ @cwd
38
+ else
39
+ File.join(@cwd, relative_dir)
40
+ end
41
+ command += ["-w", cwd]
42
+ @env.each do |env_name, env_value|
43
+ command += ["--env", "#{env_name}=#{env_value}"]
44
+ end
45
+ command << @id
46
+ command += args
47
+
48
+ out, err, stat = Open3.capture3(*command)
49
+ raise Error, err unless stat.success?
50
+ out
51
+ end
52
+
53
+ def exec_shopify(*args, relative_dir: nil)
54
+ exec(*([SHOPIFY_BIN_PATH] + args), relative_dir: relative_dir)
55
+ end
56
+
57
+ def exec(*args, relative_dir: nil)
58
+ command = ["docker", "exec"]
59
+ cwd = if relative_dir.nil?
60
+ @cwd
61
+ else
62
+ File.join(@cwd, relative_dir)
63
+ end
64
+ command += ["-w", cwd]
65
+ @env.each do |env_name, env_value|
66
+ command += ["--env", "#{env_name}=#{env_value}"]
67
+ end
68
+ command << @id
69
+ command += args
70
+
71
+ out, stat = Open3.capture2e(*command)
72
+ raise Error, out unless stat.success?
73
+ end
74
+ end
75
+ end
76
+ end
data/utilities/docker.rb CHANGED
@@ -1,10 +1,43 @@
1
1
  require "open3"
2
+ require "securerandom"
2
3
 
3
4
  module Utilities
4
5
  module Docker
6
+ autoload :Container, "docker/container"
7
+
5
8
  Error = Class.new(StandardError)
6
9
 
7
10
  class << self
11
+ def create_container(env: {})
12
+ id = SecureRandom.hex
13
+ cwd = "/tmp/#{SecureRandom.hex}"
14
+
15
+ build_image_if_needed
16
+
17
+ _, stderr, stat = Open3.capture3(
18
+ "docker", "run",
19
+ "-t", "-d",
20
+ "--name", id,
21
+ "--volume", "#{Shellwords.escape(root_dir)}:/usr/src/app",
22
+ image_tag,
23
+ "tail", "-f", "/dev/null"
24
+ )
25
+ raise Error, stderr unless stat.success?
26
+
27
+ _, stderr, stat = Open3.capture3(
28
+ "docker", "exec",
29
+ id,
30
+ "mkdir", "-p", cwd
31
+ )
32
+ raise Error, stderr unless stat.success?
33
+
34
+ Container.new(
35
+ id: id,
36
+ cwd: cwd,
37
+ env: env
38
+ )
39
+ end
40
+
8
41
  def run_and_rm_container(*args)
9
42
  build_image_if_needed
10
43
  system(
@@ -24,18 +57,26 @@ module Utilities
24
57
 
25
58
  def build_image_if_needed
26
59
  unless image_exists?(image_tag)
27
- system("docker", "build", root_dir, "-t", image_tag) || abort
60
+ _, err, stat = Open3.capture3(
61
+ "docker", "build", root_dir, "-t", image_tag
62
+ )
63
+ raise Error, err unless stat.success?
28
64
  end
29
65
  end
30
66
 
31
67
  def image_tag
32
68
  gemfile_lock_path = File.expand_path("./Gemfile.lock", root_dir)
33
- image_sha = Digest::SHA256.hexdigest(File.read(gemfile_lock_path))
69
+ dockerfile_path = File.expand_path("./Dockerfile", root_dir)
70
+ fingerprintable_strings = [
71
+ File.read(gemfile_lock_path),
72
+ File.read(dockerfile_path),
73
+ ]
74
+ image_sha = Digest::SHA256.hexdigest(fingerprintable_strings.join("-"))
34
75
  "shopify-cli-#{image_sha}"
35
76
  end
36
77
 
37
78
  def image_exists?(tag)
38
- _, stat = Open3.capture2(
79
+ _, stat = Open3.capture2e(
39
80
  "docker", "inspect",
40
81
  "--type=image",
41
82
  tag