Skip to content

Commit

Permalink
get it working
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 6, 2023
1 parent 5984eb2 commit b9c4e7a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
35 changes: 24 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ RUN apk add --update --no-cache\
libc-dev\
git\
make\
bash \
g++ \
linux-headers \
bash\
g++\
linux-headers\
perl\
snappy-dev\
snappy-static\
zlib-dev\
zlib-static\
bzip2-dev\
bzip2-static\
lz4-dev\
lz4-static\
zstd-dev\
zstd-static
zstd-dev

ARG TARGETARCH
ARG BUILDARCH
Expand All @@ -35,6 +30,20 @@ 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;\
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 \
Expand Down Expand Up @@ -65,8 +74,12 @@ RUN set -eux;\
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"';\
export LD_LIBRARY_PATH=/rocksdb CGO_CFLAGS="-I/rocksdb/include" CGO_LDFLAGS="-L/rocksdb -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd";\
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
Expand Down
35 changes: 32 additions & 3 deletions local.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
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
WORKDIR /
RUN git clone -b v7.10.2 --single-branch https://github.com/facebook/rocksdb.git

WORKDIR /rocksdb

RUN make -j$(nproc) static_lib

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -19,8 +45,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

0 comments on commit b9c4e7a

Please sign in to comment.