ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 392 forks source link

Support LABEL specification in container.yml #328

Open j00bar opened 7 years ago

j00bar commented 7 years ago

And anything else that you can specify in Dockerfile - make sure it ends up in the built image's JSON.

j00bar commented 7 years ago

@TomasTomecek

TomasTomecek commented 7 years ago

Just to note, the list of available metadata fields is quite long:

chouseknecht commented 7 years ago

Some items on the list are already being handled:

Some items are not currently supported by Ansible Container:

chouseknecht commented 7 years ago

Just for purposes of example and discussion, here's the container.yml used to build an image:

version: "2"
services:
  web:
    image: centos:7
    ports:
      - "8000:80"
    expose:
      - "9000"
    environment:
      - TEST_ENV_VAR=1
    working_dir: /
    user: apache
    volumes:
      - /project
    entrypoint: [/usr/bin/entrypoint.sh]
    labels:
      com.ansible.container.foo: bar
      com.ansible.container.bar: baz
    command: ['/usr/bin/dumb-init', '/usr/sbin/apache2ctl', '-D', 'FOREGROUND']

registries: {}

And, below is the JSON found on the resulting image. Notice all of the supported items from the list above are represented in the Config section:

$ docker inspect labels-web

[
    {
        "Id": "sha256:43c96c9616ed00ce35f35af8f1683dcd852949c14444823cf1c8fc2be34007dc",
        "RepoTags": [
            "labels-web:20170124153443",
            "labels-web:latest"
        ],
        "RepoDigests": [],
        "Parent": "sha256:b0ee41a3ebd2a6bca6f7276b428e886f975deb18d56ccb4f56415a16199c35f9",
        "Comment": "Built using Ansible Container",
        "Created": "2017-01-24T15:34:43.776275895Z",
        "Container": "b4c933a811523706fefe3500d85cc6495fda1300f30c38680606a130b7e86425",
        "ContainerConfig": {
            "Hostname": "b4c933a81152",
            "Domainname": "",
            "User": "root",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {},
                "9000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "ANSIBLE_CONTAINER=1",
                "TEST_ENV_VAR=1",
                "no_proxy=*.local, *.localhost, 169.254/16",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "sh",
                "-c",
                "while true; do sleep 1; done"
            ],
            "Image": "labels-web:latest",
            "Volumes": {
                "/project": {}
            },
            "WorkingDir": "/",
            "Entrypoint": [],
            "OnBuild": null,
            "Labels": {
                "build-date": "20161214",
                "com.ansible.container.bar": "baz",
                "com.ansible.container.foo": "bar",
                "com.docker.compose.config-hash": "2845863dbe5f767f82920cfbd1e006ea3642ef37f6c2c6794a36cd730cedc1eb",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "ansible",
                "com.docker.compose.service": "web",
                "com.docker.compose.version": "1.9.0",
                "license": "GPLv2",
                "name": "CentOS Base Image",
                "vendor": "CentOS"
            }
        },
        "DockerVersion": "1.13.0-rc7",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "apache",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {},
                "9000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "ANSIBLE_CONTAINER=1",
                "TEST_ENV_VAR=1",
                "no_proxy=*.local, *.localhost, 169.254/16",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/usr/bin/dumb-init",
                "/usr/sbin/apache2ctl",
                "-D",
                "FOREGROUND"
            ],
            "ArgsEscaped": true,
            "Image": "",
            "Volumes": {
                "/project": {}
            },
            "WorkingDir": "/",
            "Entrypoint": [
                "/usr/bin/entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "build-date": "20161214",
                "com.ansible.container.bar": "baz",
                "com.ansible.container.foo": "bar",
                "com.docker.compose.config-hash": "2845863dbe5f767f82920cfbd1e006ea3642ef37f6c2c6794a36cd730cedc1eb",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "",
                "com.docker.compose.project": "labels",
                "com.docker.compose.service": "web",
                "com.docker.compose.version": "1.9.0",
                "license": "GPLv2",
                "name": "CentOS Base Image",
                "vendor": "CentOS"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 314255285,
        "VirtualSize": 314255285,
        "GraphDriver": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/fe2ba1dddc4e93c534e9e5d965f8c33c5990c03211fe22b0d4162b97d2cff5e6/diff:/var/lib/docker/overlay2/72c7558e9d1186e829b35ec327ff502e9bc727f3fb06b9720c9a08c8072fac06/diff",
                "MergedDir": "/var/lib/docker/overlay2/aa4235070d90156b6374b2c44a21bd475c59f325e2bbccbcc217418360c9a53e/merged",
                "UpperDir": "/var/lib/docker/overlay2/aa4235070d90156b6374b2c44a21bd475c59f325e2bbccbcc217418360c9a53e/diff",
                "WorkDir": "/var/lib/docker/overlay2/aa4235070d90156b6374b2c44a21bd475c59f325e2bbccbcc217418360c9a53e/work"
            }
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:34e7b85d83e48a22bd5dfa2b6b9ee9565b7ef672f09b3d2409c61635f9bca4db",
                "sha256:e54a4ebb1a941cfa8e0717f1b6611c3d17541ac2fe7c598e268f6b10be89285e",
                "sha256:7995725458dd53094ff47fedb0b9098482adc0c071b01f9718e917f973805fd9"
            ]
        }
    }
]