Skip to content

Commit

Permalink
separate rocksdb image
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 6, 2023
1 parent 23ba229 commit f7e4490
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 19 deletions.
17 changes: 5 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 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\
Expand All @@ -24,12 +27,6 @@ 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

# Install RocksDB
WORKDIR /
RUN git clone -b v7.10.2 --single-branch https://github.com/facebook/rocksdb.git

WORKDIR /rocksdb

RUN set -eux;\
if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \
echo aarch64 > /etc/apk/arch;\
Expand All @@ -44,12 +41,8 @@ RUN set -eux;\
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
# Install RocksDB headers and static library
COPY --from=rocksdb /rocksdb /rocksdb

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
12 changes: 5 additions & 7 deletions local.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 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\
Expand All @@ -20,13 +23,8 @@ RUN apk add --update --no-cache\
lz4-static\
zstd-static

# Install RocksDB
WORKDIR /
RUN git clone -b v7.10.2 --single-branch https://github.com/facebook/rocksdb.git

WORKDIR /rocksdb

RUN make -j$(nproc) static_lib
# Install RocksDB headers and static library
COPY --from=rocksdb /rocksdb /rocksdb

WORKDIR /workspace
# Copy the Go Modules manifests
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

0 comments on commit f7e4490

Please sign in to comment.