Skip to content

Commit

Permalink
Delta Lake: Update Dockerfile base images to Alpine (#5546)
Browse files Browse the repository at this point in the history
* change the Dockerfile back to Alpine and build the Delta plugin dynamically

* remove alpine-sdk from dockerfile

* add alpine-sdk

* add comment about the 'RUSTFLAGS=-Ctarget-feature=-crt-static' flag

* change back from bullseye to alpine
  • Loading branch information
Jonathan-Rosenberg authored Mar 22, 2023
1 parent 02df923 commit 2f67bd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
50 changes: 27 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM --platform=$BUILDPLATFORM golang:1.19.2-bullseye AS build
FROM --platform=$BUILDPLATFORM golang:1.19.2-alpine3.16 AS build

ARG VERSION=dev

WORKDIR /build

# Packages required to build
RUN apt-get update
RUN apt-get install -o APT::Keep-Downloaded-Packages=false -y build-essential
RUN apk add --no-cache build-base

# Copy project deps first since they don't change often
COPY go.mod go.sum ./
Expand All @@ -27,7 +26,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
go build -ldflags "-X github.com/treeverse/lakefs/pkg/version.Version=${VERSION}" -o lakectl ./cmd/lakectl

# Build delta diff binary
FROM --platform=$BUILDPLATFORM rust:1.68-bullseye AS build-delta-diff-plugin
FROM --platform=$BUILDPLATFORM rust:1.68-alpine3.16 AS build-delta-diff-plugin
RUN apk update && apk add build-base pkgconfig openssl-dev alpine-sdk
RUN cargo new --bin delta-diff
WORKDIR /delta-diff

Expand All @@ -36,34 +36,37 @@ COPY ./pkg/plugins/diff/delta_diff_server/Cargo.lock ./Cargo.lock
COPY ./pkg/plugins/diff/delta_diff_server/Cargo.toml ./Cargo.toml

# 3. Build only the dependencies to cache them in this layer
RUN cargo build --release

# Rust default behavior is to build a static binary (default target is <arch>-unknown-linux-musl on Alpine, and musl
# is assumed to be static). It links to openssl statically, but these are dynamic libraries. Setting RUSTFLAGS=-Ctarget-feature=-crt-static
# forces Rust to create a dynamic binary, despite asking for musl.
RUN RUSTFLAGS=-Ctarget-feature=-crt-static cargo build --release
RUN rm src/*.rs

# 4. Now that the dependency is built, copy your source code
COPY ./pkg/plugins/diff/delta_diff_server/src ./src

# 5. Build for release.
RUN rm ./target/release/deps/delta_diff*
RUN cargo build --release
RUN RUSTFLAGS=-Ctarget-feature=-crt-static cargo build --release

# lakectl image
FROM --platform=$BUILDPLATFORM debian:11.6-slim AS lakectl
RUN apt-get update
RUN apt-get install -o APT::Keep-Downloaded-Packages=false -y ca-certificates
FROM --platform=$BUILDPLATFORM alpine:3.16.0 AS lakectl
RUN apk add -U --no-cache ca-certificates
WORKDIR /app
ENV PATH /app:$PATH
COPY --from=build /build/lakectl ./
RUN addgroup --system lakefs && adduser --system lakefs --ingroup lakefs
RUN addgroup -S lakefs && adduser -S lakefs -G lakefs
USER lakefs
WORKDIR /home/lakefs
ENTRYPOINT ["/app/lakectl"]

# lakefs and lakectl image
FROM --platform=$BUILDPLATFORM debian:11.6-slim AS lakefs
RUN apt-get update
RUN apt-get install -o APT::Keep-Downloaded-Packages=false -y ca-certificates
# lakefs image
FROM --platform=$BUILDPLATFORM alpine:3.16.0 AS lakefs-lakectl

RUN apk add -U --no-cache ca-certificates
# Be Docker compose friendly (i.e. support wait-for)
RUN apt-get install -o APT::Keep-Downloaded-Packages=false -y netcat-openbsd
RUN apk add netcat-openbsd

WORKDIR /app
COPY ./scripts/wait-for ./
Expand All @@ -73,19 +76,20 @@ COPY --from=build /build/lakefs /build/lakectl ./
EXPOSE 8000/tcp

# Setup user
RUN addgroup --system lakefs && adduser --system lakefs --ingroup lakefs
RUN addgroup -S lakefs && adduser -S lakefs -G lakefs
USER lakefs
WORKDIR /home/lakefs

ENTRYPOINT ["/app/lakefs"]
CMD ["run"]

# lakefs, lakectl, and plugins image
FROM --platform=$BUILDPLATFORM debian:11.6-slim AS lakefs-plugins
RUN apt-get update
RUN apt-get install -o APT::Keep-Downloaded-Packages=false -y ca-certificates
# lakefs image
FROM --platform=$BUILDPLATFORM alpine:3.16.0 AS lakefs-plugins

RUN apk add -U --no-cache ca-certificates
RUN apk add openssl-dev libc6-compat alpine-sdk
# Be Docker compose friendly (i.e. support wait-for)
RUN apt-get install -o APT::Keep-Downloaded-Packages=false -y netcat-openbsd
RUN apk add netcat-openbsd

WORKDIR /app
COPY ./scripts/wait-for ./
Expand All @@ -96,11 +100,11 @@ COPY --from=build-delta-diff-plugin /delta-diff/target/release/delta_diff ./
EXPOSE 8000/tcp

# Setup user
RUN addgroup --system lakefs && adduser --system lakefs --ingroup lakefs
RUN addgroup -S lakefs && adduser -S lakefs -G lakefs
USER lakefs
WORKDIR /home/lakefs

RUN mkdir -p /home/lakefs/.lakefs/plugins/diff && ln -s /app/delta_diff /home/lakefs/.lakefs/plugins/diff/delta

ENTRYPOINT ["/app/lakefs"]
CMD ["run"]

2 changes: 1 addition & 1 deletion esti/ops/docker-compose-dynamodb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
ports:
- "6432:8000"
esti:
image: "golang:1.19.2-bullseye"
image: "golang:1.19.2-alpine3.16"
links:
- lakefs:s3.local.lakefs.io
- lakefs:testmultipartupload.s3.local.lakefs.io
Expand Down
2 changes: 1 addition & 1 deletion esti/ops/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
POSTGRES_USER: lakefs
POSTGRES_PASSWORD: lakefs
esti:
image: "golang:1.19.2-bullseye"
image: "golang:1.19.2-alpine3.16"
links:
- lakefs:s3.local.lakefs.io
- lakefs:testmultipartupload.s3.local.lakefs.io
Expand Down

0 comments on commit 2f67bd6

Please sign in to comment.