Skip to main content

Sand 🏝

.github/workflows/ci.yml

Sand is a Dockerfile generator.

It allows you to write cleaner, shorter and more configurable Dockerfiles.

Developers ❤️ Sand

Sand is built by developers, for developers. It's built to be as simple as possible, while still being super useful.

Installation

You can install Sand using pip.

pip3 install docker-sand

Features

✅ Simple, easy to learn syntax based on Python.

✅ Configurable Dockerfiles.

✅ Share code between Dockerfiles.

✅ Perfect for monorepos composed of multiple microservices.

✅ Supports multi-stage builds.

Planned Features:

🔘 Optimize builds by finding common layers between Dockerfiles, and merging them into a base image.

🔘 Minimizing the number of layers by combining multiple RUN commands into one.

Example

Write your Dockerfile in a Python-like syntax.

# Sandfile
from sand import *

From("ubuntu", Tag="20.04")
Run([
    "apt-get update",
    "apt-get install ffmpeg python3"
])

# Install python debugger on debug images.
if config.DEBUG:
    Run("pip3 install pdb")

Copy("app", "/app")
Entrypoint("python3 /app/app.py")

⬇️

# Auto-generated by Sand, do not edit!
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install ffmpeg python3
COPY app /app
ENTRYPOINT python3 /app/app.py

Share Code

Because Sandfiles are just Python files, and are being evaluated in an hierarchical manner by using the Sand directive, you can easily share code between them.

Given the following directory structure:

my-monorepo/
│
├── tweet-service/
|   ├── src/
|   ├── ...
│   └── Sandfile
│
├── home-timeline/
|   ├── src/
|   ├── ...
│   └── Sandfile
│
└── Sandfile

You can write your Sandfiles like this:

# ./my-monorepo/Sandfile
from sand import *

def MyService(name):
    From("ubuntu", "20.04")
    Run("apt-get install python3")
    Copy(Src="src", Dst="/app")
    Entrypoint(f"python3 /app/{name}.py")

Sand("tweet-service")
Sand("home-timeline")
# ./my-monorepo/tweet-service/Sandfile
from sand import *

MyService("tweet-service") # Defined in ../Sandfile
# ./my-monorepo/home-timeline/Sandfile
from sand import *

MyService("home-timeline") # Defined in ../Sandfile

This allows you to share code between your Dockerfiles, and keep them DRY.

This is similar to the way add_subdirectory works in CMake

Usage

Running Sand is as simple as running sand in your terminal. This will generate Dockerfiles for all Sandfiles in the current directory.

$ sand config
Saving Dockerfile to backend/service1/Dockerfile
Saving Dockerfile to backend/service2/Dockerfile
Built successfully!

You can also watch for changes and automatically rebuild your Dockerfiles.

$ sand config -w
Watching for changes...

Configuration

You can pass configuration values to Sand using the -D or --set flag.

$ sand config -DDEBUG=True

Or use a YAML file.

# sand.yaml
DEBUG: True
$ sand config --values sand.yaml

Metadata

Release files for docker-sand 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docker-sand 0.0.9
File Size Uploaded
docker-sand-0.0.9.tar.gz 8.3 kB Details

Release files / docker-sand-0.0.9.tar.gz

Download URL docker-sand-0.0.9.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
53f1b1f2c59ae70a14225aa519badd7cb22b7d6cbb9b041957466bfac43b78a5
BLAKE2b-256 checksum
How to use checksums
a4cf0da03cc317f820562a3ee2a19512ecda614d6689c4ea8b721bbd03beb945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.0.9 This release

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page