Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
artyomb committed Jul 31, 2024
1 parent 120cf67 commit 97fa90e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
dry-stack (0.1.9)
dry-stack (0.1.10)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This gem allows ...
cat simple_stack.drs | dry-stack -e to_compose | docker stack deploy -c - simple_stack
$ dry-stack
Version: 0.1.9
Version: 0.1.10
Usage:
dry-stack -s stackfile [options] COMMAND
cat stackfile | dry-stack COMMAND
Expand Down
17 changes: 8 additions & 9 deletions lib/dry-stack/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def deep_merge!(second)
end
end

def each_recursive(parent, each_ =-> { _1.respond_to?(:each) ? _1.each : [] }, path = [], &blk)
def each_recursive(parent, each_ = -> { _1.respond_to?(:each) ? _1.each : [] }, path = [], &blk)
each2_ = each_.is_a?(Array) ? ->(p) { (m = each_.find { p.respond_to? _1 }) ? p.send(m) : [] } : each_
(each2_[parent] || []).each do |(k,v)|
blk.call [path + [parent], k, v, path]
Expand Down Expand Up @@ -332,13 +332,11 @@ def After(&block)
(@after_blocks ||=[]) << block
end

# TODO: latter
# def ServicesEach(names, &)
# def ServicesEach(names, opts, &)
def ServicesEach(&block)
def ServicesEach(name = nil, opts = {}, &block)
After do
@services.values.each do |svc|
ServiceFunction.new(svc, &block) if block_given?
name ||= @services.keys
[name].flatten.each do |s_name|
Service s_name, opts, &block
end
end
end
Expand All @@ -348,12 +346,13 @@ def PublishPorts(ports)
end

def Service(name, opts = {}, &)
opts = opts.dup
opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
opts[:environment] = opts.delete(:env) if opts.key? :env

service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}}
service.merge! opts
ServiceFunction.new(service, &) if block_given?
service.deep_merge! opts
ServiceFunction.new(service, &) if block_given?
end

def Description(string)
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Dry
class Stack
VERSION = '0.1.9'
VERSION = '0.1.10'
end
end
29 changes: 29 additions & 0 deletions spec/data/stack16-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
---
version: '3.8'
services:
front:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT_FRONT: "/otel"
OTEL_EXPORTER_OTLP_ENDPOINT: http://otlp_collector:4318/
OTEL_RESOURCE_ATTRIBUTES: deployment.environment=stack_name,service.name=stack_name_front
OTEL_LOG_LEVEL: error
OTEL_TRACES_EXPORTER: otlp
REPLICA: "{{.Task.Slot}}"
CONSOLE_LEVEL: error
SERVICE_INFO: 'true'
FRONT_CONF: base4
FRONT_CONF2: base_1
CONF: base1
STACK_NAME: stack_name
STACK_SERVICE_NAME: front
image: frontend
networks:
- grafana_network
- default
logging:
driver: loki
options:
loki-url: http://loki:3100/loki/api/v1/push
loki-batch-size: 100
loki-retries: 2
loki-max-backoff: 1000ms
loki-timeout: 1s
admin:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT_FRONT: "/otel"
Expand All @@ -11,6 +38,8 @@ services:
REPLICA: "{{.Task.Slot}}"
CONSOLE_LEVEL: error
SERVICE_INFO: 'true'
FRONT_CONF: base4
CONF: base1
STACK_NAME: stack_name
STACK_SERVICE_NAME: admin
image: frontend
Expand Down
15 changes: 15 additions & 0 deletions spec/data/stack16.drs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Include 'base.drs'



Service :front, image: 'frontend:latest', ports: 5000

Service :admin, image: 'frontend:latest', ports: 5000 do
dns '8.8.8.8'
dns '8.8.4.4'
Expand Down Expand Up @@ -36,3 +38,16 @@ ServicesEach do
SERVICE_INFO:'true',
REPLICA: "{{.Task.Slot}}"
end

ServicesEach :front do
env FRONT_CONF: 'base1'
end

ServicesEach :front, env: {FRONT_CONF2: 'base_1'} do
env FRONT_CONF: 'base2'
end

ServicesEach [:front, :admin], env: {FRONT_CONF: 'base_3'} do
env CONF: 'base1'
env FRONT_CONF: 'base4'
end

0 comments on commit 97fa90e

Please sign in to comment.