Skip to content

Commit 0add665

Browse files
committed
chore: add readme
Signed-off-by: Vasek - Tom C <tom@quartz.technology>
1 parent 9d0fc64 commit 0add665

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

docker_sdk/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Docker SDK
2+
3+
A magic SDK that automatically provides a custom function to build your project's Dockerfile.
4+
5+
Any argument, secret, or stages defined in your Dockerfile will be automatically exposed as parameter to your function.
6+
7+
## Usage
8+
9+
:warning: This is experimental, please open an issue if you encounter any issue.
10+
11+
```shell
12+
# Go to your project root (or any directory that contains a Dockerfile)
13+
14+
# Init Dagger module with the Docker SDK
15+
# The SDK will look in the `source` directory for a Dockerfile, so keep it to `.`
16+
dagger init --sdk github.com/quartz-technology/daggerverse/docker_sdk --name=test --source=.
17+
18+
# Build a container of project's application using your dockerfile and start a terminal inside it
19+
dagger call docker build terminal
20+
```
21+
22+
## Functions
23+
24+
### Build
25+
26+
Build a container of your project's application using your dockerfile and return it.
27+
28+
**Supported arguments**
29+
- `platform`: The platform to build the container for (default to your host platform).
30+
- `dockerfile`: The path to the Dockerfile to use (default to `Dockerfile` or the first Dockerfile found in the project).
31+
- `target`: The target stage to build (optional and will build the last stage by default).
32+
- `buildArgs`: A list of build arguments to pass to the build (optional).
33+
- `secrets`: A list of secrets to pass to the build (optional).
34+
35+
## Example
36+
37+
```Dockerfile
38+
ARG BASE_IMAGE=golang:1.23.2-alpine
39+
40+
FROM ${BASE_IMAGE} AS app
41+
42+
WORKDIR /app
43+
44+
COPY . .
45+
46+
RUN go mod download
47+
48+
RUN go build -o /app/main .
49+
50+
FROM golang:1.23.2-alpine AS runtime
51+
52+
ARG BIN_NAME
53+
54+
WORKDIR /runtime
55+
56+
COPY --from=app /app/main /runtime/${BIN_NAME}
57+
58+
RUN --mount=type=secret,id=my-super-secret \
59+
cat /run/secrets/my-super-secret > /runtime/secret.txt
60+
61+
ENTRYPOINT ["/runtime/${BIN_NAME}"]
62+
```
63+
64+
If you display the helper of the `build` function, you see that build arguments and secrets declared
65+
in the dockerfile are automatically exposed as arguments to the function (with default value if it exists).
66+
For stages, it's exposed as an enumeration to enforce validation.
67+
68+
```shell
69+
dagger call docker build --help
70+
71+
ARGUMENTS
72+
--bin-name string Set BIN_NAME build argument [required]
73+
--my-super-secret Secret Set my-super-secret secret [required]
74+
--base-image string Set BASE_IMAGE build argument (default "golang:1.23.2-alpine")
75+
--dockerfile string Path to the Dockerfile to use. (default "Dockerfile")
76+
--platform Platform Platform to build. (default linux/arm64)
77+
--target app,runtime Target stage to build.
78+
```
79+
80+
Example of command:
81+
82+
```shell
83+
dagger call docker build --bin-name foooo --my-super-secret env:PATH terminal
84+
85+
$ ls
86+
foooo secret.txt
87+
```

0 commit comments

Comments
 (0)