Skip to content

Commit

Permalink
Add docker file (#9)
Browse files Browse the repository at this point in the history
* add docker file

* makefile and minor fix

---------

Co-authored-by: Vitalis Salis <vitsalis@gmail.com>
  • Loading branch information
gitferry and vitsalis authored Jul 18, 2023
1 parent 2e635fb commit cbd47c2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM golang:1.20.5-alpine as builder

# Version to build. Default is the Git HEAD.
ARG VERSION="HEAD"

# Use muslc for static libs
ARG BUILD_TAGS="muslc"


RUN apk add --no-cache --update openssh git make build-base linux-headers libc-dev \
pkgconfig zeromq-dev musl-dev alpine-sdk libsodium-dev \
libzmq-static libsodium-static gcc


RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN git config --global url."git@github.com:".insteadOf "https://github.com/"
ENV GOPRIVATE=github.com/babylonchain/babylon-private

# Build
WORKDIR /go/src/github.com/babylonchain/btc-validator
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonchain/btc-validator/
RUN --mount=type=secret,id=sshKey,target=/root/.ssh/id_rsa go mod download
# Copy the rest of the files
COPY ./ /go/src/github.com/babylonchain/btc-validator/

# Cosmwasm - Download correct libwasmvm version
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$(uname -m) | cut -d ' ' -f 1)

RUN CGO_LDFLAGS="$CGO_LDFLAGS -lstdc++ -lm -lsodium" \
CGO_ENABLED=1 \
BUILD_TAGS=$BUILD_TAGS \
LINK_STATICALLY=true \
make build

# FINAL IMAGE
FROM alpine:3.16 AS run

RUN addgroup --gid 1138 -S btcvalidator && adduser --uid 1138 -S btcvalidator -G btcvalidator

RUN apk add bash curl jq

COPY --from=builder /go/src/github.com/babylonchain/btc-validator/build/vald /bin/vald
COPY --from=builder /go/src/github.com/babylonchain/btc-validator/build/valcli /bin/valcli

WORKDIR /home/btcvalidator
RUN chown -R btcvalidator /home/btcvalidator
USER btcvalidator

ENTRYPOINT ["/bin/vald"]
CMD []
STOPSIGNAL SIGTERM
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ $(BUILD_TARGETS): go.sum $(BUILDDIR)/
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

.PHONY: build
build-docker:
$(DOCKER) build --secret id=sshKey,src=${BBN_PRIV_DEPLOY_KEY} --tag babylonchain/btc-validator -f Dockerfile \
$(shell git rev-parse --show-toplevel)

.PHONY: build build-docker

test:
go test ./...
Expand Down

0 comments on commit cbd47c2

Please sign in to comment.