renuo-cli 5.0.2 → 5.0.3
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 +4 -4
- data/lib/renuo/cli/commands/create_deploio_object_storage.rb +1 -1
- data/lib/renuo/cli/commands/review_app/README.md +10 -0
- data/lib/renuo/cli/commands/review_app/deploy.rb +1 -1
- data/lib/renuo/cli/commands/review_app/name.rb +10 -6
- data/lib/renuo/cli/commands/review_app/purge.rb +14 -5
- data/lib/renuo/cli/commands/review_app/purge_stale.rb +164 -0
- data/lib/renuo/cli/commands/review_app/setup_semaphoreci.rb +23 -7
- data/lib/renuo/cli/commands/review_app/start.rb +1 -1
- data/lib/renuo/cli/helpers/review_app_helper.rb +6 -5
- data/lib/renuo/cli/helpers/review_app_notification.rb +1 -1
- data/lib/renuo/cli/templates/semaphore/review-app-deploy.yml.erb +2 -2
- data/lib/renuo/cli/templates/semaphore/review-app-purge-stale.yml.erb +22 -0
- data/lib/renuo/cli/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a8c98c2e7f232d4c2bea7b2fa180a10328f345e0c59bd268745c1f2058e3980
|
|
4
|
+
data.tar.gz: 7c2311a7ecc48665cc041f861678354ff2feb17dc74efe6b3be71a450bb2e543
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea957f8071a7919eaf15fac84389e6bb96d9c48901389bfce936e8011a0856288657ede489c6ebae102aed9f50a91ee33fc57d648b4d8824edca501ed5b4967e
|
|
7
|
+
data.tar.gz: 4eed8ba7723fbbbc1080f27fd4dde876229392e80f4561532991d062ac2dd06d864b4c974a133b0e1e8d36b98aa741ddcdf5e0d09f2125ac289cf2156e6b86ef
|
|
@@ -106,7 +106,7 @@ class Renuo::Cli::Commands::CreateDeploioObjectStorage
|
|
|
106
106
|
nctl update app #{branch} \\
|
|
107
107
|
--project #{@project_name} \\
|
|
108
108
|
--env="DEPLOIO_S3_ACCESS_KEY={ACCESS_KEY}" \\
|
|
109
|
-
--env="DEPLOIO_S3_SECRET_KEY={SECRET_KEY}" \\
|
|
109
|
+
--sensitive-env="DEPLOIO_S3_SECRET_KEY={SECRET_KEY}" \\
|
|
110
110
|
--env="DEPLOIO_S3_ENDPOINT=https://#{@location.gsub("nine-", "")}.objects.nineapis.ch" \\
|
|
111
111
|
--env="DEPLOIO_S3_BUCKET=#{bucket_name}"
|
|
112
112
|
OUTPUT
|
|
@@ -16,6 +16,7 @@ These are the steps of command execution in the happy path:
|
|
|
16
16
|
1. Announce it on Slack `renuo notify:slack:review-app-deploy`
|
|
17
17
|
1. Cleanup `renuo review-app:purge`
|
|
18
18
|
1. Announce the cleanup on Slack `renuo notify:slack:review-app-purge`
|
|
19
|
+
1. _(Scheduled)_ Clean up the review apps of merged or deleted branches `renuo review-app:purge-stale`
|
|
19
20
|
|
|
20
21
|
## Design Choices
|
|
21
22
|
|
|
@@ -23,7 +24,16 @@ These are the steps of command execution in the happy path:
|
|
|
23
24
|
* The branch name **hash** is the only safe identifier.
|
|
24
25
|
It is being used to purge resources.
|
|
25
26
|
Connected services do not work across all systems (e.g. Nutanix Object Storage)
|
|
27
|
+
* Review app names are `review-app-<project hash>-<branch hash>`.
|
|
28
|
+
Nine bucket names are unique beyond a project, so without the project hash
|
|
29
|
+
the review apps of the same branch in two projects would claim the same bucket.
|
|
26
30
|
* A dry-run command flag is not easily possible because we rely on generated system output.
|
|
31
|
+
* `review-app:purge-stale` can't reverse a review app name into its branch, so it hashes every branch on the
|
|
32
|
+
Git remote and purges the resources named like a review app that no branch accounts for.
|
|
33
|
+
Unlike `review-app:purge`, it only deletes exact review app names, and it aborts if the remote lists no branches.
|
|
34
|
+
Combined with GitHub's "Automatically delete head branches", a scheduled run cleans up after merged pull requests.
|
|
35
|
+
With `--max-age-in-days`, it also purges review apps whose app was created more than that many days ago.
|
|
36
|
+
The age counts from the first deploy: a redeploy keeps the existing app, so it doesn't reset the age.
|
|
27
37
|
* We use the sunny/actor gem to concentrate reviewability to the command flow
|
|
28
38
|
* There is a special "safeguards" feature test. It covers the safe name contract.
|
|
29
39
|
* All `nctl` commands are routed through `system!` and are logged in a command trail for auditing.
|
|
@@ -80,7 +80,7 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
80
80
|
|
|
81
81
|
Contract Contracts::None => SafeReviewAppNameContract
|
|
82
82
|
def derive_target_app_name
|
|
83
|
-
result.target_app_name = review_app_name(branch).tap do |name|
|
|
83
|
+
result.target_app_name = review_app_name(project, branch).tap do |name|
|
|
84
84
|
abort "'#{name}' contains the origin pattern '#{origin_pattern}', aborting" if name.include?(origin_pattern)
|
|
85
85
|
end
|
|
86
86
|
end
|
|
@@ -9,10 +9,12 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
9
9
|
|
|
10
10
|
command "review-app:name" do |c|
|
|
11
11
|
c.syntax = "renuo review-app:name [options]"
|
|
12
|
-
c.summary = "Prints the review app name derived from the branch."
|
|
12
|
+
c.summary = "Prints the review app name derived from the project and the branch."
|
|
13
13
|
c.description = c.summary
|
|
14
|
+
c.option "-p", "--project <name>", String, "The name of the Deploio project"
|
|
14
15
|
c.option "-b", "--branch <name>", String, "The Git branch"
|
|
15
|
-
c.example "nctl update app $(renuo review-app:name -b add-s3-to-docs)
|
|
16
|
+
c.example "nctl update app $(renuo review-app:name -p renuo-acme -b add-s3-to-docs) " \
|
|
17
|
+
"-p renuo-acme --env KEY=value",
|
|
16
18
|
"Sets an env variable on the branch's review app"
|
|
17
19
|
c.action { |_args, options| new(options).run }
|
|
18
20
|
end
|
|
@@ -24,15 +26,17 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
24
26
|
private
|
|
25
27
|
|
|
26
28
|
def initialize(options)
|
|
29
|
+
project = options.project
|
|
27
30
|
branch = options.branch
|
|
28
31
|
|
|
32
|
+
abort "missing project name" unless project
|
|
29
33
|
abort "missing branch name" unless branch
|
|
30
|
-
@name = derive_name(branch)
|
|
34
|
+
@name = derive_name(project, branch)
|
|
31
35
|
end
|
|
32
36
|
|
|
33
|
-
Contract String => SafeReviewAppNameContract
|
|
34
|
-
def derive_name(branch)
|
|
35
|
-
review_app_name(branch)
|
|
37
|
+
Contract String, String => SafeReviewAppNameContract
|
|
38
|
+
def derive_name(project, branch)
|
|
39
|
+
review_app_name(project, branch)
|
|
36
40
|
end
|
|
37
41
|
end
|
|
38
42
|
end
|
|
@@ -32,16 +32,25 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
32
32
|
|
|
33
33
|
def initialize(options)
|
|
34
34
|
@project = options.project
|
|
35
|
-
branch = options.branch
|
|
36
|
-
|
|
37
35
|
abort "missing project name" unless @project
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
|
|
37
|
+
if options.branch
|
|
38
|
+
derive_name_pattern(options.branch)
|
|
39
|
+
elsif options.review_app_name # set by callers whose review app's branch is unknown, e.g. purge-stale
|
|
40
|
+
use_name_pattern(options.review_app_name)
|
|
41
|
+
else
|
|
42
|
+
abort "missing branch name"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
Contract SafeReviewAppNameContract => SafeReviewAppNameContract
|
|
47
|
+
def use_name_pattern(review_app_name)
|
|
48
|
+
@name_pattern = review_app_name
|
|
40
49
|
end
|
|
41
50
|
|
|
42
51
|
Contract String => SafeReviewAppNameContract
|
|
43
52
|
def derive_name_pattern(branch)
|
|
44
|
-
@name_pattern = review_app_name(branch)
|
|
53
|
+
@name_pattern = review_app_name(@project, branch)
|
|
45
54
|
end
|
|
46
55
|
|
|
47
56
|
Contract Contracts::Enum[*RESOURCE_TYPES], SafeReviewAppNameContract => Contracts::Any
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../helpers/safe_review_app_name_contract"
|
|
4
|
+
require_relative "purge"
|
|
5
|
+
require_relative "../notify/slack/review_app_purge"
|
|
6
|
+
|
|
7
|
+
module Renuo::Cli::Commands::ReviewApp
|
|
8
|
+
class PurgeStale # rubocop:disable Metrics/ClassLength
|
|
9
|
+
include ReviewAppHelper
|
|
10
|
+
|
|
11
|
+
RESOURCE_TYPES = Purge::RESOURCE_TYPES
|
|
12
|
+
SECONDS_PER_DAY = 24 * 60 * 60
|
|
13
|
+
|
|
14
|
+
command "review-app:purge-stale" do |c|
|
|
15
|
+
c.syntax = "renuo review-app:purge-stale [options]"
|
|
16
|
+
c.summary = "Deletes the Deploio resources of all review apps whose Git branch no longer exists " \
|
|
17
|
+
"or that are older than the maximum age."
|
|
18
|
+
c.description = "#{c.summary} The existing branches are read from the Git remote (origin by default). " \
|
|
19
|
+
"The age is counted from the app's creation, a redeploy does not reset it. " \
|
|
20
|
+
"Only resources named exactly like a review app are considered. With --channel, each " \
|
|
21
|
+
"purged app is announced like notify:slack:review-app-purge does, using the branch its " \
|
|
22
|
+
"app was deployed from."
|
|
23
|
+
c.option "-p", "--project <name>", String, "The name of the Deploio project"
|
|
24
|
+
c.option "--max-age-in-days <days>", Integer, "Also purge review apps created more than this many days ago"
|
|
25
|
+
c.option "--remote <name>", String, "The Git remote to read the existing branches from, defaults to origin"
|
|
26
|
+
c.option "--channel <name>", String, "The Slack channel to announce each purged review app in"
|
|
27
|
+
c.option "--dry-run", "List the stale review apps without deleting anything"
|
|
28
|
+
c.example "renuo review-app:purge-stale -p renuo-acme",
|
|
29
|
+
"Deletes all review app resources of branches that were merged or deleted"
|
|
30
|
+
c.example "renuo review-app:purge-stale -p renuo-acme --max-age-in-days 14 --dry-run",
|
|
31
|
+
"Lists the review apps that would be deleted, including those created more than 14 days ago"
|
|
32
|
+
c.action { |_args, options| new(options).run }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def run
|
|
36
|
+
stale = stale_review_apps
|
|
37
|
+
if stale.empty?
|
|
38
|
+
puts "no stale review apps found"
|
|
39
|
+
else
|
|
40
|
+
print_stale(stale)
|
|
41
|
+
purge_and_notify(stale) unless @dry_run
|
|
42
|
+
end
|
|
43
|
+
CmdTrail::Print.call
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def initialize(options)
|
|
49
|
+
@project = options.project || abort("missing project name")
|
|
50
|
+
@max_age = options.max_age_in_days
|
|
51
|
+
abort "the maximum age must be a positive number of days" if @max_age && !@max_age.positive?
|
|
52
|
+
@remote = options.remote || "origin"
|
|
53
|
+
@channel = options.channel
|
|
54
|
+
@dry_run = options.dry_run
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# [{ name: "review-app-a2ad35-daf08c", branch: "feature/42-...", created_at: "...", resources: [...],
|
|
58
|
+
# reason: "its branch no longer exists" }, ...]
|
|
59
|
+
def stale_review_apps
|
|
60
|
+
live_names = branches.to_set { |branch| review_app_name(@project, branch) }
|
|
61
|
+
|
|
62
|
+
review_apps(list_resources).filter_map do |review_app|
|
|
63
|
+
reason = stale_reason(review_app, live_names.include?(review_app[:name]))
|
|
64
|
+
review_app.merge(reason:) if reason
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def stale_reason(review_app, branch_exists)
|
|
69
|
+
return "its branch no longer exists" unless branch_exists
|
|
70
|
+
return unless @max_age && review_app[:app]
|
|
71
|
+
|
|
72
|
+
age_in_days = ((Time.now.utc - creation_time(review_app)) / SECONDS_PER_DAY).floor
|
|
73
|
+
"created #{age_in_days} days ago, more than #{@max_age}" if age_in_days > @max_age
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def branches
|
|
77
|
+
stdout, = system!("git ls-remote --heads #{@remote}", quiet: true)
|
|
78
|
+
names = stdout.lines.filter_map { |line| line.chomp[%r{\trefs/heads/(.+)\z}, 1] }
|
|
79
|
+
# An empty listing would mark every review app as stale.
|
|
80
|
+
abort "'git ls-remote --heads #{@remote}' listed no branches, aborting" if names.empty?
|
|
81
|
+
names
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Every resource review-app:purge would consider: [{ type: "app", name: "review-app-a2ad35-daf08c",
|
|
85
|
+
# created_at: "2026-11-24T13:08:19Z", branch: "feature/42-..." }, ...], the last two only set on apps.
|
|
86
|
+
def list_resources
|
|
87
|
+
RESOURCE_TYPES.flat_map do |type|
|
|
88
|
+
nctl_resources("nctl get #{type} -p #{@project} -o yaml").filter_map do |resource|
|
|
89
|
+
next if resource.dig("metadata", "labels", "nine.ch/owned-by") == "nine"
|
|
90
|
+
|
|
91
|
+
{ type:, name: resource.dig("metadata", "name"),
|
|
92
|
+
created_at: resource.dig("metadata", "creationTimestamp"),
|
|
93
|
+
branch: resource.dig("spec", "forProvider", "git", "revision") }
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Resources named exactly like a review app identify it, even if its app is gone. Its resources are
|
|
99
|
+
# the same review-app:purge deletes: those whose name contains the review app's name.
|
|
100
|
+
def review_apps(resources)
|
|
101
|
+
names = resources.map { |resource| resource[:name] }.select { |name| SafeReviewAppNameContract.valid?(name) }
|
|
102
|
+
names.uniq.map do |name|
|
|
103
|
+
app = resources.find { |resource| resource[:type] == "app" && resource[:name] == name }
|
|
104
|
+
{ name:, app:, branch: deployed_branch(name, app), resources: resources.select { |r| r[:name].include?(name) } }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Deploy points the review app at its branch. Only trust it if it leads back to the same review app.
|
|
109
|
+
def deployed_branch(name, app)
|
|
110
|
+
branch = app&.dig(:branch)
|
|
111
|
+
branch if branch.is_a?(String) && review_app_name(@project, branch) == name
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def creation_time(review_app)
|
|
115
|
+
Time.parse(review_app.dig(:app, :created_at).to_s).utc
|
|
116
|
+
rescue ArgumentError
|
|
117
|
+
abort "app #{review_app[:name]} has no valid creation timestamp, aborting"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def print_stale(stale)
|
|
121
|
+
puts "#{@dry_run ? "would delete" : "deleting"} #{stale.size} stale review app(s):"
|
|
122
|
+
stale.each do |review_app|
|
|
123
|
+
types = review_app[:resources].map do |resource|
|
|
124
|
+
resource[:name] == review_app[:name] ? resource[:type] : "#{resource[:type]} #{resource[:name]}"
|
|
125
|
+
end
|
|
126
|
+
puts " #{review_app[:name]} (#{types.join(", ")}): #{review_app[:reason]}"
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Builds every purge and notification first, so a misconfiguration aborts before anything is deleted.
|
|
131
|
+
def purge_and_notify(stale)
|
|
132
|
+
stale.map { |review_app| [purge(review_app), notifier(review_app)] }.each do |purge, notifier|
|
|
133
|
+
purge.run
|
|
134
|
+
notifier&.run
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Purge by branch, or by name if the branch is unknown, e.g. because the review app's app is gone.
|
|
139
|
+
def purge(review_app)
|
|
140
|
+
options = Commander::Command::Options.new
|
|
141
|
+
options.project = @project
|
|
142
|
+
if review_app[:branch]
|
|
143
|
+
options.branch = review_app[:branch]
|
|
144
|
+
else
|
|
145
|
+
options.review_app_name = review_app[:name]
|
|
146
|
+
end
|
|
147
|
+
Purge.new(options)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def notifier(review_app)
|
|
151
|
+
return unless @channel
|
|
152
|
+
|
|
153
|
+
unless review_app[:branch]
|
|
154
|
+
return warn("#{review_app[:name]} has no app deployed from a known branch, it won't be announced on Slack")
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
options = Commander::Command::Options.new
|
|
158
|
+
options.project = @project
|
|
159
|
+
options.branch = review_app[:branch]
|
|
160
|
+
options.channel = @channel
|
|
161
|
+
Renuo::Cli::Commands::Notify::Slack::ReviewAppPurge.new(options)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -4,15 +4,18 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
4
4
|
class SetupSemaphoreci
|
|
5
5
|
DEPLOY_PIPELINE_TEMPLATE_FILE = File.join(__dir__, "../../templates/semaphore/review-app-deploy.yml.erb")
|
|
6
6
|
PURGE_PIPELINE_TEMPLATE_FILE = File.join(__dir__, "../../templates/semaphore/review-app-purge.yml.erb")
|
|
7
|
+
PURGE_STALE_PIPELINE_TEMPLATE_FILE = File.join(__dir__,
|
|
8
|
+
"../../templates/semaphore/review-app-purge-stale.yml.erb")
|
|
7
9
|
|
|
8
10
|
DEPLOY_PIPELINE_TARGET_FILE = ".semaphore/review-app-deploy.yml"
|
|
9
11
|
PURGE_PIPELINE_TARGET_FILE = ".semaphore/review-app-purge.yml"
|
|
12
|
+
PURGE_STALE_PIPELINE_TARGET_FILE = ".semaphore/review-app-purge-stale.yml"
|
|
10
13
|
|
|
11
14
|
attr_reader :project, :origin_pattern, :slack_channel
|
|
12
15
|
|
|
13
16
|
command "review-app:setup-semaphoreci" do |c|
|
|
14
17
|
c.syntax = "renuo review-app:setup-semaphoreci [options]"
|
|
15
|
-
c.summary = "Generates the pipeline files to deploy and purge Deploio review apps."
|
|
18
|
+
c.summary = "Generates the pipeline files to deploy, purge and purge stale Deploio review apps."
|
|
16
19
|
c.description = c.summary
|
|
17
20
|
c.option "-p", "--project <name>", String, "The name of the Deploio project"
|
|
18
21
|
c.option "--origin-pattern <pattern>", String, "Name pattern identifying the origin app to copy from"
|
|
@@ -22,11 +25,9 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
22
25
|
|
|
23
26
|
def run
|
|
24
27
|
FileUtils.mkdir_p File.dirname(DEPLOY_PIPELINE_TARGET_FILE)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
write_or_warn PURGE_PIPELINE_TARGET_FILE,
|
|
29
|
-
render(PURGE_PIPELINE_TEMPLATE_FILE, { project:, secret_name:, slack_channel: })
|
|
28
|
+
pipelines.each do |target_file, (template_file, variables)|
|
|
29
|
+
write_or_warn target_file, render(template_file, variables)
|
|
30
|
+
end
|
|
30
31
|
print_instructions
|
|
31
32
|
end
|
|
32
33
|
|
|
@@ -38,6 +39,16 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
38
39
|
@slack_channel = options.slack_channel || abort("missing Slack channel")
|
|
39
40
|
end
|
|
40
41
|
|
|
42
|
+
def pipelines
|
|
43
|
+
{
|
|
44
|
+
DEPLOY_PIPELINE_TARGET_FILE => [DEPLOY_PIPELINE_TEMPLATE_FILE,
|
|
45
|
+
{ project:, origin_pattern:, secret_name:, slack_channel: }],
|
|
46
|
+
PURGE_PIPELINE_TARGET_FILE => [PURGE_PIPELINE_TEMPLATE_FILE, { project:, secret_name:, slack_channel: }],
|
|
47
|
+
PURGE_STALE_PIPELINE_TARGET_FILE => [PURGE_STALE_PIPELINE_TEMPLATE_FILE,
|
|
48
|
+
{ project:, secret_name:, slack_channel: }]
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
41
52
|
def secret_name
|
|
42
53
|
"review-apps"
|
|
43
54
|
end
|
|
@@ -57,7 +68,7 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
57
68
|
|
|
58
69
|
Register its credentials and the incoming webhook of the Slack channel #{slack_channel}
|
|
59
70
|
(https://api.slack.com/messaging/webhooks) as the project secret #{secret_name} of the Semaphore project
|
|
60
|
-
(assumed to be named #{project} as well), used by
|
|
71
|
+
(assumed to be named #{project} as well), used by all pipelines:
|
|
61
72
|
|
|
62
73
|
sem create secret -p #{project} #{secret_name} \\
|
|
63
74
|
-e NCTL_API_CLIENT_ID="$(nctl get asa #{service_account_name} --project #{project} --print-client-id)" \\
|
|
@@ -78,6 +89,11 @@ module Renuo::Cli::Commands::ReviewApp
|
|
|
78
89
|
Both buttons appear on every branch workflow in Semaphore. Deploy and purge the review app
|
|
79
90
|
of a branch by clicking the promotion on that branch's workflow. The Slack message announcing
|
|
80
91
|
a review app links that workflow, so it can be purged from there.
|
|
92
|
+
|
|
93
|
+
Purge the review apps of merged or deleted branches with a scheduled Semaphore task
|
|
94
|
+
(Project settings > Tasks) running review-app-purge-stale.yml on the default branch, e.g. daily
|
|
95
|
+
with the cron expression "0 17 * * *". Enable "Automatically delete head branches" in the GitHub
|
|
96
|
+
repository settings, so merged branches disappear and their review apps become stale.
|
|
81
97
|
INSTRUCTIONS
|
|
82
98
|
end
|
|
83
99
|
|
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
require "digest"
|
|
4
4
|
|
|
5
5
|
module ReviewAppHelper
|
|
6
|
+
PROJECT_HASH_LENGTH = 6
|
|
6
7
|
HASH_LENGTH = 6
|
|
7
|
-
|
|
8
|
-
NAME_PATTERN = /\Areview-app-(?:\d{1,#{MAX_NUMBER_LENGTH}}-)?\h{#{HASH_LENGTH}}\z/
|
|
8
|
+
NAME_PATTERN = /\Areview-app-\h{#{PROJECT_HASH_LENGTH}}-\h{#{HASH_LENGTH}}\z/
|
|
9
9
|
MIN_PATTERN_LENGTH = 3
|
|
10
10
|
# Deploio keeps modifying an app for a while after a change, so nctl updates right after it can conflict.
|
|
11
11
|
RECONCILIATION_RETRY_DELAYS = [1, 4, 16].freeze
|
|
12
12
|
|
|
13
13
|
class FailedAttempt < StandardError; end
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
# Nine bucket names are unique beyond a project, so the same branch in two projects needs two names.
|
|
16
|
+
def review_app_name(project, branch)
|
|
17
|
+
"review-app-#{Digest::SHA256.hexdigest(project)[0, PROJECT_HASH_LENGTH]}-" \
|
|
18
|
+
"#{Digest::SHA256.hexdigest(branch)[0, HASH_LENGTH]}"
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# nctl prints a YAML stream, a YAML list, "[]" or a plain-text banner, depending on version and match count
|
|
@@ -27,7 +27,7 @@ blocks:
|
|
|
27
27
|
- renuo review-app:deploy --project <%= project %> --branch $SEMAPHORE_GIT_WORKING_BRANCH --origin-pattern <%= origin_pattern %>
|
|
28
28
|
# Make sure your review apps have the right environment variables. We don't copy from origin.
|
|
29
29
|
#
|
|
30
|
-
# -| nctl update app $(renuo review-app:name --branch $SEMAPHORE_GIT_WORKING_BRANCH) --project <%= project %> \
|
|
30
|
+
# -| nctl update app $(renuo review-app:name --project <%= project %> --branch $SEMAPHORE_GIT_WORKING_BRANCH) --project <%= project %> \
|
|
31
31
|
# --env "KEY=value" --sensitive-env "SECRET=$FROM_SEMAPHORE_SECRET" \
|
|
32
32
|
# --build-env "KEY=value" --sensitive-build-env "KEY=value"
|
|
33
33
|
#
|
|
@@ -42,5 +42,5 @@ blocks:
|
|
|
42
42
|
#
|
|
43
43
|
# - renuo review-app:deploy --project <%= project %> --branch $SEMAPHORE_GIT_WORKING_BRANCH --origin-pattern <%= origin_pattern %> --keep-envs=build,sensitive-build,runtime,sensitive-runtime --start
|
|
44
44
|
- renuo review-app:start --project <%= project %> --branch $SEMAPHORE_GIT_WORKING_BRANCH
|
|
45
|
-
- renuo ci check-deploio-status $(renuo review-app:name --branch $SEMAPHORE_GIT_WORKING_BRANCH) --project <%= project %>
|
|
45
|
+
- renuo ci check-deploio-status $(renuo review-app:name --project <%= project %> --branch $SEMAPHORE_GIT_WORKING_BRANCH) --project <%= project %>
|
|
46
46
|
- renuo notify:slack:review-app-deploy --project <%= project %> --branch $SEMAPHORE_GIT_WORKING_BRANCH --channel '<%= slack_channel %>'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
version: v1.0
|
|
2
|
+
name: review-app-purge-stale
|
|
3
|
+
|
|
4
|
+
agent:
|
|
5
|
+
machine:
|
|
6
|
+
type: e1-standard-2
|
|
7
|
+
os_image: ubuntu2404
|
|
8
|
+
|
|
9
|
+
blocks:
|
|
10
|
+
- name: review-app-purge-stale
|
|
11
|
+
execution_time_limit:
|
|
12
|
+
minutes: 10
|
|
13
|
+
task:
|
|
14
|
+
secrets:
|
|
15
|
+
- name: <%= secret_name %>
|
|
16
|
+
jobs:
|
|
17
|
+
- name: purging stale review apps
|
|
18
|
+
commands:
|
|
19
|
+
- checkout
|
|
20
|
+
- gem i -q renuo-cli
|
|
21
|
+
- renuo ci setup
|
|
22
|
+
- renuo review-app:purge-stale --project <%= project %> --max-age-in-days 14 --channel '<%= slack_channel %>'
|
data/lib/renuo/cli/version.rb
CHANGED
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: 5.0.
|
|
4
|
+
version: 5.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Renuo AG
|
|
@@ -132,6 +132,7 @@ files:
|
|
|
132
132
|
- lib/renuo/cli/commands/review_app/deploy.rb
|
|
133
133
|
- lib/renuo/cli/commands/review_app/name.rb
|
|
134
134
|
- lib/renuo/cli/commands/review_app/purge.rb
|
|
135
|
+
- lib/renuo/cli/commands/review_app/purge_stale.rb
|
|
135
136
|
- lib/renuo/cli/commands/review_app/setup_semaphoreci.rb
|
|
136
137
|
- lib/renuo/cli/commands/review_app/start.rb
|
|
137
138
|
- lib/renuo/cli/commands/setup_autocompletion.rb
|
|
@@ -169,6 +170,7 @@ files:
|
|
|
169
170
|
- lib/renuo/cli/templates/semaphore/bin/cache_store.erb
|
|
170
171
|
- lib/renuo/cli/templates/semaphore/notification.yml.erb
|
|
171
172
|
- lib/renuo/cli/templates/semaphore/review-app-deploy.yml.erb
|
|
173
|
+
- lib/renuo/cli/templates/semaphore/review-app-purge-stale.yml.erb
|
|
172
174
|
- lib/renuo/cli/templates/semaphore/review-app-purge.yml.erb
|
|
173
175
|
- lib/renuo/cli/templates/semaphore/semaphore-deploy.yml.erb
|
|
174
176
|
- lib/renuo/cli/templates/semaphore/semaphore.yml.erb
|