renuo-cli 4.19.0 → 4.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67d1a1aabbf0a54a5f93018178724eef959d87e61b6b5e7819c72c826646b925
4
- data.tar.gz: 8b584d301b391e7bab989af846092bffd7635ba84862d31621fc45b76969b580
3
+ metadata.gz: 96e87891f76ac2c03e7d49276a00ec9f28b6d51530636c9fe18861b517202d56
4
+ data.tar.gz: 58a5b66274436e087f13ba451b252d2fc16a3e96c873e1abc43e6901e47dbc6c
5
5
  SHA512:
6
- metadata.gz: 6c94a81ccf21115e5bdd9149ea408d31686c0f7b018a292f633bfae5b9da0e2dde58ecb3cd32d88f7ebb2a63207ecffd38c526ba342aa2d552bd07554256cf14
7
- data.tar.gz: 7bb4bb3454243794e9efed8becd728a7d976f972618b8d29af226072c602c2c49d069e7a01ed8500faaf9645556bdcf9f490040e3ada0d2e3609e6a64e65944a
6
+ metadata.gz: 3f8ead33a76b828827e9ffeb699d9b4005d84bb3eb92bc984fae844c9d11acf3008d60cb980d75ee52707f98c68ad675a13d75d5d34c3bdc95b3ebab3a6fbef9
7
+ data.tar.gz: 682b8f5e3c1ce078db1bca379297a29c174f382d1a7ce882ee0a52db2056f6b54a6b3e330c6e790d0cb926130535b1e8982768886b1847fca5e7bd51b7f0a9ac
@@ -7,7 +7,7 @@ class Renuo::Cli::Commands::CheckDeploioStatus
7
7
 
8
8
  command "check-deploio-status" do |c|
9
9
  c.syntax = "renuo check-deploio-status"
10
- c.summary = "Checks the build and release status of the deployment."
10
+ c.summary = "DEPRECATED: Use 'renuo ci check-deploio-status' instead."
11
11
  c.description = "Checks the build and release status of the deployment."
12
12
  c.option "-a", "--app <name>", String, "The name of the app"
13
13
  c.option "-p", "--project <name>", String, "The name of the project"
@@ -25,6 +25,7 @@ class Renuo::Cli::Commands::CheckDeploioStatus
25
25
  end
26
26
 
27
27
  def run
28
+ warn "DEPRECATED: Use 'renuo ci check-deploio-status' instead."
28
29
  puts "(1/2) Checking build status for revision #{@revision}..."
29
30
  poll "build"
30
31
  abort "build check timed out after #{TIMEOUT_IN_SECONDS} seconds" if build.nil?
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Renuo::Cli::Commands::Ci
5
+ class CheckDeploioStatus
6
+ TIMEOUT_IN_SECONDS = 600
7
+ INTERVAL_IN_SECONDS = 5
8
+
9
+ command "ci check-deploio-status" do |c|
10
+ c.syntax = "renuo ci check-deploio-status"
11
+ c.summary = "Checks the build and release status of the deployment."
12
+ c.description = c.summary
13
+ c.option "-p", "--project <name>", String, "The name of the project"
14
+ c.action { |args, options| new(args, options).run }
15
+ end
16
+
17
+ def run
18
+ puts "(1/2) Checking build status for revision #{@revision}..."
19
+ poll "build"
20
+ abort "build check timed out after #{TIMEOUT_IN_SECONDS} seconds" if build.nil?
21
+
22
+ puts "(2/2) Checking release status for build #{build_name}..."
23
+ poll "release"
24
+ abort "release check timed out after #{TIMEOUT_IN_SECONDS} seconds" if release.nil?
25
+ end
26
+
27
+ private
28
+
29
+ def initialize(args, options)
30
+ @app = args.first
31
+ @project = options.project
32
+ @revision = ENV.fetch("SEMAPHORE_GIT_SHA", nil)
33
+
34
+ abort "missing app name" unless @app
35
+ abort "missing project name" unless @project
36
+ abort "this command must be run in Semaphore" unless @revision
37
+ end
38
+
39
+ def system!(cmd)
40
+ abort unless system cmd
41
+ end
42
+
43
+ def fetch(type)
44
+ command = "nctl get #{type} -a #{@app} -p #{@project} -o yaml"
45
+ stdout, stderr, status = Open3.capture3 command
46
+
47
+ abort "error fetching #{type} information: #{stderr}" unless status.success?
48
+ Psych.load_stream stdout
49
+ end
50
+
51
+ def fetch_build_logs
52
+ command = "nctl logs build -a #{@app} -p #{@project} -l 5000 --no-labels"
53
+ stdout, stderr, status = Open3.capture3 command
54
+
55
+ puts "error fetching build logs: #{stderr}" unless status.success?
56
+ stdout
57
+ end
58
+
59
+ def build
60
+ @build ||= fetch("builds").find do |build|
61
+ build.dig("spec", "forProvider", "sourceConfig", "git", "revision") == @revision
62
+ end
63
+ end
64
+
65
+ def build_name
66
+ @build_name ||= build.dig("metadata", "name")
67
+ end
68
+
69
+ def build_status
70
+ build.dig("status", "atProvider", "buildStatus")
71
+ end
72
+
73
+ def release
74
+ @release ||= fetch("releases").find do |release|
75
+ release.dig("spec", "forProvider", "build", "name") == build_name
76
+ end
77
+ end
78
+
79
+ def release_status
80
+ release.dig("status", "atProvider", "releaseStatus")
81
+ end
82
+
83
+ def succeeded?(status, type) # rubocop:disable Metrics/MethodLength
84
+ time = "[#{Time.now.utc.iso8601}]"
85
+
86
+ case status
87
+ when "available", "success"
88
+ puts "#{time} #{type} succeeded"
89
+ true
90
+ when "superseded"
91
+ puts "#{time} release was superseded"
92
+ true
93
+ when "paused"
94
+ abort "#{time} app is paused"
95
+ when "error", "failed", "failure"
96
+ puts fetch_build_logs
97
+ abort "#{time} #{type} failed"
98
+ else
99
+ puts "#{time} #{type} status is #{status}, waiting..."
100
+ instance_variable_set :"@#{type}", nil
101
+ end
102
+ end
103
+
104
+ def poll(type)
105
+ elapsed = 0
106
+
107
+ while elapsed < TIMEOUT_IN_SECONDS
108
+ if send type
109
+ break if succeeded?(send(:"#{type}_status"), type)
110
+ else
111
+ puts "no matching #{type} found, waiting..."
112
+ end
113
+
114
+ sleep INTERVAL_IN_SECONDS
115
+ elapsed += INTERVAL_IN_SECONDS
116
+ end
117
+ end
118
+ end
119
+ end
120
+ # :nocov:
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Renuo::Cli::Commands::Ci
4
+ class UpdateDeploioApp
5
+ command "ci update-deploio-app" do |c|
6
+ c.syntax = "renuo ci update-deploio-app"
7
+ c.summary = "Updates a Deploio app."
8
+ c.description = c.summary
9
+ c.option "-d", "--docker", "If the app uses a Dockerfile"
10
+ c.option "-p", "--project <name>", String, "The name of the project"
11
+ c.example "renuo ci update-deploio-app main -dp renuo-dashboard",
12
+ "Updates the 'main' app of the 'renuo-dashboard' project using a Dockerfile"
13
+ c.action { |args, options| new(args, options).run }
14
+ end
15
+
16
+ def run
17
+ system! "checkout --use-cache" if @docker
18
+ system! "echo 'deb [trusted=yes] https://repo.nine.ch/deb/ /' " \
19
+ "| sudo tee /etc/apt/sources.list.d/repo.nine.ch.list"
20
+ system! "sudo apt-get update -qqo Dir::Etc::sourcelist=/etc/apt/sources.list.d/repo.nine.ch.list"
21
+ system! "sudo apt-get install -qq nctl"
22
+ system! "nctl auth login"
23
+ system! "nctl update app #{@app} -p #{@project} --env APP_REVISION=$SEMAPHORE_GIT_SHA " \
24
+ "#{"--build-env RUBY_VERSION=#{File.read(".ruby-version").strip} " if @docker}" \
25
+ "--git-revision $SEMAPHORE_GIT_SHA --skip-repo-access-check"
26
+ end
27
+
28
+ private
29
+
30
+ def initialize(args, options)
31
+ @app = args.first
32
+ @project = options.project
33
+ @docker = options.docker
34
+
35
+ abort "missing app name" unless @app
36
+ abort "missing project name" unless @project
37
+ abort "this command must be run in Semaphore" unless ENV.key?("SEMAPHORE_GIT_SHA")
38
+ end
39
+
40
+ def system!(cmd)
41
+ abort unless system cmd
42
+ end
43
+ end
44
+ end
@@ -155,25 +155,14 @@ class Renuo::Cli::Commands::CreateDeploioApp # rubocop:disable Metrics/ClassLeng
155
155
  end
156
156
 
157
157
  def say_database_creation(environment)
158
- if environment == "main"
159
- say <<~OUTPUT
160
- nctl create postgres #{environment} \\
161
- --project=#{@project_name_with_org_prefix} \\
162
- --postgres-version=#{@postgres_version} \\
163
- --machine-type=nine-db-xs \\
164
- --allowed-cidrs=0.0.0.0/0 \\
165
- --location=nine-es34
166
- OUTPUT
167
- else
168
- say <<~OUTPUT
169
- nctl create postgresdatabase #{environment} \\
170
- --project=#{@project_name_with_org_prefix} \\
171
- --postgres-database-version=#{@postgres_version} \\
172
- --location=nine-es34 \\
173
- --backup-schedule=daily
174
- --collation=C.UTF-8
175
- OUTPUT
176
- end
158
+ say <<~OUTPUT
159
+ nctl create postgresdatabase #{environment} \\
160
+ --project=#{@project_name_with_org_prefix} \\
161
+ --postgres-database-version=#{@postgres_version} \\
162
+ --location=nine-es34 \\
163
+ --backup-schedule=daily
164
+ --collation=C.UTF-8
165
+ OUTPUT
177
166
  end
178
167
 
179
168
  def say_app_creation(environment)
@@ -3,8 +3,8 @@ name: <%= environment %>-deploy
3
3
 
4
4
  agent:
5
5
  machine:
6
- type: f1-standard-4
7
- os_image: ubuntu2204
6
+ type: e1-standard-2
7
+ os_image: ubuntu2404
8
8
 
9
9
  blocks:
10
10
  - name: cd
@@ -17,10 +17,6 @@ blocks:
17
17
  jobs:
18
18
  - name: deploying
19
19
  commands:
20
- - echo 'deb [trusted=yes] https://repo.nine.ch/deb/ /' | sudo tee /etc/apt/sources.list.d/repo.nine.ch.list
21
- - sudo apt-get update -qqo Dir::Etc::sourcelist=/etc/apt/sources.list.d/repo.nine.ch.list
22
- - sudo apt-get install -qq nctl
23
- - nctl auth login --api-client-id=$NCTL_API_CLIENT_ID --api-client-secret=$NCTL_API_CLIENT_SECRET --organization=$NCTL_ORGANIZATION
24
- - nctl update app <%= environment %> -p <%= project_name %> --build-env="RUBY_VERSION=$(cat .ruby-version)" --git-revision=$SEMAPHORE_GIT_SHA --skip-repo-access-check
25
20
  - gem i -q renuo-cli
26
- - renuo check-deploio-status -a <%= environment %> -p <%= project_name %> -g $SEMAPHORE_GIT_SHA
21
+ - renuo ci update-deploio-app <%= environment %> -p renuo-<%= project_name %>
22
+ - renuo ci check-deploio-status <%= environment %> -p renuo-<%= project_name %>
@@ -4,7 +4,7 @@ name: <%= project_name %>
4
4
  agent:
5
5
  machine:
6
6
  type: f1-standard-4
7
- os_image: ubuntu2204
7
+ os_image: ubuntu2404
8
8
 
9
9
  auto_cancel:
10
10
  running:
@@ -3,7 +3,7 @@
3
3
  # :nocov:
4
4
  module Renuo
5
5
  class Cli
6
- VERSION = "4.19.0"
6
+ VERSION = "4.20.0"
7
7
  NAME = "renuo-cli"
8
8
  end
9
9
  end
data/lib/renuo/cli.rb CHANGED
@@ -34,7 +34,7 @@ module Renuo
34
34
  program :description, "Renuo CLI"
35
35
  program :help_paging, false
36
36
 
37
- Dir[File.expand_path("cli/{commands,services}/*.rb", __dir__)].each { |f| require f }
37
+ Dir[File.expand_path("cli/{commands,services}/**/*.rb", __dir__)].each { |f| require f }
38
38
  default_command :help
39
39
  end
40
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renuo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.19.0
4
+ version: 4.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
@@ -65,6 +65,8 @@ files:
65
65
  - bin/renuo
66
66
  - lib/renuo/cli.rb
67
67
  - lib/renuo/cli/commands/check_deploio_status.rb
68
+ - lib/renuo/cli/commands/ci/check_deploio_status.rb
69
+ - lib/renuo/cli/commands/ci/update_deploio_app.rb
68
70
  - lib/renuo/cli/commands/commit_leaderboard_stage.rb
69
71
  - lib/renuo/cli/commands/commit_leaderboard_sync.rb
70
72
  - lib/renuo/cli/commands/configure_semaphore.rb