https://github.com/r2d4/dacc
docker-as-code compiler
https://github.com/r2d4/dacc
docker infrastructure-as-code
Last synced: about 1 month ago
JSON representation
docker-as-code compiler
- Host: GitHub
- URL: https://github.com/r2d4/dacc
- Owner: r2d4
- Created: 2024-09-06T16:54:58.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T21:44:28.000Z (7 months ago)
- Last Synced: 2025-03-24T20:22:00.177Z (2 months ago)
- Topics: docker, infrastructure-as-code
- Language: TypeScript
- Homepage:
- Size: 432 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dacc: docker-as-code compiler
#### _Cache-efficient, sandboxed, builds as code._
* Native support with any Docker installation, no extra tools needed
* Infrastructure-as-code for docker images
* Cache-efficient: Represent any build graph in dacc
* Extend: [__merge__](examples/merge.ts), [__diff__](examples/diff.ts), and [__nested builds__](examples/nested-builds.ts) operations
*A very parallel build [(src)](./packages/dacc/src/build/df.ts) generated with dacc*### Installation
__dacc__ requires [Docker](https://www.docker.com).
```
npm install dacc
```
### Getting Started - Hello World
Create a new project with the `create-dacc`, which will create a new TypeScript project and install dacc in the directory provided.
```
npx create-dacc hello-dacc
```
Enter the newly created directory and run the build
```
cd hello-dacc && npm start
```## Examples
- [Merging / Parallelism](#merging--parallelism)
- [Diff Layers](./examples/src/diff.ts)
- [Generating protobuf definitions for this repository](./packages/dacc/src/build/df.ts)
- [Building the Buildkit Frontend Image](https://github.com/r2d4/llb/blob/main/build/src/main.ts)
- [Multi-platform](./examples/src/multi-platform.ts)
- [Nested builds](./examples/src/nested-builds.ts)
- [Directory of additional examples](./examples)### Merging / Parallelism
Docker images often have to install packages via a package manager. This might be specified in a single command `RUN apk add git curl wget`. But when a new package is added, the entire cache is invalidated.Instead, with dacc, you can install them in parallel and then merge the resulting filesystems. Adding or removing packages from the list won't invalidate the cache for the other packages.
```typescript main.ts
import { cacheMount, State } from 'dacc'async function main() {
const s = (await new State().from("alpine"))const bins = ["git", "curl", "wget"]
s.merge(
s.parallel(
...bins.map(bin => (s: State) =>
s.run(`apk add ${bin}`).with(cacheMount("/var/cache/apk")))
),
)s.image.run({
run: { command: "ls", args: bins.map(bin => `/usr/bin/${bin}`) },
})
}void main()
```