Code Monkey home page Code Monkey logo

sand's Introduction

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, so 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

sand's People

Contributors

gkpln3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sand's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.