Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Add labels to support docker stacks #92

Merged
merged 8 commits into from
Oct 18, 2018
Merged

Add labels to support docker stacks #92

merged 8 commits into from
Oct 18, 2018

Conversation

bhuisgen
Copy link
Contributor

@bhuisgen bhuisgen commented Oct 7, 2018

This PR adds the missing labels to docker_network and docker_volume resources allowing to simulate docker-compose stacks. It can be used to support docker UCP/swarm collections.

Improvements:

  • add labels to docker_network and these new flags: attachable, ingress, ipv6
  • add labels to docker_volume
  • add labels to docker_secret
  • fix bug with default bridge network and custom user networks (network_mode + networks). Network aliases are working now (network_alias)

I use this plan to test it with portainer which have the capability to show docker stacks (swarm + docker-compose):

variable "docker_project" {
  default = "test"
}

resource "docker_network" "default" {
  name       = "${var.docker_project}_default"
  attachable = true

  labels {
    "com.docker.compose.network" = "default"
    "com.docker.compose.project" = "${var.docker_project}"
  }
}

resource "docker_volume" "portainer" {
  name = "${var.docker_project}_portainer"

  labels {
    "com.docker.compose.project" = "${var.docker_project}"
    "com.docker.compose.volume"  = "portainer"
  }
}

resource "docker_container" "portainer" {
  count = 1

  image   = "bhuisgen/alpine-portainer:prod"
  name    = "${var.docker_project}_portainer_${count.index + 1}"
  restart = "unless-stopped"

  labels {
    "com.docker.compose.container-number" = "${count.index + 1}"
    "com.docker.compose.project"          = "${var.docker_project}"
    "com.docker.compose.service"          = "portainer"
    "com.docker.compose.oneoff"           = "False"
    "com.docker.compose.version"          = "1.22.0"
  }

  network_mode  = "bridge"
  networks      = ["${docker_network.default.id}"]
  network_alias = ["portainer"]

  ports {
    ip       = "169.254.0.1"
    external = "8080"
    internal = "9000"
  }

  volumes {
    host_path      = "/etc/localtime"
    container_path = "/etc/localtime"
    read_only      = true
  }

  volumes {
    volume_name    = "${docker_volume.portainer.name}"
    container_path = "/var/lib/portainer"
  }

  volumes {
    host_path      = "/var/run/docker.sock"
    container_path = "/var/run/docker.sock"
  }

  env = [
    "ENV=local",
    "PORTAINER_TEMPLATE=generic",
  ]

  log_driver = "syslog"

  log_opts {
    "tag" = "{{.Name}}/{{.ID}}"
  }

  must_run = true
}

@ghost ghost added the size/L label Oct 7, 2018
@bhuisgen bhuisgen changed the title Add labels to support docker-compose stacks Add labels to support docker stacks Oct 8, 2018
@mavogel mavogel added this to the v1.1.0 milestone Oct 8, 2018
@mavogel
Copy link
Contributor

mavogel commented Oct 8, 2018

@bhuisgen thx again for the contribution. Please fix the test failures and update the documentation for the new properties :)

Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>

Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
@mavogel mavogel self-requested a review October 18, 2018 10:37
Copy link
Contributor

@mavogel mavogel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :) Thank you very much for contributing 🎉

@mavogel mavogel self-assigned this Oct 18, 2018
@mavogel mavogel merged commit eca96b9 into hashicorp:master Oct 18, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants