{"id":15020944,"url":"https://github.com/lexsca/prefab","last_synced_at":"2025-10-26T19:30:28.726Z","repository":{"id":46260561,"uuid":"291603498","full_name":"lexsca/prefab","owner":"lexsca","description":"Build container images faster ⚡️","archived":false,"fork":false,"pushed_at":"2022-11-09T03:09:46.000Z","size":133,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-28T16:02:52.143Z","etag":null,"topics":["build-automation","build-tool","ci","container","container-image","continuous-integration","docker","docker-image","python","python3"],"latest_commit_sha":null,"homepage":"https://prefab.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lexsca.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-31T03:20:14.000Z","updated_at":"2023-07-10T11:15:19.000Z","dependencies_parsed_at":"2023-01-21T17:45:22.169Z","dependency_job_id":null,"html_url":"https://github.com/lexsca/prefab","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexsca%2Fprefab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexsca%2Fprefab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexsca%2Fprefab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexsca%2Fprefab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lexsca","download_url":"https://codeload.github.com/lexsca/prefab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219862313,"owners_count":16555957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-automation","build-tool","ci","container","container-image","continuous-integration","docker","docker-image","python","python3"],"created_at":"2024-09-24T19:55:55.202Z","updated_at":"2025-10-26T19:30:23.387Z","avatar_url":"https://github.com/lexsca.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"######\nPrefab\n######\n\n**Build container images faster** ⚡️\n\n.. image:: https://imgs.xkcd.com/comics/compiling.png\n    :target: https://xkcd.com/license.html\n    :alt: https://xkcd.com/303/\n\n|\n\n.. image:: https://github.com/lexsca/prefab/actions/workflows/checks.yml/badge.svg\n    :target: https://github.com/lexsca/prefab/actions/workflows/checks.yml\n\n.. image:: https://img.shields.io/docker/image-size/lexsca/prefab/dood\n   :target: https://hub.docker.com/r/lexsca/prefab/tags\n\n.. image:: https://img.shields.io/pypi/v/container-prefab.svg\n    :target: https://pypi.org/project/container-prefab/\n\n.. image:: https://img.shields.io/pypi/pyversions/container-prefab.svg\n    :target: https://pypi.org/project/container-prefab/\n\n.. image:: https://img.shields.io/github/license/lexsca/prefab.svg\n    :target: https://github.com/lexsca/prefab/blob/master/LICENSE\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n|\n\n*Prefab* is a Python-based container image build tool that uses deterministic remote caching to reduce build times.  Unlike `BuildKit \u003chttps://github.com/moby/buildkit#cache\u003e`_ and the `Docker CLI \u003chttps://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources\u003e`_, which use build layer caching, *Prefab* uses whole image caching based on a digest of the Dockerfile in combination with digests of specified files and directory trees.  This allows *Prefab* to check for and pull cached images before resorting to building a new image.\n\n\nQuickstart\n==========\n\nLook at the `example directory \u003chttps://github.com/lexsca/prefab/tree/main/example\u003e`_ to see how to build an example app with *Prefab*.\n\n\nInstallation and usage\n======================\n\n*Prefab* can be installed and run in three different ways:\n\n#. Local Python package\n#. Docker outside of Docker (DooD) container\n#. Docker in Docker (DinD) container\n\nUse whichever mode works best for the use-case(s) at hand.  Each supports the same CLI arguments:\n\nCLI arguments\n-------------\n\n::\n\n    usage: prefab [-h] [--config PATH] [--dry-run] [--force] [--monochrome]\n                  [--push TARGET_NAME [TARGET_NAME ...]] [--push-all] --repo URI\n                  --target TARGET_NAME[:TAG] [TARGET_NAME[:TAG] ...]\n\n    Build container images faster ⚡️\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      --config PATH, -c PATH\n                            Target build config file to use (default: prefab.yml)\n      --dry-run             Show how targets would be built (implies --force)\n      --force               Force target(s) to be rebuilt\n      --monochrome, -m      Don't colorize log messages\n      --push TARGET_NAME [TARGET_NAME ...], -p TARGET_NAME [TARGET_NAME ...]\n                            Image target(s) to push to repo after building\n      --push-all            Push all image targets to repo after building\n      --repo URI, -r URI    Image repo to use (e.g. lexsca/prefab)\n      --target TARGET_NAME[:TAG] [TARGET_NAME[:TAG] ...], -t TARGET_NAME[:TAG] [TARGET_NAME[:TAG] ...]\n                            Image target(s) to build with optional custom image tag\n\n\nLocal Python package\n--------------------\n\nTo install *Prefab* as a local Python package::\n\n    pip install container-prefab\n\nTo run *Prefab* as a local Python package to build an push a build target::\n\n    prefab --repo repo.tld/org/project --push --target name\n\nNOTE: Container images now hosted on Docker Hub\n-----------------------------------------------\n\nThe container images below used to be hosted by Quay and are now\nhosted by `Docker Hub \u003chttps://hub.docker.com/r/lexsca/prefab\u003e`_\nThis decision was not taken lightly. Sadly, Quay has not proven to\nbe a reliable service. The final straw was when RedHat acquired\nthem and broke authentication.\n\nDocker outside of Docker (DooD)\n-------------------------------\n\nTo get the *Prefab* Docker outside of Docker (DooD) image::\n\n    docker pull lexsca/prefab:dood\n\nTo run the *Prefab* Docker outside of Docker image to build an push a build target::\n\n    docker run --rm -it -v $(/bin/pwd):/build -w /build \\\n        -e REGISTRY_AUTH=$(jq -c . ~/.docker/config.json | base64) \\\n        -v /var/run/docker.sock:/docker.sock \\\n        lexsca/prefab:dood --repo repo.tld/org/project \\\n        --push-all --target name\n\nDocker in Docker (DinD)\n-----------------------\n\nTo get the *Prefab* Docker in Docker (DinD) image::\n\n    docker pull lexsca/prefab:dind\n\nTo run the *Prefab* Docker in Docker image to build an push a build target::\n\n    docker run --rm -it -v $(/bin/pwd):/build -w /build --privileged \\\n        -e REGISTRY_AUTH=$(jq -c . ~/.docker/config.json | base64) \\\n        lexsca/prefab:dind --repo repo.tld/org/project \\\n        --push-all --target name\n\nConfiguration\n=============\n\n*Prefab* uses a `YAML \u003chttps://en.wikipedia.org/wiki/YAML\u003e`_ configuration file to determine which container images to build for a given target and in which order.  This configuration below is taken from the `example directory \u003chttps://github.com/lexsca/prefab/tree/main/example\u003e`_ in this repo.\n\nThis example ``prefab.yml`` file has two build targets, each with a Dockerfile. The ``app`` target has a dependency on the ``packages`` target, so it's built or pulled first, before building the ``app`` target.  This is a simple example, but the dependency graph can be arbitrarily deep or wide for complex build targets.\n\n``prefab.yml``\n--------------\n\n::\n\n    targets:\n\n      app:\n        dockerfile: Dockerfile.app\n        depends_on:\n          - packages\n        watch_files:\n          - app.py\n\n      packages:\n        dockerfile: Dockerfile.packages\n\nWhen building a container image, *Prefab* populates `build arguments \u003chttps://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg\u003e`_ for each build target depndency, uppercased by convention, and prefixed with ``PREFAB_`` to avoid conflicts with other build arguments.\n\n\n``Dockerfile.app``\n------------------\n\n::\n\n    ARG PREFAB_PACKAGES\n\n    FROM $PREFAB_PACKAGES as packages\n\nContributing\n============\n\nBug reports are welcome.  Pull requests even more so.\n\nBefore making any changes, first ensure the development environment is functional and the extant linting and tests are passing.  To start a development environment, clone or fork this source repo and follow the instructions below.\n\nAlternatively, it's fine to create a virtual environment an install packages from ``requirements.txt`` and ``requirements-dev.txt`` files. The Python version should be 3.7 or later.\n\nPrerequisites\n-------------\n\n#. POSIX Shell (e.g. bash)\n#. Docker\n#. GNU Make\n\nCreate environment\n------------------\n\nTo create a development runtime environment::\n\n    $ make bootstrap\n\nThe above will create a minimal environment that will allow *Prefab* to build its development environment image.  This image can be used to run linting and tests::\n\n    $ docker images lexsca/prefab:dev\n    REPOSITORY      TAG                 IMAGE ID            CREATED              SIZE\n    lexsca/prefab   dev                 ddee1cafb775        About a minute ago   429MB\n\nUse environment\n---------------\n\nOnce created, the development image can used via::\n\n    $ make shell\n    docker run --rm -it -v /Users/lexsca/git/prefab:/prefab -w /prefab \\\n            -v /var/run/docker.sock:/docker.sock -e PYTHONPATH=/prefab/lib \\\n            --entrypoint /bin/bash lexsca/prefab:dev --login -o vi\n    3053ae861610:/prefab# make test\n\nThis will mount the docker socket and current working directory in an environment where tests can be run, dependencies built, or a debugger invoked to aid in iterating.\n\nThe ``make test`` command should pass before attempting to submit any code changes.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexsca%2Fprefab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flexsca%2Fprefab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexsca%2Fprefab/lists"}