Skip to content

Commit

Permalink
Feat: Allow users to bring their own Dockerfile (#773)
Browse files Browse the repository at this point in the history
Resolve BE-2084

This feature adds a new operator to the `Image` abstraction that allows
users to specify a path to a Dockerfile that they wish to use as the
base of their Image. We use `buildah` and `umoci` to build their
Dockerfile and gather the bundle needed to run it.

It can be used as follows: 
```python
from beta9 import Image, endpoint

image = Image().from_dockerfile("./Dockerfile").add_python_packages(["numpy"])


@endpoint(image=image, name="test_dockerfile")
def handler():
    return "pass"
```
Where `./Dockerfile` is: 
```
FROM ubuntu:22.04
RUN echo hello
ENV FOO=bar
```

Note: when testing locally, you might need to build gateway again to get
`make start` to work because the go version is bumped.
  • Loading branch information
dleviminzi authored Dec 16, 2024
1 parent 3dda0e3 commit 44e21d8
Show file tree
Hide file tree
Showing 19 changed files with 784 additions and 421 deletions.
4 changes: 2 additions & 2 deletions docker/Dockerfile.gateway
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-bullseye AS base
FROM golang:1.23.4-bullseye AS base

RUN apt-get update && \
apt-get install -y --no-install-recommends fuse3
Expand All @@ -25,7 +25,7 @@ FROM base AS build

WORKDIR /workspace

RUN apt-get install -y libfuse3-dev && \
RUN apt-get install -y libfuse3-dev libbtrfs-dev libgpgme-dev && \
go install github.com/cosmtrek/[email protected]

COPY go.mod go.sum ./
Expand Down
36 changes: 34 additions & 2 deletions docker/Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1.7-labs
ARG BASE_STAGE=dev

FROM golang:1.22-bullseye AS golang
FROM golang:1.23.4-bookworm AS golang

RUN apt-get update && apt-get install -y curl git

Expand Down Expand Up @@ -58,6 +58,28 @@ make binaries
EOT


# buildah build stage
FROM golang AS buildah

WORKDIR /workspace
RUN apt-get update && apt-get install -y \
make \
btrfs-progs \
git \
go-md2man \
iptables \
libapparmor-dev \
libglib2.0-dev \
libgpgme11-dev \
libseccomp-dev \
libselinux1-dev \
libbtrfs-dev \
pkg-config

RUN git clone https://github.com/containers/buildah.git . && \
make BUILDTAGS="cni" && \
make install

# beta9 worker
# ========================
FROM golang AS worker
Expand Down Expand Up @@ -93,6 +115,11 @@ RUN apt-get install -y --no-install-recommends nvidia-container-toolkit-base nvi

RUN apt-get update && apt-get install -y fuse3 libfuse2 libfuse3-dev libfuse-dev bash-completion

RUN apt-get install -y libbtrfs-dev libgpgme11-dev
RUN mkdir -p /etc/containers/registries.conf.d
RUN curl -L https://raw.githubusercontent.com/containers/shortnames/refs/heads/main/shortnames.conf \
-o /etc/containers/registries.conf.d/shortnames.conf

# XXX: Remove once cedana starts shipping with a compatible binary
RUN <<EOT
set -eux
Expand Down Expand Up @@ -125,7 +152,6 @@ RUN if [ -n "${CEDANA_TOKEN}" ]; then \
chmod +x /usr/local/lib/libcedana-gpu.so; \
fi


ARG TARGETARCH

ENV MOUNT_S3_URL_ARM64="https://s3.amazonaws.com/mountpoint-s3-release/1.8.0/arm64/mount-s3-1.8.0-arm64.tar.gz"
Expand All @@ -149,6 +175,8 @@ RUN apt-get remove -y curl && \
apt-get clean && apt-get autoremove -y && apt-get autopurge -y && \
rm -rf /var/lib/apt/lists/* /var/log/*


ENV BUILDAH_RUNTIME=/usr/local/sbin/runc
RUN echo "nameserver 8.8.8.8" > /workspace/resolv.conf
COPY --from=runc /usr/local/sbin/runc /usr/local/sbin/runc
COPY --from=skopeo /usr/local/bin/skopeo /usr/local/bin/skopeo
Expand All @@ -157,6 +185,10 @@ COPY --from=nvidia-container-toolkit /workspace/nvidia-container-runtime* /usr/b
COPY ./bin/volume_cache.so /usr/local/lib/volume_cache.so
COPY --from=worker /usr/local/bin/worker /usr/local/bin/worker
COPY ./sdk/src/beta9 /workspace/sdk
COPY --from=buildah /usr/local/bin/buildah /usr/local/bin/buildah

VOLUME "/usr/lib/x86_64-linux-gnu"
VOLUME "/usr/lib/aarch64-linux-gnu"

ENV _BUILDAH_STARTED_IN_USERNS="" \
BUILDAH_ISOLATION=chroot
89 changes: 45 additions & 44 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module github.com/beam-cloud/beta9

go 1.22.0
go 1.23.1

toolchain go1.22.4
toolchain go1.23.4

require (
buf.build/gen/go/cedana/task/grpc/go v1.5.1-20241203191352-12c25eb032cd.1
buf.build/gen/go/cedana/task/protocolbuffers/go v1.35.2-20241203191352-12c25eb032cd.1
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/Masterminds/squirrel v1.5.4
github.com/alicebob/miniredis/v2 v2.30.5
github.com/aws/aws-sdk-go-v2 v1.30.1
github.com/aws/aws-sdk-go-v2/config v1.27.24
github.com/aws/aws-sdk-go-v2/credentials v1.17.24
github.com/aws/aws-sdk-go-v2 v1.30.3
github.com/aws/aws-sdk-go-v2/config v1.27.27
github.com/aws/aws-sdk-go-v2/credentials v1.17.27
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.9
github.com/aws/aws-sdk-go-v2/service/ec2 v1.144.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.24.4
github.com/aws/aws-sdk-go-v2/service/s3 v1.51.4
github.com/aws/aws-sdk-go-v2/service/s3 v1.55.1
github.com/beam-cloud/blobcache-v2 v0.0.0-20241206144620-d0ca8ede5095
github.com/beam-cloud/clip v0.0.0-20240826223025-899feb184e88
github.com/beam-cloud/go-runc v0.0.0-20231222221338-b89899f33170
Expand Down Expand Up @@ -44,14 +44,14 @@ require (
github.com/mholt/archiver/v3 v3.5.1
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/mitchellh/mapstructure v1.5.0
github.com/opencontainers/runc v1.1.14
github.com/opencontainers/runc v1.2.1
github.com/opencontainers/runtime-spec v1.2.0
github.com/opencontainers/umoci v0.4.7
github.com/openmeterio/openmeter v1.0.0-beta.47
github.com/oracle/oci-go-sdk v24.3.0+incompatible
github.com/pkg/errors v0.9.1
github.com/pressly/goose/v3 v3.21.1
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_golang v1.20.2
github.com/prometheus/procfs v0.15.1
github.com/redis/go-redis/v9 v9.5.1
github.com/rs/zerolog v1.33.0
Expand All @@ -60,7 +60,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/tj/assert v0.0.3
github.com/vishvananda/netlink v1.2.1-beta.2
github.com/vishvananda/netlink v1.3.0
github.com/vishvananda/netns v0.0.4
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0
Expand All @@ -72,10 +72,10 @@ require (
go.opentelemetry.io/otel/sdk/log v0.7.0
go.opentelemetry.io/otel/sdk/metric v1.31.0
go.opentelemetry.io/otel/trace v1.31.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/net v0.30.0
golang.org/x/sync v0.8.0
golang.org/x/sys v0.26.0
golang.org/x/sync v0.9.0
golang.org/x/sys v0.27.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.2
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -84,7 +84,7 @@ require (
k8s.io/apimachinery v0.30.3
k8s.io/client-go v0.30.3
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
tailscale.com v1.72.1
tailscale.com v1.76.6
)

require (
Expand All @@ -97,45 +97,44 @@ require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/apex/log v1.4.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.45.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.22.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.22.4 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/beam-cloud/ristretto v0.0.0-20241013204426-d1403e359aa2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cilium/ebpf v0.16.0 // indirect
github.com/coder/websocket v1.8.12 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/cyphar/filepath-securejoin v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/dgraph-io/ristretto v1.0.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e // indirect
github.com/djherbis/atime v1.1.0 // indirect
github.com/docker/docker v27.2.0+incompatible // indirect
github.com/docker/docker v27.3.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
github.com/gaissmai/bart v0.11.1 // indirect
github.com/getkin/kin-openapi v0.127.0 // indirect
Expand All @@ -147,9 +146,9 @@ require (
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-test/deep v1.1.0 // indirect
github.com/go-test/deep v1.1.1 // indirect
github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -164,7 +163,7 @@ require (
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/illarion/gonotify v1.0.1 // indirect
github.com/illarion/gonotify/v2 v2.0.3 // indirect
github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/jellydator/ttlcache/v3 v3.2.0 // indirect
Expand All @@ -174,7 +173,7 @@ require (
github.com/jsimonetti/rtnetlink v1.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
Expand All @@ -185,6 +184,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/sdnotify v1.0.0 // indirect
Expand All @@ -203,17 +203,18 @@ require (
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/okteto/okteto v0.0.0-20231222160652-094ca6b3fca8 // indirect
github.com/onsi/ginkgo/v2 v2.20.0 // indirect
github.com/onsi/gomega v1.34.1 // indirect
github.com/onsi/ginkgo/v2 v2.21.0 // indirect
github.com/onsi/gomega v1.35.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/sftp v1.13.7 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/prometheus-community/pro-bing v0.4.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/common v0.57.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rootless-containers/proto v0.1.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand All @@ -226,18 +227,18 @@ require (
github.com/tailscale/golang-x-crypto v0.0.0-20240604161659-3fde5e568aa4 // indirect
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 // indirect
github.com/tailscale/netlink v1.1.1-0.20240822203006-4d49adab4de7 // indirect
github.com/tailscale/peercred v0.0.0-20240214030740-b535050b2aa4 // indirect
github.com/tailscale/web-client-prebuilt v0.0.0-20240226180453-5db17b287bf1 // indirect
github.com/tailscale/wireguard-go v0.0.0-20240731203015-71393c576b98 // indirect
github.com/tailscale/wireguard-go v0.0.0-20240905161824-799c1978fafc // indirect
github.com/tchap/go-patricia v2.3.0+incompatible // indirect
github.com/tcnksm/go-httpstat v0.2.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/u-root/uio v0.0.0-20240118234441-a3c409a6018e // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/urfave/cli v1.22.14 // indirect
github.com/urfave/cli v1.22.16 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vbatts/go-mtree v0.5.0 // indirect
Expand All @@ -251,13 +252,13 @@ require (
go.uber.org/zap v1.27.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
Expand Down
Loading

0 comments on commit 44e21d8

Please sign in to comment.