envirobly-orchestra 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27540543de48daec3396d69ad5ce05079fefd25a0f76a092c914a8e2873a80e7
4
- data.tar.gz: 96d0c5e27e028b8c0cc06df90c81bc111a5efe4d591c1926d201773443bc9e11
3
+ metadata.gz: 649c4efdb1b871fd9da2d82daee65246626bcade95f6ebe96660e8864c9a1fc3
4
+ data.tar.gz: 36d68bc5b20e51c7ef1f594fb3b0f31cfeb439b93bfc813bdbaa0af56a50ec3d
5
5
  SHA512:
6
- metadata.gz: 803c22a7247aa5e69a133436924146cb94d2d7d7f56258e446154fac304fcfdba4d4b60f84a1b9407af1505d12eb40946bb515ce19f1a6354b6ae73f178fc82a
7
- data.tar.gz: d16b2d572fbb2acd1357c733af6083ea5020cc82eee376c771ffcab3ec5a795bccd9cb948f558247fcec5c27e02950a44add0d7247d0f497da8bb1f856d6bb55
6
+ metadata.gz: a26add478d2971183ed4dcedc6cec9f8b23aae2cda5682c0fea41d9560a2f0bc2abdd8c1bf05cb56abc48fab65b942e7df220701469dc690a1701fca78ffb1b0
7
+ data.tar.gz: 646480972fe697e48b5eca15fed1100657a6799adfdcdb710d1675f4fb7f454d97f926ca5b81c76429ebb6efd797c6f0153fd10ae38ba5fb98057eefb204b5f6
@@ -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
- Orchestra::Logger.instance.log "inv-#{Thread.current[:invocation]} #{text}"
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 = Open3.capture2e *cmd
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.blank?
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
@@ -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
- status = 1
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
- output, status =
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
- puts "Checkout finished in #{checkout_time.to_i}s\n"
19
+ log "Checkout finished in #{checkout_time.to_i}s\n"
27
20
 
28
- $stdout.flush
21
+ build_time = Benchmark.realtime do
22
+ execute buildx_build_cmd, escape_arguments: false
23
+ end
29
24
 
30
- exit 1 if status.to_i > 0
25
+ log "Build finished in #{build_time.to_i}s"
31
26
 
32
- exec *buildx_build_cmd
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
- "--cache-from=type=s3,region=#{options.cache_region},bucket=#{options.cache_bucket},name=app",
41
- "--cache-to=type=s3,region=#{options.cache_region},bucket=#{options.cache_bucket},name=app,mode=max",
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 if service.dig("labels", "envirobly.data-volume.pool").blank?
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
@@ -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
@@ -1,5 +1,6 @@
1
1
  require "singleton"
2
2
 
3
+ # @deprecated in favor of Ruby's Logger
3
4
  class Orchestra::Logger
4
5
  include Singleton
5
6
 
@@ -1,3 +1,3 @@
1
1
  module Orchestra
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.3"
3
3
  end
data/lib/orchestra.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Orchestra
2
2
  end
3
3
 
4
- require "active_support"
5
- require "active_support/core_ext"
4
+ # require "active_support"
5
+ # require "active_support/core_ext"
6
6
  require "zeitwerk"
7
7
 
8
8
  loader = Zeitwerk::Loader.for_gem
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.1
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-21 00:00:00.000000000 Z
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