Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocksdb and pebbledb support #386

Merged
merged 10 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# See rocksdb/README.md for instructions to update rocksdb version
FROM ghcr.io/strangelove-ventures/rocksdb:v7.10.2 AS rocksdb

FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS builder

RUN apk add --update --no-cache gcc libc-dev
RUN apk add --update --no-cache\
gcc\
libc-dev\
git\
make\
bash\
g++\
linux-headers\
perl\
snappy-dev\
zlib-dev\
bzip2-dev\
lz4-dev\
zstd-dev

ARG TARGETARCH
ARG BUILDARCH
Expand All @@ -11,6 +27,23 @@ RUN if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
wget -c https://musl.cc/x86_64-linux-musl-cross.tgz -O - | tar -xzvv --strip-components 1 -C /usr; \
fi

RUN set -eux;\
if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
echo aarch64 > /etc/apk/arch;\
elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \
echo x86_64 > /etc/apk/arch;\
fi;\
apk add --update --no-cache\
snappy-static\
zlib-static\
bzip2-static\
lz4-static\
zstd-static\
--allow-untrusted

# Install RocksDB headers and static library
COPY --from=rocksdb /rocksdb /rocksdb

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -28,13 +61,19 @@ COPY internal/ internal/

ARG VERSION

RUN if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
RUN set -eux;\
if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then\
export CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++;\
elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \
export CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++; \
fi; \
export GOOS=linux GOARCH=$TARGETARCH CGO_ENABLED=1 LDFLAGS='-linkmode external -extldflags "-static"'; \
go build -ldflags "-X github.com/strangelove-ventures/cosmos-operator/internal/version.version=$VERSION $LDFLAGS" -a -o manager .
elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then\
export CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++;\
fi;\
export GOOS=linux \
GOARCH=$TARGETARCH \
CGO_ENABLED=1 \
LDFLAGS='-linkmode external -extldflags "-static"' \
CGO_CFLAGS="-I/rocksdb/include" \
CGO_LDFLAGS="-L/rocksdb -L/usr/lib -L/lib -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd";\
go build -tags 'rocksdb pebbledb' -ldflags "-X github.com/strangelove-ventures/cosmos-operator/internal/version.version=$VERSION $LDFLAGS" -a -o manager .

# Build final image from scratch
FROM scratch
Expand Down
33 changes: 30 additions & 3 deletions local.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# See rocksdb/README.md for instructions to update rocksdb version
FROM ghcr.io/strangelove-ventures/rocksdb:v7.10.2 AS rocksdb

FROM golang:1.20-alpine AS builder

RUN apk add --update --no-cache gcc libc-dev
RUN apk add --update --no-cache\
gcc\
libc-dev\
git\
make\
bash\
g++\
linux-headers\
perl\
snappy-dev\
zlib-dev\
bzip2-dev\
lz4-dev\
zstd-dev\
snappy-static\
zlib-static\
bzip2-static\
lz4-static\
zstd-static

# Install RocksDB headers and static library
COPY --from=rocksdb /rocksdb /rocksdb

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -19,8 +43,11 @@ COPY internal/ internal/

ARG VERSION

RUN export CGO_ENABLED=1 LDFLAGS='-linkmode external -extldflags "-static"'; \
go build -ldflags "-X github.com/strangelove-ventures/cosmos-operator/internal/version.version=$VERSION $LDFLAGS" -a -o manager .
RUN export CGO_ENABLED=1 \
LDFLAGS='-linkmode external -extldflags "-static"' \
CGO_CFLAGS="-I/rocksdb/include" \
CGO_LDFLAGS="-L/rocksdb -L/usr/lib -L/lib -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd";\
go build -tags 'rocksdb pebbledb' -ldflags "-X github.com/strangelove-ventures/cosmos-operator/internal/version.version=$VERSION $LDFLAGS" -a -o manager .

# Build final image from scratch
FROM scratch
Expand Down
54 changes: 54 additions & 0 deletions rocksdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS builder

RUN apk add --update --no-cache\
gcc\
libc-dev\
git\
make\
bash\
g++\
linux-headers\
perl\
snappy-dev\
zlib-dev\
bzip2-dev\
lz4-dev\
zstd-dev

ARG TARGETARCH
ARG BUILDARCH

RUN if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
wget -c https://musl.cc/aarch64-linux-musl-cross.tgz -O - | tar -xzvv --strip-components 1 -C /usr; \
elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \
wget -c https://musl.cc/x86_64-linux-musl-cross.tgz -O - | tar -xzvv --strip-components 1 -C /usr; \
fi

ARG ROCKSDB_VERSION=v7.10.2

# Install RocksDB
WORKDIR /
RUN git clone -b ${ROCKSDB_VERSION} --single-branch https://github.com/facebook/rocksdb.git

WORKDIR /rocksdb

RUN set -eux;\
if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
echo aarch64 > /etc/apk/arch;\
elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \
echo x86_64 > /etc/apk/arch;\
fi;\
apk add --update --no-cache\
snappy-static\
zlib-static\
bzip2-static\
lz4-static\
zstd-static\
--allow-untrusted

RUN if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
export CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++;\
elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \
export CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++; \
fi; \
PORTABLE=1 make -j$(nproc) static_lib
16 changes: 16 additions & 0 deletions rocksdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# RocksDB Static Build

This Dockerfile produces cross-architecture (amd64 and arm64) docker images with a static rocksdb library.

## Reason

This static rocksdb build takes a while, and it is not necessary to build every time the cosmos-operator docker image is built, so this image caches the required artifacts to link rocksdb into the operator build.

## Build and push to Github Container Registry

```
ROCKSDB_VERSION=v7.10.2
docker buildx build --platform linux/arm64,linux/amd64 --build-arg "ROCKSDB_VERSION=$ROCKSDB_VERSION" --push -t ghcr.io/strangelove-ventures/rocksdb:$ROCKSDB_VERSION .
```

After publishing a new version, import that version in the `Dockerfile` and `local.Dockerfile` in the root of the cosmos-operator repository
Loading