Class: DockerComposeDeploy::Actions::Deployment

Inherits:
Struct
  • Object
show all
Defined in:
lib/docker_compose_deploy/actions/deployment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ignore_pull_failuresObject

Returns the value of attribute ignore_pull_failures

Returns:

  • (Object)

    the current value of ignore_pull_failures



5
6
7
# File 'lib/docker_compose_deploy/actions/deployment.rb', line 5

def ignore_pull_failures
  @ignore_pull_failures
end

#shellObject

Returns the value of attribute shell

Returns:

  • (Object)

    the current value of shell



5
6
7
# File 'lib/docker_compose_deploy/actions/deployment.rb', line 5

def shell
  @shell
end

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/docker_compose_deploy/actions/deployment.rb', line 7

def create
  shell.ssh!("mkdir -p ./sites")
  shell.ssh!("rm -rf ./sites/config") # bin/deploy is irreversible :)
  shell.scp!("./sites/config/", "#{connection}:./sites/config", "-r")

  docker_compose.services.each do |service_name|
    shell.ssh!("mkdir -p ./sites/config/#{service_name}")
    shell.ssh!("mkdir -p ./sites/data/#{service_name}")
    shell.ssh!("mkdir -p ./sites/log/#{service_name}")
  end

  if DockerComposeDeploy.config.stack?
    shell.scp!(docker_compose.path, "#{connection}:./docker-stack.yml")
    shell.ssh!("docker node ls || docker swarm init") # ensure a swarm is initialized
    shell.ssh!("docker stack rm dcd_stack || exit 0") # try to remove previous stack
    shell.ssh!("while docker ps | grep dcd > /dev/null; do echo 'waiting for shutdown' && sleep 1; done")
    shell.ssh!("docker stack deploy --compose-file docker-stack.yml dcd_stack")
  else
    shell.scp!(docker_compose.path, "#{connection}:./docker-compose.yml")
    shell.ssh!("docker-compose down")
    shell.ssh!("docker-compose pull #{ignore_pull_failures_option}")
    shell.ssh!("docker-compose up -d")
  end

  shell.notify "success"
end