Automate Test, Build, Package & Publishing of code all through containers
Clone or download
Cromel Merge pull request #128 from d3sw/update_vers
updated version to  v_0.2.13
Latest commit 81f36ce Oct 23, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs add description of service name (#113) Jan 23, 2018
scripts drclean: cleanup network interfaces (#63) Aug 1, 2017
testdata Fixed version getting wrong tag (#127) Oct 22, 2018
.gitignore Build fixes (#44 #67 #56) Aug 25, 2017
.mold.yml Fixed build configs Aug 21, 2017
.travis.yml Fixed deploy yaml Sep 7, 2017
CONTRIBUTING.md Update CONTRIBUTING.md Aug 1, 2017
Dockerfile init commit Jul 28, 2017
Gopkg.lock use dep to manage dependencies & update tests Aug 22, 2017
Gopkg.toml use dep to manage dependencies & update tests Aug 22, 2017
LICENSE init commit Jul 28, 2017
Makefile Fixed darwin build Oct 17, 2017
README.md Modifying markdown to fix lists and some grammatical errors (#121) May 17, 2018
artifacts.go Add ability to upload artifacts to s3 (#122) May 25, 2018
artifacts_test.go Improve mold test (#104) Dec 13, 2017
docker.go Add git hash to service container name (#125) Sep 4, 2018
docker_test.go Add git hash to service container name (#125) Sep 4, 2018
docker_worker.go Add git hash to service container name (#125) Sep 4, 2018
docker_worker_test.go Add git hash to service container name (#125) Sep 4, 2018
docker_worker_unit_test.go Add git hash to service container name (#125) Sep 4, 2018
gitversion.go Fixed version getting wrong tag (#127) Oct 22, 2018
gitversion_test.go Improve mold test (#104) Dec 13, 2017
imageconfig.go Add a clean function to cleanup all build resources created (#89) Nov 3, 2017
imageconfig_test.go Improve mold test (#104) Dec 13, 2017
lifecycle.go Add ability to upload artifacts to s3 (#122) May 25, 2018
lifecycle_test.go Add git hash to service container name (#125) Sep 4, 2018
log.go Use shorter build names in log (#91) Nov 9, 2017
main.go Improve mold test (#104) Dec 13, 2017
main_test.go Improve mold test (#104) Dec 13, 2017
moldconfig.go replace placeholders at s3 artifacts source and target (#124) May 31, 2018
moldconfig_test.go Improve mold test (#104) Dec 13, 2017
runconfig.go env_file to support both yml and ini style (#110) Jan 12, 2018
runconfig_test.go env_file to support both yml and ini style (#110) Jan 12, 2018
s3.go Add ability to upload artifacts to s3 (#122) May 25, 2018
s3config.go replace placeholders at s3 artifacts source and target (#124) May 31, 2018
s3config_test.go Add ability to upload artifacts to s3 (#122) May 25, 2018
state.go rename imgCache to cache Aug 2, 2017
state_test.go Improve mold test (#104) Dec 13, 2017
utils.go Improve mold test (#104) Dec 13, 2017
utils_test.go Improve mold test (#104) Dec 13, 2017
version.go updated version to 2.13 Oct 23, 2018

README.md

mold Build Status

Mold is a tool to help test, build, package and publish your application completely within a containerized environment. It automates the process from installing dependencies and testing to packaging and publishing your image to a registry.

Mold starts by creating an isolated network to run your build, followed by installing your dependencies, running unit tests and building any needed binaries in a container. These binaries are in turn used to package the image and publish to a registry.

Mold also helps manage versioning by leveraging git and using tags as points of reference to automate version computation and appropriately tagging images.

Installation

Download the binary based on your OS. Once uncompressed copy it into your system PATH.

Usage

To use mold you can simply issue the mold command in the root of your git repository. By default the command looks for a .mold.yml configuration file at the root of your project. All available options can be seen by issuing:

mold --help

Windows Usage

On Windows 10, the following needs to be performed in order for mold to function properly

  1. Must specify -uri tcp://127.0.0.1:2375 options.
  2. Set the home environment variable to HOME=C:/Users/{username}
  3. Make sure $HOME/.docker/config.json exists. You can run docker login to create one or simply create any empty file.
  4. Make sure C: is shared: Docker settings > Shared Drives > Select the local drives you want to be available to your containers
  5. Configure Docker by checking Expose daemon on tcp://localhost:2375

It is NOT recommended to run mold on Windows 7 since Docker Engine cannot run natively on it. Just when there is no other options, Docker toolbox could be installed and Docker Engine so as mold can run inside a Linux VM hosted on the Windows 7 system.

(Ref: https://docs.docker.com/toolbox/toolbox_install_windows/)

  1. Check the OS version - "Run a tool like the Microsoft® Hardware-Assisted Virtualization Detection Tool or Speccy, and follow the on-screen instructions."
  2. Install Remote Server Administration Tools (RSAT) (of Windows)
  3. Install Hyper-V tools (of Windows)
  4. Install Docker toolbox
  5. Disable TLS in Docker profile
    • Start "Docker Quickstart Terminal
    • Start ssh: docker-machine ssh
    • Edit /var/lib/boot2docker/profile so DOCKER_HOST='-H tcp://{ip}:2375' and DOCKER_TLS=no
    • Exit ssh: exit
    • Restart Docker machine: docker-machine restart
  6. Mount mold released for Linux to the VM
  7. Mount project files to the VM
  8. Start docker-machine ssh and run mold and Docker in it

Configuration

The mold process is controlled by a single configuration file which by default is .mold.yml. For detailed information on configuration options please visit the configuration page.

Cleanup

As you perform builds, there will be a build of containers and images left behind that may no longer be needed. You can pick and choose which ones to keep. A helper script has been provided which removes all containers that have exited, intermediate images as well as dangling volumes.

DO NOT USE this script if any of the exited containers, images or volumes are of any value that you would like to save.

The script can be found in scripts/drclean. Please read the comments if you would like to know what it exactly does.

FAQ

1. Why not use Docker Compose to test, build, package, and publish our applications?

Docker Compose is a tool to define and run multi-container applications, optionally assembling needed images before running the application stack. Mold is used manage your CI pipeline in Docker i.e test, build, package and publish.

One still may wonder if mold is really needed and if the same could be acheived via docker-compose. Based on our tests, it does seem viable to use docker-compose as a CI solution.

Docker compose controls the order of service startup but does not provide way to manage the order of image builds. Below shows the docker-compose file and the Dockerfile we used to mimic the build process and test if the dependency conditions would delay the image build from the Dockerfile until the application is built.

docker-compose.yml

version: '2.1'
services:
  build_img:
    build: .
    depends_on:
      build_app:
        condition: service_healthy
  build_app:
    image: alpine
    volumes:
      - ./:/app/
    command: /bin/sh -ec "sleep 5s; head -c 10 /dev/urandom > /app/myApp"
    healthcheck:
        test: ["CMD", "/bin/sh", "-f", "/app/fileExist.sh", "/app/myApp"]
        interval: 30s
        timeout: 10s
        retries: 5

Dockerfile

FROM alpine
ADD . /app
CMD ["/bin/sh", "-f", "/app/fileExist.sh", "/app/myApp"]

The result below shows the dependency condition only affects the order of the service startup and not that of an image build:

Building build_img
...
Successfully built 2946ba878f8c
...
Creating composetest_build_app_1
Creating composetest_build_img_1
...
build_img_1  | /app/myApp does NOT exist
composetest_build_app_1 exited with code 0
composetest_build_img_1 exited with code 1

Another aspect that mold handles is separating the build images from the deployment images i.e builds happen in 1 container and the resulting artifacts are then used to build the final image which will be published to a registry.

2. What are the system requirements to run mold?

Mold is released for Linux, Mac, and Windows. It however requires Docker installed on the system. This also means for Windows system, it requires 64bit Windows 10 Pro, Enterprise and Education (1511 November update, Build 10586 or later) and Microsoft Hyper-V. Please see the details from the Docker site.

3. Where should I run mold? Should it be triggered on the CI server or should I run it locally?

You can run mold locally or be incorporate it into your CI pipeline and run on you CI server.

Roadmap

  • 0.2.6
    • Build image optimization and caching.
  • 0.2.5
    • First official open-source release.

Known Issues

Output Delay

This issue appears due to Docker API limits. At times the command runs and completes execution before the output and status can even be obtained. This is particularly the case when a command is not found or a single command execution completes quickly enough. i.e. before the call to get the status and output is made.

To avoid this a sleep statement can be added as the first command in the build process. Example:

commands:
- sleep 1
- mvn test

In the case where mvn exists the sleep is not required.