Skip to content

SWARM: Deploy Docker Ready Images

Current Status:

At the moment, Lakedrops is using stateless containers. This essentially means that the project-specific source code is mounted into the container upon startup instead of providing it with a stateful container.

Motivation

Stateful containers have several key advantages over stateless containers:

  • They are not tied to a server in order to start the project.
  • There is no need for special source code handling in cluster environments.
  • Related CI pipeline tasks do not require an ssh connection since the pipeline pushes the deployment-ready image into a container registry. The cluster monitors the registry and takes care of the deployment.

Requirements

  • The image should function without source code volume mounts upon startup.
  • Parameters and configurations needed, that are not already in the image, must be provided via environment variables upon startup.
  • All related services, such as redis, mariadb, minio, need to be configurable via environment variables upon startup.
  • The images require a unique docker tag for identification. Ideally, this should incorporate some semantic versioning concept.
  • Build and push the image to the gitlab container registry.

Suggestion

Create an additional CI task that utilizes the build artifact of the project to generate a stateful container. This can be achieved by adding a new step in your CI pipeline configuration file with the necessary commands to build and push the image.

create_stateful_image:
  stage: deploy
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - docker build --rm -f Dockerfile.stateful -t $CI_REGISTRY_IMAGE:latest .
    - docker push $CI_REGISTRY_IMAGE:latest