propellor-5.17: property-based host configuration management in haskell

Maintainer | currently unmaintained; your name here!
Safe Haskell | Safe-Inferred
Language | Haskell2010

Propellor.Property.Docker

Contents

- Host properties
- Container configuration
- Internal use

Description

Docker support for propellor

The existance of a docker container is just another Property of a system, which propellor can set up. See config.hs for an example.

Synopsis

- installed :: Property (DebianLike + ArchLinux)
- configured :: Property (HasInfo + DebianLike)
- container :: ContainerName -> Image -> Props metatypes -> Container
- docked :: Container -> RevertableProperty (HasInfo + Linux) (HasInfo + Linux)
- imageBuilt :: HasImage c => FilePath -> c -> Property Linux
- imagePulled :: HasImage c => c -> Property Linux
- memoryLimited :: Property DebianLike
- garbageCollected :: Property Linux
- tweaked :: Property Linux
- data Image = Image {
  - repository :: String
  - tag :: Maybe String
  }
- latestImage :: String -> Image
- type ContainerName = String
- data Container = Container Image Host
- class HasImage a where
  - getImageName :: a -> Image
- dns :: String -> Property (HasInfo + Linux)
- hostname :: String -> Property (HasInfo + Linux)
- class Publishable p
- publish :: Publishable p => p -> Property (HasInfo + Linux)
- expose :: String -> Property (HasInfo + Linux)
- user :: String -> Property (HasInfo + Linux)
- class Mountable p
- volume :: Mountable v => v -> Property (HasInfo + Linux)
- volumes_from :: ContainerName -> Property (HasInfo + Linux)
- workdir :: String -> Property (HasInfo + Linux)
- memory :: String -> Property (HasInfo + Linux)
- cpuShares :: Int -> Property (HasInfo + Linux)
- link :: ContainerName -> ContainerAlias -> Property (HasInfo + Linux)
- environment :: (String, String) -> Property (HasInfo + Linux)
- type ContainerAlias = String
- restartAlways :: Property (HasInfo + Linux)
- restartOnFailure :: Maybe Int -> Property (HasInfo + Linux)
- restartNever :: Property (HasInfo + Linux)
- init :: String -> IO ()
- chain :: [Host] -> HostName -> String -> IO ()

# Host properties

installed :: Property (DebianLike + ArchLinux) Source #

configured :: Property (HasInfo + DebianLike) Source #

Configures docker with an authentication file, so that images can be pushed to index.docker.io. Optional.

container :: ContainerName -> Image -> Props metatypes -> Container Source #

Defines a Container with a given name, image, and properties. Add properties to configure the Container.

    container "web-server" (latestImage "debian") $ props
       & publish "80:80"
       & Apt.installed {"apache2"]
       & ...

docked :: Container -> RevertableProperty (HasInfo + Linux) (HasInfo + Linux) Source #

Ensures that a docker container is set up and running.

The container has its own Properties which are handled by running propellor inside the container.

When the container's Properties include DNS info, such as a CNAME, that is propagated to the Info of the Host it's docked in.

Reverting this property ensures that the container is stopped and removed.

imageBuilt :: HasImage c => FilePath -> c -> Property Linux Source #

Build the image from a directory containing a Dockerfile.

imagePulled :: HasImage c => c -> Property Linux Source #

Pull the image from the standard Docker Hub registry.

memoryLimited :: Property DebianLike Source #

Configures the kernel to respect docker memory limits.

This assumes the system boots using grub 2. And that you don't need any other GRUB_CMDLINE_LINUX_DEFAULT settings.

Only takes effect after reboot. (Not automated.)

garbageCollected :: Property Linux Source #

Causes *any* docker images that are not in use by running containers to be deleted. And deletes any containers that propellor has set up before that are not currently running. Does not delete any containers that were not set up using propellor.

Generally, should come after the properties for the desired containers.

tweaked :: Property Linux Source #

Tweaks a container to work well with docker.

Currently, this consists of making pam_loginuid lines optional in the pam config, to work around https://github.com/docker/docker/issues/5663 which affects docker 1.2.0.

data Image Source #

A docker image, that can be used to run a container. The user has to specify a name and can provide an optional tag. See Docker Image Documention for more information.

Constructors

Image |

Fields

- repository :: String
- tag :: Maybe String

#### Instances

Instances details

Read Image Source # |
Instance details Defined in Propellor.Property.Docker Methods readsPrec :: Int -> ReadS Image readList :: ReadS [Image] readPrec :: ReadPrec Image readListPrec :: ReadPrec [Image]
Show Image Source # |
Instance details Defined in Propellor.Property.Docker Methods showsPrec :: Int -> Image -> ShowS show :: Image -> String showList :: [Image] -> ShowS
Eq Image Source # |
Instance details Defined in Propellor.Property.Docker Methods (==) :: Image -> Image -> Bool (/=) :: Image -> Image -> Bool
HasImage Image Source # |
Instance details Defined in Propellor.Property.Docker Methods getImageName :: Image -> Image Source #

latestImage :: String -> Image Source #

Defines a Docker image without any tag. This is considered by Docker as the latest image of the provided repository.

type ContainerName = String Source #

A short descriptive name for a container. Should not contain whitespace or other unusual characters, only [a-zA-Z0-9_-] are allowed

data Container Source #

A docker container.

Constructors

Container Image Host |

#### Instances

Instances details

IsContainer Container Source # |
Instance details Defined in Propellor.Property.Docker Methods containerProperties :: Container -> [ChildProperty] Source # containerInfo :: Container -> Info Source # setContainerProperties :: Container -> [ChildProperty] -> Container Source #
HasImage Container Source # |
Instance details Defined in Propellor.Property.Docker Methods getImageName :: Container -> Image Source #

class HasImage a where Source #

Methods

getImageName :: a -> Image Source #

#### Instances

Instances details

HasImage Container Source # |
Instance details Defined in Propellor.Property.Docker Methods getImageName :: Container -> Image Source #
HasImage Image Source # |
Instance details Defined in Propellor.Property.Docker Methods getImageName :: Image -> Image Source #

# Container configuration

dns :: String -> Property (HasInfo + Linux) Source #

Set custom dns server for container.

hostname :: String -> Property (HasInfo + Linux) Source #

Set container host name.

class Publishable p Source #

Minimal complete definition

toPublish

#### Instances

Instances details

Publishable String Source # | string format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort
Instance details Defined in Propellor.Property.Docker Methods toPublish :: String -> String
Publishable (Bound Port) Source # |
Instance details Defined in Propellor.Property.Docker Methods toPublish :: Bound Port -> String

publish :: Publishable p => p -> Property (HasInfo + Linux) Source #

Publish a container's port to the host

expose :: String -> Property (HasInfo + Linux) Source #

Expose a container's port without publishing it.

user :: String -> Property (HasInfo + Linux) Source #

Username or UID for container.

class Mountable p Source #

Minimal complete definition

toMount

#### Instances

Instances details

Mountable String Source # | string format: [host-dir]:[container-dir]:[rw|ro] With just a directory, creates a volume in the container.
Instance details Defined in Propellor.Property.Docker Methods toMount :: String -> String
Mountable (Bound FilePath) Source # |
Instance details Defined in Propellor.Property.Docker Methods toMount :: Bound FilePath -> String

volume :: Mountable v => v -> Property (HasInfo + Linux) Source #

Mount a volume

volumes_from :: ContainerName -> Property (HasInfo + Linux) Source #

Mount a volume from the specified container into the current container.

workdir :: String -> Property (HasInfo + Linux) Source #

Work dir inside the container.

memory :: String -> Property (HasInfo + Linux) Source #

Memory limit for container. Format: number unit, where unit = b, k, m or g

Note: Only takes effect when the host has the memoryLimited property enabled.

cpuShares :: Int -> Property (HasInfo + Linux) Source #

CPU shares (relative weight).

By default, all containers run at the same priority, but you can tell the kernel to give more CPU time to a container using this property.

link :: ContainerName -> ContainerAlias -> Property (HasInfo + Linux) Source #

Link with another container on the same host.

environment :: (String, String) -> Property (HasInfo + Linux) Source #

Set environment variable with a tuple composed by the environment variable name and its value.

type ContainerAlias = String Source #

A short alias for a linked container. Each container has its own alias namespace.

restartAlways :: Property (HasInfo + Linux) Source #

This property is enabled by default for docker containers configured by propellor; as well as keeping badly behaved containers running, it ensures that containers get started back up after reboot or after docker is upgraded.

restartOnFailure :: Maybe Int -> Property (HasInfo + Linux) Source #

Docker will restart the container if it exits nonzero. If a number is provided, it will be restarted only up to that many times.

restartNever :: Property (HasInfo + Linux) Source #

Makes docker not restart a container when it exits Note that this includes not restarting it on boot!

# Internal use

init :: String -> IO () Source #

Called when propellor is running inside a docker container. The string should be the container's ContainerId.

This process is effectively init inside the container. It even needs to wait on zombie processes!

In the foreground, run an interactive bash (or sh) shell, so that the user can interact with it when attached to the container.

When the system reboots, docker restarts the container, and this is run again. So, to make the necessary services get started on boot, this needs to provision the container then. However, if the container is already being provisioned by the calling propellor, it would be redundant and problimatic to also provisoon it here, when not booting up.

The solution is a flag file. If the flag file exists, then the container was already provisioned. So, it must be a reboot, and time to provision again. If the flag file doesn't exist, don't provision here.

chain :: [Host] -> HostName -> String -> IO () Source #