Skip to content

Commit

Permalink
add dockerfile, contracts, and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
dekm committed Mar 13, 2024
1 parent 382a4e0 commit 0611d18
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# docker build . -t unigrid/paxd:latest
# docker run --name paxd --rm -it unigrid/paxd:latest /bin/sh
# docker cp pax:/usr/bin/paxd /path/to/local/directory

# Use the Go alpine image as the base for the builder stage
FROM golang:1.21-alpine AS go-builder

SHELL ["/bin/sh", "-ecuxo", "pipefail"]

# Install necessary build dependencies
RUN apk add --no-cache ca-certificates build-base git

WORKDIR /code

# Add go.mod and go.sum to download and cache dependencies
ADD go.mod go.sum ./

# Dynamically determine the version of CosmWasm libwasmvm and download it
RUN set -eux; \
ARCH=$(uname -m); \
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \
if [ ! -z "${WASM_VERSION}" ]; then \
wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
fi; \
go mod download

# Copy over the source code
COPY . /code/

# Build the project with static linking using the Makefile
# Ensure that the binary is statically linked
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build \
&& file /code/bin/paxd \
&& echo "Ensuring binary is statically linked ..." \
&& (file /code/bin/paxd | grep "statically linked")

# Start a new stage for the final image
FROM alpine:3.16

# Copy the built binary from the builder stage
COPY --from=go-builder /code/bin/paxd /usr/bin/paxd

# Copy the necessary scripts and configuration files
COPY docker/* /opt/
RUN chmod +x /opt/*.sh

COPY contracts/artifacts /opt/artifacts/

WORKDIR /opt

# Expose necessary ports (adjust these according to your application's needs)
EXPOSE 1317 26656 26657 9090

# Define the default command
CMD ["/usr/bin/paxd", "version"]
69 changes: 69 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/make -f

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
BINDIR ?= $(GOPATH)/bin
APP = ./app

# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
DOCKER := $(shell which docker)
BUILDDIR ?= $(CURDIR)/build
export GO111MODULE = on

# process build tags
build_tags = netgo osusergo

ifeq ($(LEDGER_ENABLED),true)
# Add ledger build tags if necessary
endif

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))

# process linker flags
ldflags = -X github.com/unigrid-project/pax/cmd/paxd/version.Name=pax \
-X github.com/unigrid-project/pax/cmd/paxd/version.AppName=paxd \
-X github.com/unigrid-project/pax/cmd/paxd/version.Version=$(VERSION) \
-X github.com/unigrid-project/pax/cmd/paxd/version.Commit=$(COMMIT) \
-X "github.com/unigrid-project/pax/cmd/paxd/version.BuildTags=$(build_tags_comma_sep)"

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ifeq (,$(findstring nostrip,$(JUNO_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
ifeq (,$(findstring nostrip,$(JUNO_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

all: install

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/paxd

build:
go build $(BUILD_FLAGS) -o bin/paxd ./cmd/paxd

# Add other targets like test, lint, clean, etc., as per your project's needs

.PHONY: all install build
8 changes: 8 additions & 0 deletions contracts/artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
174e11919fa261986da7893da5f08a2dad8694cb281753d23bbecab1521d6b3a cw1_subkeys.wasm
91f3f07865a8f953625e36e2a7c024363a94e91f1b56aba5ef8e0dc7d3c15f57 cw1_whitelist.wasm
b460b30d218b3bbd6e7f77a917c85f2352714d63d611601811c77056c985b180 cw20_base.wasm
d2aaf86f9b2edba244fad10ae4025e3d4e09b07b5afb135d68721d9257d64ca3 cw20_ics20.wasm
f2f8b6517da62c070ff312fe435eaac9e4812bd9fa82e3d1f51426db1b6ec54b cw3_fixed_multisig.wasm
189fceef673c9e4e1895231582d1a2276cc8171b1b3509a34672dfa0b9365b04 cw3_flex_multisig.wasm
3ea6161ae16129418ae2a7808df90ababd2b7931fdc3bf2da08dd215090e87ed cw4_group.wasm
b8985e434092ad8f378dfb0465502dce95eb4e858607e80deb6adf23c684fd10 cw4_stake.wasm
8 changes: 8 additions & 0 deletions contracts/artifacts/checksums_intermediate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
c78975fd4a247f8966d823b0537486f2f98fa856d312dfaa5391a193ce3f1244 target/wasm32-unknown-unknown/release/cw1_subkeys.wasm
0bba681e6d235efa7c2ee9c6782a670d9ac378e0292fea8ff863f1997667886f target/wasm32-unknown-unknown/release/cw1_whitelist.wasm
4c20b021f677d7a1b38c52ceae113234fbcf746b8562e41b4cbf217edb56c300 target/wasm32-unknown-unknown/release/cw20_base.wasm
01e446628de73b15b85f27e8b105eafcbdebc9294a424aba4ae0b016e451e28a target/wasm32-unknown-unknown/release/cw20_ics20.wasm
d43f03e919104f80fbb7c0c6c4de7a01e1ad3c680c502ae460c28d88e10677a6 target/wasm32-unknown-unknown/release/cw3_fixed_multisig.wasm
fdab4220eb1f1dc9fb265c70588aac49d71422e9f0156fb18b97b24f150873a3 target/wasm32-unknown-unknown/release/cw3_flex_multisig.wasm
3afa37810f57a53e88b82e3e9ac4355cf45a6a426a71e6b37e37a61cfc4a1161 target/wasm32-unknown-unknown/release/cw4_group.wasm
43143990f5bd9ab3f35462007c44af7bd7b896d817b680413724388abc655ca8 target/wasm32-unknown-unknown/release/cw4_stake.wasm
Binary file added contracts/artifacts/cw1_subkeys.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw1_whitelist.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw20_base.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw20_ics20.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw3_fixed_multisig.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw3_flex_multisig.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw4_group.wasm
Binary file not shown.
Binary file added contracts/artifacts/cw4_stake.wasm
Binary file not shown.
12 changes: 12 additions & 0 deletions docker/run_paxd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if test -n "$1"; then
# need -R not -r to copy hidden files
cp -R "$1/.paxd" /root
fi

# Create a unique log file name with timestamp
LOG_FILE="/root/paxd_$(date +%Y%m%d_%H%M%S).log"

mkdir -p /root/log
paxd start --rpc.laddr tcp://0.0.0.0:26657 --api.enable=true --api.swagger=true --api.address tcp://0.0.0.0:1317 --trace >> "$LOG_FILE" 2>&1
4 changes: 4 additions & 0 deletions docker/setup_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

./setup_paxd.sh "$@"
./run_paxd.sh
33 changes: 33 additions & 0 deletions docker/setup_paxd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
#set -o errexit -o nounset -o pipefail

PASSWORD=${PASSWORD:-1234567890}
STAKE=${STAKE_TOKEN:-ustake}
FEE=${FEE_TOKEN:-ucosm}
CHAIN_ID=${CHAIN_ID:-testing}
MONIKER=${MONIKER:-node001}

paxd init --chain-id "$CHAIN_ID" "$MONIKER"
# staking/governance token is hardcoded in config, change this
sed -i "s/\"stake\"/\"$STAKE\"/" "$HOME"/.pax/config/genesis.json
# this is essential for sub-1s block times (or header times go crazy)
sed -i 's/"time_iota_ms": "1000"/"time_iota_ms": "10"/' "$HOME"/.pax/config/genesis.json

if ! paxd keys show validator; then
(echo "$PASSWORD"; echo "$PASSWORD") | paxd keys add validator
fi
# hardcode the validator account for this instance
echo "$PASSWORD" | paxd genesis add-genesis-account validator "1000000000$STAKE,1000000000$FEE"

# (optionally) add a few more genesis accounts
for addr in "$@"; do
echo $addr
paxd genesis add-genesis-account "$addr" "1000000000$STAKE,1000000000$FEE"
done

# submit a genesis validator tx
## Workraround for https://github.com/cosmos/cosmos-sdk/issues/8251
(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | paxd genesis gentx validator "250000000$STAKE" --chain-id="$CHAIN_ID" --amount="250000000$STAKE"
## should be:
# (echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | paxd gentx validator "250000000$STAKE" --chain-id="$CHAIN_ID"
paxd genesis collect-gentxs
34 changes: 34 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,38 @@ After compiling you can check the version was correctly added.
paxd version
```

### Dev server

Bring up a local node with a test account containing tokens

This is just designed for local testing/CI - do not use these scripts in production.
Very likely you will assign tokens to accounts whose mnemonics are public on github.

### Build the container with latest code
```sh
docker build --no-cache . -t unigrid/paxd:latest
```
Remove the volume to reset data.
```sh
docker volume rm -f paxd_data

# pass password (one time) as env variable for setup, so we don't need to keep typing it
# add some addresses that you have private keys for (locally) to give them genesis funds
docker run --rm -it \
--name paxd \
-p 1317:1317 \
-e PASSWORD=xxxxxxxx \
--mount type=volume,source=paxd_data,target=/root \
unigrid/paxd:latest /opt/setup_and_run.sh unigrid1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6

# only perform setup
docker run --rm -it \
-e PASSWORD=xxxxxxxx \
--mount type=volume,source=paxd_data,target=/root \
unigrid/paxd:latest /opt/setup_paxd.sh unigrid1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6

# This will start both paxd and rest-server, both are logged
docker run --rm -it -p 26657:26657 -p 26656:26656 -p 1317:1317 \
--mount type=volume,source=paxd_data,target=/root \
unigrid/paxd:latest /opt/run_paxd.sh
```

0 comments on commit 0611d18

Please sign in to comment.