Home

Awesome

Docker Build Management

PyPI version Build Status MIT license

Build Management is a python application, installed with pip. The application makes it easy to manage a build system based on Docker by configuring a single yaml file describing how to build, test, run or publish a containerized solution.

Install Or Upgrade

Verify Installation

Example

Either of the sections (run, build, test, publish, promote) in the yaml file is triggered with the following cli commands:

Each of the command sections (run, build, test, publish, promote) includes context sections, each defined by a suitable key describing that section. Each of the context sections are executed in sequence from top to bottom by default, or you may specify the sections to execute by adding the section keys to the command line:

It is also possible to execute multiple command sections in the same command line:

The swarm section helps deploying necessary domain services needed in the development. Start/Stop/Restart/Wait the swarm:

Please refer to the SwarmManagement project for further info on how to configure the swarm deployment.

By convention, the default yaml filename is build.management.yml. It is possible to specify a separate yaml file (or multiple) with the -f key:

changelog:
    directory: src
    cmd:
        - python ./pythonSnippet.py
    file: CHANGELOG.md
    envKey: VERSION
    envMajorVersionKey: VERSIONMAJOR
    envMinorVersionKey: VERSIONMINOR

env_files: 
    - environment.env

run:
    selections:
        firstSelection:
            directory: src
            environmentVariables:
                ENVIRONMENT_VARIABLE_KEY: environment_variable
            copyFromContainer:
                pythonSnippet:
                    containerSrc: /src/
                    hostDest: output/
            cmd:
                - python ./pythonSnippet.py
            abortOnContainerExit: true
            verifyContainerExitCode: true
            removeContainers: true
            detached: false
            preserveMergedComposeFile: false
            files:
                - docker-compose.pythonSnippet.yml
                - docker-compose.pythonSnippet.overriden.yml
        secondSelection:
            directory: src
            files:
                - docker-compose.pythonSnippet.yml

build:
    selections:
        firstSelection:
            directory: src
            environmentVariables:
                ENVIRONMENT_VARIABLE_KEY: environment_variable
            cmd:
                - python ./pythonSnippet.py
            additionalTag: latest
            additionalTags:
                - ${VERSION:-1.0.0}.beta
                - ${VERSION:-1.0.0}.zeta
            saveImages: ../output
            composeFileWithDigests: docker-compose.digest.pythonSnippet.yml
            preserveMergedComposeFile: false
            files:
                - docker-compose.pythonSnippet.yml

test:
    selections:
        firstSelection:
            directory: src
            environmentVariables:
                ENVIRONMENT_VARIABLE_KEY: environment_variable
            cmd:
                - python ./pythonSnippet.py
            removeContainers: true
            preserveMergedComposeFile: false
            files:
                - docker-compose.pythonSnippet.yml

publish:
    selections:
        firstSelection:
            directory: src
            environmentVariables:
                ENVIRONMENT_VARIABLE_KEY: environment_variable
            cmd:
                - python ./pythonSnippet.py
            additionalTag: latest
            additionalTags:
                - ${VERSION:-1.0.0}.beta
                - ${VERSION:-1.0.0}.zeta
            platforms:
                - linux/amd64
                - linux/arm64
            composeFileWithDigests: docker-compose.digest.pythonSnippet.yml
            preserveMergedComposeFile: false
            files:
                - docker-compose.pythonSnippet.yml
        secondSelection:
            directory: src
            containerArtifact: false
            files:
                - docker-compose.pythonSnippet.yml

promote:
    selections:
        firstSelection:
            directory: src
            environmentVariables:
                ENVIRONMENT_VARIABLE_KEY: environment_variable
            cmd:
                - python ./pythonSnippet.py
            targetTags:
                - latest
                - qaapproved
            sourceFeed: <docker.dockerserver>
            targetFeed: <docker2.dockerserver>
            user: <user_for_target_and_source_feed>
            password: <password_for_target_and_source_feed>
            logout: false
            dryRun: false
            files:
                - docker-compose.pythonSnippet.yml

swarm:
    selections:
        firstSelection:
            directory: src
            environmentVariables:
                ENVIRONMENT_VARIABLE_KEY: environment_variable
            cmd:
                - python ./pythonSnippet.py
            properties:
                - -stack -remove proxy
            files:
                - swarm-management.yml

Please have a look at an example of use here:

Or take a look at another project which takes use of this library:

Section Features

General features

Run Features

The run section runs all listed docker-compose files with docker-compose up.

Build Features

The build section builds all docker images as described by the docker-compose.yml files.

Test Features

The test section runs all services listed in the docker-compose.yml files, and detects if either of the services exited with a non-zero exit code due to an error.

Publish Features

The publish section publishes all docker images listed in the docker-compose.yml files.

Promote Features

The promote section promotes docker images listed in the images property using docker pull, docker tag and docker push.

Swarm Features

The swarm section helps to deploy service stacks to your local swarm. It reuses the SwarmManagement deployment tool to deploy and remove services to and from the Swarm.

General Properties

Prerequisites

Additional Info

Publish New Version

  1. Configure setup.py with new version.
  2. Install build tools: pip install twine wheel
  3. Build: python setup.py bdist_wheel
  4. Check: twine check dist/*
  5. Publish: twine upload dist/*

Test a new version locally

  1. Build: python setup.py bdist_wheel
  2. Install from local file with force-reinstall and no-cache-dir options to force reinstallation when you have changed the code without changing the version number: python -m pip install path\to\yourgitrepo\DockerBuildManagement\dist\DockerBuildManagement-0.0.65-py2.py3-none-any.whl --force-reinstall --no-cache-dir

Run Unit Tests