Skip to content

Commit

Permalink
Dockerize and READM updates
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Oct 18, 2023
1 parent 5bd8581 commit 10f5e86
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ redis-cache

# Tools
bin

build
73 changes: 73 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,4 +40,17 @@ redis-stop:

lint:
@echo "--> Running linter"
golangci-lint run --timeout=10m
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 .
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions config-mainnet.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
"id": "localosmosis",
"node_uri": "tcp://localhost:26657"
}

}

0 comments on commit 10f5e86

Please sign in to comment.