Updated mappings, sample yml and options.

This commit is contained in:
Fabian Schlenz 2020-09-04 06:18:38 +02:00
parent 18eb80ebf6
commit eee7b009a4

119
dup.rb
View File

@ -7,6 +7,16 @@ require 'ostruct'
require 'json' require 'json'
MAPPINGS = [ MAPPINGS = [
# Syntax:
# [name_in_yml, docker_option_name, lambda_for_creating_yml_for_container=nil, options={}]
# Options are:
# type: Sets type of this option
# switch: Only adds the docker_option_name to the command, ignoring the value.
# name: Value will be set to the name of the container (from yml filename or root element)
# hidden: Will not be added to the run command
# allow_empty: May be empty.
# escape: If set to false, will not be shellescaped
['stdin_open', '--interactive', lambda{|c,i| c.Config.OpenStdin}, {:type=>:switch}], ['stdin_open', '--interactive', lambda{|c,i| c.Config.OpenStdin}, {:type=>:switch}],
['tty', '--tty', lambda{|c,i| c.Config.Tty}, {:type=>:switch}], ['tty', '--tty', lambda{|c,i| c.Config.Tty}, {:type=>:switch}],
#['detach', '--detach', {:type=>:switch}], #['detach', '--detach', {:type=>:switch}],
@ -31,74 +41,74 @@ MAPPINGS = [
['working_dir', '--workdir', lambda{|c,i| (wd=c.Config.WorkingDir) == i.Config.WorkingDir ? nil : wd}], ['working_dir', '--workdir', lambda{|c,i| (wd=c.Config.WorkingDir) == i.Config.WorkingDir ? nil : wd}],
['init', '--init', lambda{|c,i| c.Config.Init}, {:type=>:switch}], ['init', '--init', lambda{|c,i| c.Config.Init}, {:type=>:switch}],
['image', nil, lambda{|c,i| c.Config.Image}], ['image', nil, lambda{|c,i| c.Config.Image}],
['command', nil, lambda{|c,i| (cmd=c.Config.Cmd.join(" ") rescue nil) == (i.Config.Cmd.join(" ") rescue nil)? nil : cmd}, {:escape=>false}],
['test', nil, nil, {type: :hidden}],
['auto_update', nil, nil, {type: :hidden}] ['auto_update', nil, nil, {type: :hidden}]
] ]
def get_sample(name="container") def get_sample(name="container")
return <<~HEREDOC return <<~HEREDOC
#{name}: image: "my/image:1.2.3"
image: "my/image:1.2.3" restart: always
restart: always detach: true
detach: true test: true # Having this set to true will prevent dup from creating a label de.fabianonline.dup
test: true # Having this set to true will prevent dup from creating a label de.fabianonline.dup auto_update: true # Enabling this adds a label to allow watchtower to automatically update this container
ports: ports:
- "1234:1234" - "1234:1234"
- "8080" - "8080"
- "1001:1001/udp" - "1001:1001/udp"
environment: environment:
VERSION: 1.7.0 VERSION: 1.7.0
TZ: TZ:
volumes: volumes:
- "/etc/localtime:/etc/localtime:ro" - "/etc/localtime:/etc/localtime:ro"
links: labels:
- "another_container" nginx_virtual_host: container.home.schle.nz
nginx_port: 80
nginx_additional_ports: "443, 5050"
nginx_allow: fabian # "user" or "@group" or "user, user, @group" or "all"
nginx_no_robots: true
nginx_public_paths: "/public, /api"
nginx_type: # "http" (default), "https", "skip" (doesn't create any entries)
nginx_client_max_body_size: 25M
labels: networks:
com.centurylinklabs.watchtower.enable: true - "nginx"
nginx_virtual_host: container.home.fabianonline.de - "mosquitto"
nginx_port: 80 - "bridge"
nginx_allow: fabian # "user" or "@group" or "user, user, @group" or "all"
nginx_no_robots: true
nginx_public_paths: "/public, /api"
nginx_type: # "http" (default), "fastcgi", "skip" (doesn't create any entries)
networks: user: "1000:1000"
- "nginx" command: "/bin/bash"
- "mosquitto" entrypoint: "/script.sh"
- "bridge" build: "/data/dir"
pull: false
container_name: "Something"
hostname: "foo"
mem_limit: 125M
stdin_open: false
net: host
tty: false
remove: false
stop_signal: SIGUSR1
stop_grace_period: 5
test: true before_build:
command: "/bin/bash" - "echo 'Starting build'"
entrypoint: "/script.sh" after_build:
build: "/data/dir" - "echo 'After build'"
pull: false before_run:
container_name: "Something" - "echo 'Starting run'"
hostname: "foo" after_run:
mem_limit: 125M - "echo 'Run has finished.'"
stdin_open: false
net: host
tty: false
remove: false
stop_signal: SIGUSR1
stop_grace_period: 5
before_build:
- "echo 'Starting build'"
after_build:
- "echo 'After build'"
before_run:
- "echo 'Starting run'"
after_run:
- "echo 'Run has finished.'"
- "docker restart container" - "docker restart container"
devices: devices:
- "/dev/ttyUSB0:/dev/ttyUSB0" - "/dev/ttyUSB0:/dev/ttyUSB0"
HEREDOC HEREDOC
end end
@ -245,7 +255,7 @@ class Container
if !@data["test"] if !@data["test"]
add_label("de.fabianonline.dup", "true") add_label("de.fabianonline.dup", "true")
end end
if @data["auto_update"] if @data["auto_update"]
add_label("com.centurylinklabs.watchtower.enable", "true") add_label("com.centurylinklabs.watchtower.enable", "true")
@ -431,6 +441,7 @@ opts = GetoptLong.new(
[ '--update', '-u', GetoptLong::NO_ARGUMENT ], [ '--update', '-u', GetoptLong::NO_ARGUMENT ],
[ '--_completion', GetoptLong::OPTIONAL_ARGUMENT ], [ '--_completion', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--host', GetoptLong::NO_ARGUMENT ], [ '--host', GetoptLong::NO_ARGUMENT ],
[ '--regenerate', GetoptLong::NO_ARGUMENT ],
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
[ '--all', GetoptLong::NO_ARGUMENT ], [ '--all', GetoptLong::NO_ARGUMENT ],
) )