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 f78c05b commit 54cd6bb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 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.7)
dry-stack (0.1.8)

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.7
Version: 0.1.8
Usage:
dry-stack -s stackfile [options] COMMAND
cat stackfile | dry-stack COMMAND
Expand Down
20 changes: 16 additions & 4 deletions lib/dry-stack/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,12 @@ def to_compose(opts = @options)
end

service[:networks]&.map! do |network|
if network.is_a? Hash
if network.is_a?(Hash)
if network.key?(:name)
n_name= network[:name].gsub('-','_').to_sym
compose[:networks][n_name] ||= {}
compose[:networks][n_name].merge! network.slice(:name, :driver, :driver_opts, :attachable, :external, :labels)
n_name = network[:name].gsub('-','_').to_sym
if n_name != :default
(compose[:networks][n_name] ||= {}).merge! network
end
n_name
else
$stderr.puts ':name must be specified in network declaration'
Expand Down Expand Up @@ -331,6 +332,17 @@ def After(&block)
(@after_blocks ||=[]) << block
end

# TODO: latter
# def ServicesEach(names, &)
# def ServicesEach(names, opts, &)
def ServicesEach(&)
After do
@services.values.each do |svc|
ServiceFunction.new(svc,&) if block_given?
end
end
end

def PublishPorts(ports)
@publish_ports.merge! ports.to_h { |k, v| [k,[v].flatten] }
end
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.7'
VERSION = '0.1.8'
end
end
13 changes: 11 additions & 2 deletions spec/data/stack16-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ services:
admin:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT_FRONT: "/otel"
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel/
OTEL_EXPORTER_OTLP_ENDPOINT: http://otlp_collector:4318/
OTEL_RESOURCE_ATTRIBUTES: deployment.environment=stack_name,service.name=stack_name_admin
OTEL_LOG_LEVEL: error
OTEL_TRACES_EXPORTER: otlp
REPLICA: "{{.Task.Slot}}"
CONSOLE_LEVEL: error
SERVICE_INFO: 'true'
STACK_NAME: stack_name
STACK_SERVICE_NAME: admin
image: frontend
Expand All @@ -17,11 +19,18 @@ services:
- 8.8.4.4
- 7.7.4.4
- 6.6.4.4
networks:
- grafana_network
- default
logging:
driver: loki
options:
loki-url: http://localhost:3100/loki/api/v1/push
loki-url: http://loki:3100/loki/api/v1/push
loki-batch-size: 100
loki-retries: 2
loki-max-backoff: 1000ms
loki-timeout: 1s
networks:
grafana_network:
name: grafana-network
external: true
26 changes: 26 additions & 0 deletions spec/data/stack16.drs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,34 @@ DSC
Options name: 'stack_name', traefik: true
Include 'base.drs'



Service :admin, image: 'frontend:latest', ports: 5000 do
dns '8.8.8.8'
dns '8.8.4.4'
dns ['7.7.4.4','6.6.4.4']
end

# TODO: latter
# ServicesEach :admin, env: {A:1}
# ServicesEach [:admin], env: {A:1}
# ServicesEach env: {A:1}

ServicesEach do
network name: 'grafana-network', external: true
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',
}

env OTEL_EXPORTER_OTLP_ENDPOINT_FRONT: '/otel',
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otlp_collector:4318/",
OTEL_RESOURCE_ATTRIBUTES: 'deployment.environment=%{stack-name},service.name=%{service-name}',
OTEL_LOG_LEVEL: 'error',
CONSOLE_LEVEL: 'error',
OTEL_TRACES_EXPORTER:'otlp',
SERVICE_INFO:'true',
REPLICA: "{{.Task.Slot}}"
end

0 comments on commit 54cd6bb

Please sign in to comment.