docker-container-running

Description

Installs docker (if necessary), then downloads and executes a Docker image.

TODO: Add other important 'docker run' flags. Maybe not all of them, have a 'docker-container-running-export' (or so) frecklet for that. Probably also have a different frecklet for interactive docker containers that can take command-line arguments. Not sure yet.

Variables

Name Type Default Description

image

string --

The image to use. Required

name

string --

A name to identify this container with. Required

volumes

list --

A list of volumes to mount. Required

ensure_docker_installed

boolean False

Install Docker if not already present.

ports

list []

A list of ports to expose on the host.

users

list --

A list of users who will be added to the 'docker' group.

Code

doc:
  short_help: Makes sure a specific docker image is running on this machine.
  help: |
    Installs docker (if necessary), then downloads and executes a Docker image.

    TODO: Add other important 'docker run' flags. Maybe not all of them, have a 'docker-container-running-export' (or so) frecklet for that.
    Probably also have a different frecklet for interactive docker containers that can take command-line arguments. Not sure yet.

args:
  _import:
  - docker-service
  name:
    doc:
      short_help: A name to identify this container with.
    type: string
    required: true
  ensure_docker_installed:
    doc:
      short_help: Install Docker if not already present.
    type: boolean
    required: false
    default: false
  ports:
    doc:
      short_help: A list of ports to expose on the host.
    type: list
    schema:
      type: string
    default: []
    empty: true
    cli:
      param_decls:
      - --port
      - -p
  image:
    doc:
      short_help: The image to use.
    type: string
    required: true
  volumes:
    doc:
      short_help: A list of volumes to mount.
    type: list
    schema:
      type: string
    empty: true
    cli:
      param_decls:
      - --volume
      - -v

frecklets:
- docker-service:
    frecklet::skip: '{{:: ensure_docker_installed | negate ::}}'
    users: '{{:: users ::}}'
- frecklet:
    name: docker_container
    type: ansible-module
    desc:
      short: 'executing docker image: {{:: image ::}}'
    properties:
      idempotent: true
      internet: true
      elevated: true
    resources:
      python-package:
      - docker
  task:
    become: true
  vars:
    name: '{{:: name ::}}'
    image: '{{:: image ::}}'
    published_ports: '{{:: ports ::}}'
    volumes: '{{:: volumes ::}}'
frecklecute docker-container-running --help

Usage: frecklecute docker-container-running [OPTIONS]

  Installs docker (if necessary), then downloads and executes a Docker
  image.

  TODO: Add other important 'docker run' flags. Maybe not all of them, have
  a 'docker-container-running-export' (or so) frecklet for that. Probably
  also have a different frecklet for interactive docker containers that can
  take command-line arguments. Not sure yet.

Options:
  --image IMAGE                   The image to use.  [required]
  --name NAME                     A name to identify this container with.
                                  [required]
  -v, --volume VOLUMES            A list of volumes to mount.  [required]
  --ensure-docker-installed / --no-ensure-docker-installed
                                  Install Docker if not already present.
  -p, --port PORTS                A list of ports to expose on the host.
  -u, --user USER                 A list of users who will be added to the
                                  'docker' group.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.docker_container_running.DockerContainerRunning
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class DockerContainerRunning(AutoPycklet):
    """Installs docker (if necessary), then downloads and executes a Docker image.

     TODO: Add other important 'docker run' flags. Maybe not all of them, have a 'docker-container-running-export' (or so) frecklet for that.
     Probably also have a different frecklet for interactive docker containers that can take command-line arguments. Not sure yet.

       Args:
         ensure_docker_installed: Install Docker if not already present.
         image: The image to use.
         name: A name to identify this container with.
         ports: A list of ports to expose on the host.
         users: A list of users who will be added to the 'docker' group.
         volumes: A list of volumes to mount.

    """

    FRECKLET_ID = "docker-container-running"

    ensure_docker_installed: bool = None
    image: str = None
    name: str = None
    ports: List = None
    users: List = None
    volumes: List = None


    def __post_init__(self):
        super(DockerContainerRunning, self).__init__(var_names=["ensure_docker_installed", "image", "name", "ports", "users", "volumes"])


frecklet_class = DockerContainerRunning
# -*- coding: utf-8 -*-


#
# module path: pycklets.docker_container_running.DockerContainerRunning
#


from pyckles import AutoPycklet

class DockerContainerRunning(AutoPycklet):
    """Installs docker (if necessary), then downloads and executes a Docker image.

     TODO: Add other important 'docker run' flags. Maybe not all of them, have a 'docker-container-running-export' (or so) frecklet for that.
     Probably also have a different frecklet for interactive docker containers that can take command-line arguments. Not sure yet.

       Args:
         ensure_docker_installed: Install Docker if not already present.
         image: The image to use.
         name: A name to identify this container with.
         ports: A list of ports to expose on the host.
         users: A list of users who will be added to the 'docker' group.
         volumes: A list of volumes to mount.

    """

    FRECKLET_ID = "docker-container-running"

    def __init__(self, ensure_docker_installed=None, image=None, name=None, ports=None, users=None, volumes=None):

        super(DockerContainerRunning, self).__init__(var_names=["ensure_docker_installed", "image", "name", "ports", "users", "volumes"])
        self._ensure_docker_installed = ensure_docker_installed
        self._image = image
        self._name = name
        self._ports = ports
        self._users = users
        self._volumes = volumes

    @property
    def ensure_docker_installed(self):
        return self._ensure_docker_installed

    @ensure_docker_installed.setter
    def ensure_docker_installed(self, ensure_docker_installed):
        self._ensure_docker_installed = ensure_docker_installed

    @property
    def image(self):
        return self._image

    @image.setter
    def image(self, image):
        self._image = image

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name

    @property
    def ports(self):
        return self._ports

    @ports.setter
    def ports(self, ports):
        self._ports = ports

    @property
    def users(self):
        return self._users

    @users.setter
    def users(self, users):
        self._users = users

    @property
    def volumes(self):
        return self._volumes

    @volumes.setter
    def volumes(self, volumes):
        self._volumes = volumes



frecklet_class = DockerContainerRunning