envirobly-orchestra 0.4.1 → 0.4.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/orchestra/base.rb +12 -4
- data/lib/orchestra/cli/images.rb +25 -18
- data/lib/orchestra/cli/services.rb +5 -1
- data/lib/orchestra/cli/stack.rb +4 -0
- data/lib/orchestra/logger.rb +1 -0
- data/lib/orchestra/version.rb +1 -1
- data/lib/orchestra.rb +2 -2
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 649c4efdb1b871fd9da2d82daee65246626bcade95f6ebe96660e8864c9a1fc3
|
4
|
+
data.tar.gz: 36d68bc5b20e51c7ef1f594fb3b0f31cfeb439b93bfc813bdbaa0af56a50ec3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a26add478d2971183ed4dcedc6cec9f8b23aae2cda5682c0fea41d9560a2f0bc2abdd8c1bf05cb56abc48fab65b942e7df220701469dc690a1701fca78ffb1b0
|
7
|
+
data.tar.gz: 646480972fe697e48b5eca15fed1100657a6799adfdcdb710d1675f4fb7f454d97f926ca5b81c76429ebb6efd797c6f0153fd10ae38ba5fb98057eefb204b5f6
|
data/lib/orchestra/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "thor"
|
2
|
+
require "logger"
|
2
3
|
|
3
4
|
class Orchestra::Base < Thor
|
4
5
|
def self.exit_on_failure?
|
@@ -27,13 +28,20 @@ class Orchestra::Base < Thor
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def log(text)
|
30
|
-
|
31
|
+
@logger ||= Logger.new("/var/log/orchestra.log")
|
32
|
+
|
33
|
+
@logger.info text
|
31
34
|
end
|
32
35
|
|
33
|
-
def execute(cmd, exit_on_failure: true)
|
34
|
-
stdout_and_err, status =
|
36
|
+
def execute(cmd, exit_on_failure: true, escape_arguments: true)
|
37
|
+
stdout_and_err, status =
|
38
|
+
if escape_arguments
|
39
|
+
Open3.capture2e *cmd
|
40
|
+
else
|
41
|
+
Open3.capture2e cmd.join(" ")
|
42
|
+
end
|
35
43
|
|
36
|
-
log stdout_and_err unless stdout_and_err.
|
44
|
+
log stdout_and_err unless stdout_and_err.nil? || stdout_and_err.empty?
|
37
45
|
|
38
46
|
if exit_on_failure && status.to_i > 0
|
39
47
|
exit 1
|
data/lib/orchestra/cli/images.rb
CHANGED
@@ -6,30 +6,27 @@ class Orchestra::Cli::Images < Orchestra::Base
|
|
6
6
|
desc "build", "Build and push a Docker image"
|
7
7
|
method_option :git_url, type: :string, required: true
|
8
8
|
method_option :commit_id, type: :string, required: true
|
9
|
-
method_option :cache_bucket, type: :string, required: true
|
10
|
-
method_option :cache_region, type: :string, required: true
|
11
9
|
method_option :image_uri, type: :string, required: true
|
12
10
|
method_option :dockerfile, type: :string, required: true
|
13
11
|
method_option :build_context, type: :string, required: true
|
14
12
|
def build
|
15
|
-
|
16
|
-
|
17
|
-
puts "Checking out commit #{options.commit_id}..."
|
13
|
+
log "Checking out commit #{options.commit_id}..."
|
18
14
|
|
19
15
|
checkout_time = Benchmark.realtime do
|
20
|
-
|
21
|
-
Open3.capture2e "envirobly-git-checkout-commit", git_checkout_path.to_s, options.git_url, options.commit_id
|
22
|
-
|
23
|
-
puts output
|
16
|
+
execute git_checkout_cmd, escape_arguments: false
|
24
17
|
end
|
25
18
|
|
26
|
-
|
19
|
+
log "Checkout finished in #{checkout_time.to_i}s\n"
|
27
20
|
|
28
|
-
|
21
|
+
build_time = Benchmark.realtime do
|
22
|
+
execute buildx_build_cmd, escape_arguments: false
|
23
|
+
end
|
29
24
|
|
30
|
-
|
25
|
+
log "Build finished in #{build_time.to_i}s"
|
31
26
|
|
32
|
-
|
27
|
+
if FileUtils.rm_rf git_checkout_path
|
28
|
+
log "Removed #{git_checkout_path}"
|
29
|
+
end
|
33
30
|
end
|
34
31
|
|
35
32
|
private
|
@@ -37,16 +34,16 @@ class Orchestra::Cli::Images < Orchestra::Base
|
|
37
34
|
[
|
38
35
|
"docker", "buildx", "build",
|
39
36
|
"--progress=plain",
|
40
|
-
"--
|
41
|
-
"
|
42
|
-
"-t", options.image_uri, "--push",
|
37
|
+
"--push",
|
38
|
+
"-t", options.image_uri,
|
43
39
|
"-f", dockerfile_path.to_s,
|
44
|
-
build_context.to_s
|
40
|
+
build_context.to_s,
|
41
|
+
">> /var/log/orchestra.log 2>&1"
|
45
42
|
]
|
46
43
|
end
|
47
44
|
|
48
45
|
def git_checkout_path
|
49
|
-
Pathname.new "/tmp/build"
|
46
|
+
Pathname.new "/tmp/build-#{options.commit_id}"
|
50
47
|
end
|
51
48
|
|
52
49
|
def build_context
|
@@ -56,4 +53,14 @@ class Orchestra::Cli::Images < Orchestra::Base
|
|
56
53
|
def dockerfile_path
|
57
54
|
git_checkout_path.join options.dockerfile
|
58
55
|
end
|
56
|
+
|
57
|
+
def git_checkout_cmd
|
58
|
+
[
|
59
|
+
"envirobly-git-checkout-commit",
|
60
|
+
git_checkout_path.to_s,
|
61
|
+
options.git_url,
|
62
|
+
options.commit_id,
|
63
|
+
"&> /dev/null"
|
64
|
+
]
|
65
|
+
end
|
59
66
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require "open3"
|
2
2
|
# require "httpx"
|
3
3
|
require "pathname"
|
4
|
+
require "yaml"
|
5
|
+
require "erb"
|
4
6
|
|
5
7
|
class Orchestra::Cli::Services < Orchestra::Base
|
6
8
|
desc "up", "Start services based on config synced from config bucket"
|
@@ -99,7 +101,7 @@ class Orchestra::Cli::Services < Orchestra::Base
|
|
99
101
|
|
100
102
|
def initialize_data_volumes
|
101
103
|
compose_definition["services"].each do |_, service|
|
102
|
-
next
|
104
|
+
next unless service["labels"]
|
103
105
|
|
104
106
|
zpool = service["labels"]["envirobly.data-volume.pool"]
|
105
107
|
mountpoint = service["labels"]["envirobly.data-volume.pool.mountpoint"]
|
@@ -107,6 +109,8 @@ class Orchestra::Cli::Services < Orchestra::Base
|
|
107
109
|
dataset_mountpoint = service["labels"]["envirobly.data-volume.dataset.mountpoint"]
|
108
110
|
device = service["labels"]["envirobly.data-volume.device"]
|
109
111
|
|
112
|
+
next if zpool.nil? || mountpoint.nil? || zfs_dataset.nil? || dataset_mountpoint.nil? || device.nil?
|
113
|
+
|
110
114
|
if zfs_dataset_exist?(zfs_dataset)
|
111
115
|
log " ZFS dataset exists"
|
112
116
|
next
|
data/lib/orchestra/cli/stack.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
class Orchestra::Cli::Stack < Orchestra::Base
|
2
2
|
desc "prune", "Stop inactive services and clean up their data volumes"
|
3
3
|
def prune
|
4
|
+
# Get running containers:
|
5
|
+
# curl -s --unix-socket /var/run/docker.sock "http://localhost/v1.43/containers/json"
|
6
|
+
|
7
|
+
# Actual "prune":
|
4
8
|
# docker compose up -d --quiet-pull --no-recreate --remove-orphans --no-start
|
5
9
|
end
|
6
10
|
end
|
data/lib/orchestra/logger.rb
CHANGED
data/lib/orchestra/version.rb
CHANGED
data/lib/orchestra.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envirobly-orchestra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '7.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '7.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: thor
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|