class Companion::Manager

Overview

Manage all docker operations.

Some care must be taken for updates to be detected. At startup, the images state is saved. You can then add project.

When upping a project, missing images will be pulled, but not new ones, and the images state will be refreshed.

You should then run periodically Companion::Manager#check_updates which pulls all images and yield Companion::UpdateEvent for each service that can be updated.

Defined in:

events.cr
manager.cr

Constant Summary

Log = Companion::Log.for(self)

Constructors

Instance Method Summary

Constructor Detail

def self.new(docker : Docker::Client) #

Create an new Manager.


[View source]

Instance Method Detail

def add_project(name : String, content : String, working_directory : Path | Nil = nil) #

Add a new project.

The project must have a unique name, and content must be a some YAML describing the project using docker-compose 3.8 format. working_directory must be the project's directory. It is used to find bind mounts.


[View source]
def check_updates(&block : UpdateEvent -> ) : Nil #

Checks if there are images update.

If an update is found, the block is called with an event indicating the image name and the projects's containers concerned.


[View source]
def create(name : String) : Nil #

Creates missing containers for the project name.

It pulls the image if needed. If the container are already there, it does not recreate them even if their config changed.


[View source]
def create_container(project_name : String, service : Companion::Docker::Compose::Service) : String #

[View source]
def down(name : String) : Nil #

Kills and removes all containers for the project name.


[View source]
def down(name : String, &block : String -> ) : Nil #

Kills and removes all containers for the project name.

Yield each service name.


[View source]
def down_service(project_name : String, service_name : String) : Nil #

Kills and removes the service service_name container for the project project_name.


[View source]
def each_projects #

Returns an iterator over the projects' names.


[View source]
def get_logs(project_name : String, name : String) : String #

Returns a project container's logs


[View source]
def images : Hash(String, Companion::Manager::ImageState) #

[View source]
def networks : Array(Companion::Docker::Client::Network) #

[View source]
def pull_image(image : String) : Nil #

Pull an image.

The image name can contains a tag in the form "image:tag", and even a registry in the form "regitry/image:tag".


[View source]
def pull_images(name : String) : Nil #

Pulls the docker images for the project name.


[View source]
def start(name : String) #

Starts all the containers for the project name.

If a container is already running, it does nothing.


[View source]
def up(name : String) #

Creates and starts containers for the project name.


[View source]
def up_service(project_name : String, service_name : String) : Nil #

Creates and starts the service service_name container for project project_name.

It does not pull the image.


[View source]