Introduction
Typebuild makes it possible to create container images using typescript.
Instead of this
#syntax=docker/dockerfile:1.4
FROM golang:1.18.0-alpine3.15 as builder
RUN apk add git
WORKDIR /app
RUN --mount=target=. go build -o /binary
FROM scratch as final
COPY --from=builder --link /binary /app
ENTRYPOINT /app
You can do this
//syntax=rumpl/typebuild
import { BindMount, Image, Scratch } from "https://raw.githubusercontent.com/rumpl/typebuild-node/main/index.ts";
const golangImage = "golang:1.18.0-alpine3.15";
const binary = "/binary";
const entrypoint = "/app";
const mounts = [new BindMount({ target: "." })];
const builder = new Image(golangImage)
.run("apk add git")
.workdir("/app")
.run(`go build -o ${binary}`, mounts);
export default new Scratch()
.copy({
from: builder,
source: binary,
destination: entrypoint,
})
.entrypoint([entrypoint]);
And of course, since this is TypeScript, you can refactor your build file and it could look something like this
import { Golang } from "https://my-registry.org/my-awesome-builder-lib/golang.ts";
export default new Golang().build();