From 10f5e8694c31276e4310d84cbf7b55c181b310e2 Mon Sep 17 00:00:00 2001 From: "roman@osmosis.team" Date: Tue, 17 Oct 2023 20:40:43 -0400 Subject: [PATCH] Dockerize and READM updates --- .gitignore | 2 ++ Dockerfile | 73 +++++++++++++++++++++++++++++++++++++++++++++ Makefile | 25 +++++++++++++++- README.md | 17 ++++++++++- config-mainnet.json | 21 +++++++++++++ config.json | 1 - 6 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 config-mainnet.json diff --git a/.gitignore b/.gitignore index 0f106687..f9760d5d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ redis-cache # Tools bin + +build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f8f1665a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,73 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION="1.20" +ARG RUNNER_IMAGE="ubuntu" + +# -------------------------------------------------------- +# Builder +# -------------------------------------------------------- + +FROM golang:1.20-alpine as builder + +ARG GIT_VERSION +ARG GIT_COMMIT + +# Download go dependencies +WORKDIR /osmosis +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + go mod download + +# Cosmwasm - Download correct libwasmvm version +RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \ + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.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.$ARCH | cut -d ' ' -f 1) + +# Copy the remaining files +COPY . . + +RUN set -eux; apk add --no-cache ca-certificates build-base; + +# needed by github.com/zondax/hid +RUN apk add linux-headers + +# Cosmwasm - Download correct libwasmvm version +RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \ + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.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.$ARCH | cut -d ' ' -f 1) + +RUN BUILD_TAGS=muslc LINK_STATICALLY=true GOWORK=off go build \ + -mod=readonly \ + -tags "netgo,ledger,muslc" \ + -ldflags \ + "-X github.com/cosmos/cosmos-sdk/version.Name="osmosis" \ + -X github.com/cosmos/cosmos-sdk/version.AppName="osmosisd" \ + -X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \ + -X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \ + -X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc \ + -w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \ + -v -o /osmosis/build/sqsd /osmosis/app/main.go + +# -------------------------------------------------------- +# Runner +# -------------------------------------------------------- + +FROM ${RUNNER_IMAGE} + +COPY --from=builder /osmosis/build/sqsd /bin/sqsd +COPY --from=builder /osmosis/config-mainnet.json /osmosis/config.json + +ENV HOME /osmosis +WORKDIR $HOME + +EXPOSE 9092 + +ENTRYPOINT ["/bin/sqsd"] + diff --git a/Makefile b/Makefile index 27bb61c0..c0077d63 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,16 @@ export SHELL := bash # Type of OS: Linux or Darwin. export OSTYPE := $(shell uname -s) +VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') +COMMIT := $(shell git log -1 --format='%H') +GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2) + +BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' +# check for nostrip option +ifeq (,$(findstring nostrip,$(OSMOSIS_BUILD_OPTIONS))) + BUILD_FLAGS += -trimpath +endif + # --- Tooling & Variables ---------------------------------------------------------------- include ./misc/make/tools.Makefile @@ -30,4 +40,17 @@ redis-stop: lint: @echo "--> Running linter" - golangci-lint run --timeout=10m \ No newline at end of file + golangci-lint run --timeout=10m + +############################################################################### +### Docker ### +############################################################################### + +docker-build: + @DOCKER_BUILDKIT=1 docker build \ + -t sqs:local \ + -t sqs:local-distroless \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + -f Dockerfile . diff --git a/README.md b/README.md index 71221a01..d296036a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,26 @@ # Sidecar Query Server (SQS) +## To Run + +- Ensure that Redis is running locally + * Instructions TBD +- Ensure that localosmosis is running locally + +``` +make run +``` +- Uses the `config.json` para + ## TODOs -- Upgrade to Go 1.21 +- Set-up docker-compose that starts up all test services: sqs, localosmosis and redis - Reduce code duplication in pool repository tests by using Generics - Consider separate balancer and stableswap pools to be written to separate indexes - Switch to using custom pool models and avoid writing chain pool models to state +- Tests + - Refactor & test worker that pulls data from chain + - Test pools use case + - Test pools delivery ## Questions diff --git a/config-mainnet.json b/config-mainnet.json new file mode 100644 index 00000000..64cab2cf --- /dev/null +++ b/config-mainnet.json @@ -0,0 +1,21 @@ +{ + "debug": true, + "server": { + "address": ":9092" + }, + "context":{ + "timeout":2 + }, + "database": { + "host": "localhost", + "port": "6379", + "user": "user", + "pass": "password", + "name": "article" + }, + "chain": { + "id": "localosmosis", + "node_uri": "https://rpc.osmosis.zone:443" + } + } + \ No newline at end of file diff --git a/config.json b/config.json index ba9a2f3f..ace599c7 100644 --- a/config.json +++ b/config.json @@ -17,6 +17,5 @@ "id": "localosmosis", "node_uri": "tcp://localhost:26657" } - } \ No newline at end of file