From b9c4e7ac9be6119147bf7e78ea1b728787ac5601 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Mon, 6 Nov 2023 14:58:50 -0700 Subject: [PATCH] get it working --- Dockerfile | 35 ++++++++++++++++++++++++----------- local.Dockerfile | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index a0204f15..3319fc10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 \ @@ -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 diff --git a/local.Dockerfile b/local.Dockerfile index 45602348..8573bb9c 100644 --- a/local.Dockerfile +++ b/local.Dockerfile @@ -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 @@ -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