From 5e9372fd7fdaed787a2c7f6f779c18ab17e0f33e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 6 Mar 2024 17:26:01 +0530 Subject: [PATCH] Add a Dockerfile --- .gitignore | 3 ++ Dockerfile | 31 +++++++++++++++++++++ Makefile | 29 +++++++++++++------ README.md | 2 +- tests/sdk_tests/build-laconicd-container.sh | 3 ++ 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 Dockerfile create mode 100755 tests/sdk_tests/build-laconicd-container.sh diff --git a/.gitignore b/.gitignore index 3b735ec4..61aa57ea 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ # Go workspace file go.work + +# build +build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2a3e66c3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM golang:alpine AS build-env + +# Install dependencies +RUN apk add --update git build-base linux-headers + +# Set working directory for the build +WORKDIR /go/src/git.vdb.to/cerc-io/laconic2d + +# Cache Go modules +COPY go.mod go.sum ./ +RUN go mod download + +# Add source files +COPY . . + +# Make the binary +RUN make build + +# Final image +FROM alpine:3.17.0 + +# Install ca-certificates +RUN apk add --update ca-certificates jq curl + +# Copy over binaries from the build-env +COPY --from=build-env /go/src/git.vdb.to/cerc-io/laconic2d/build/laconic2d /usr/bin/laconic2d + +WORKDIR / + +# Run laconic2d by default +CMD ["laconic2d"] diff --git a/Makefile b/Makefile index 99401443..a89331a3 100644 --- a/Makefile +++ b/Makefile @@ -24,20 +24,33 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=laconic \ BUILD_FLAGS := -ldflags '$(ldflags)' +BUILDDIR ?= $(CURDIR)/build + ########### # Install # ########### +go.sum: go.mod + echo "Ensure dependencies have not been modified ..." >&2 + go mod verify + go mod tidy + +BUILD_TARGETS := build install + +build: BUILD_ARGS=-o $(BUILDDIR)/ +build-linux: + GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build + +$(BUILD_TARGETS): go.sum $(BUILDDIR)/ + @echo "--> installing laconic2d" + go $@ $(BUILD_FLAGS) $(BUILD_ARGS) ./... + +$(BUILDDIR)/: + mkdir -p $(BUILDDIR)/ + all: install -install: - @echo "--> ensure dependencies have not been modified" - @go mod verify - @echo "--> installing laconic2d" - @go install $(BUILD_FLAGS) -mod=readonly ./cmd/laconic2d - -init: - ./scripts/init.sh +.PHONY: build build-linux install ################## ### Protobuf ### diff --git a/README.md b/README.md index cf2e1845..73266c19 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Install `laconic2d`: make install ``` -Run with a single node: +Run with a single node fixture: ```bash # start the chain diff --git a/tests/sdk_tests/build-laconicd-container.sh b/tests/sdk_tests/build-laconicd-container.sh new file mode 100755 index 00000000..c2cb4ec4 --- /dev/null +++ b/tests/sdk_tests/build-laconicd-container.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker build -t cerc/laconic2d:local ../.. --progress=plain --no-cache