Dockly: Building Ready-to-Launch Docker Images
We needed a way to take a git repo and make it ready to launch. We wanted to take the repo, add it to a Docker image, build assets, generate startup scripts, and package it in a Debian package for easy deployment - all in under 20 lines of code.
So we built Dockly to provide a simple syntax to define exactly how our deployment packages are built.
From repo to container
Describe putting your app into a Docker container with:
docker :my_image do
import 's3://.../base-image.tar.gz'
git_archive '/app'
build <<-EOF
run cd /app && ./configure && make
EOF
end
- The
import
command specifies the base image. - The
git_archive
command puts the git archive of your app into the/app
path, or wherever you want to put it. - The
build
command allows you to run commands from the context of the Docker container. Anything that is valid in a Dockerfile can go here.
Adding init scripts
Generate your init scripts to control the Docker processes using foreman:
foreman :my_app do
log_dir '/data/logs'
user 'appuser'
end
You can customize the init scripts with all the same options as foreman export.
Pulling it all together
Pull the docker and foreman definitions into a Debian package:
deb :my_package do
package_name 'my_app'
docker :my_image
foreman :my_app
end
Or, if you prefer nesting, you can inline your definitions. All together this looks like:
deb :my_package do
package_name 'my_app'
docker do
name 'my_image'
import 's3://.../base-image.tar.gz'
git_archive '/app'
build <<-EOF
run cd /app && ./configure && make
EOF
end
foreman do
name 'my_app'
log_dir '/data/logs'
user 'appuser'
end
end
Your Turn!
There's a lot more Dockly can do to package your applications. Features include build caching, mixing in files and directories and including pre/post install/uninstall scripts. When built, we push the final image to S3.
We're packaging more than just Rails applications: we use Dockly to nicely wrap up Node projects and other services.
Dockly is open source. Try it out!