Skip to content

Commit f5c76d8

Browse files
authored
Merge pull request #33 from KiFoundation/improve_makefile
Improve makefile
2 parents 3ba8ff8 + 6f62604 commit f5c76d8

File tree

3 files changed

+153
-36
lines changed

3 files changed

+153
-36
lines changed
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
ARG IMG_TAG=latest
2+
ARG PLATFORM="linux/amd64"
23

34
# Compile the kid binary
4-
FROM golang:1.17-alpine3.15 AS kid-builder
5+
FROM --platform=${PLATFORM} golang:1.17.10-alpine3.15 AS kid-builder
56
WORKDIR /src/app/
67
COPY go.mod go.sum* ./
78
RUN go mod download
89
COPY . .
910

1011
# From https://github.com/CosmWasm/wasmd/blob/master/Dockerfile
1112
# For more details see https://github.com/CosmWasm/wasmvm#builds-of-libwasmvm
12-
ARG arch=x86_64
13+
ARG ARCH=x86_64
1314
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-beta10/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
1415
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-beta10/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
1516
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 5b7abfdd307568f5339e2bea1523a6aa767cf57d6a8c72bc813476d790918e44
1617
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 2f44efa9c6c1cda138bd1f46d8d53c5ebfe1f4a53cf3457b01db86472c4917ac
17-
RUN cp /lib/libwasmvm_muslc.${arch}.a /lib/libwasmvm_muslc.a
18+
RUN cp /lib/libwasmvm_muslc.${ARCH}.a /lib/libwasmvm_muslc.a
1819

1920
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
2021
RUN apk add --no-cache $PACKAGES
2122
RUN set -eux; apk add --no-cache ca-certificates build-base;
22-
RUN BUILD_TAGS=muslc LINK_STATICALLY=true make install
23+
24+
ARG BUILD_TARGET_PREFIX=""
25+
ARG VERSION=""
26+
RUN BUILD_TAGS=muslc LINK_STATICALLY=true LDFLAGS=-buildid=$VERSION make build$BUILD_TARGET_PREFIX
2327

2428
# Add to a distroless container
25-
FROM gcr.io/distroless/cc:$IMG_TAG
29+
ARG PLATFORM="linux/amd64"
30+
FROM --platform=${PLATFORM} gcr.io/distroless/cc:$IMG_TAG
2631
ARG IMG_TAG
27-
COPY --from=kid-builder /go/bin/kid /usr/local/bin/
32+
COPY --from=kid-builder /src/app/build/kid /usr/local/bin/
2833
EXPOSE 26656 26657 1317 9090
2934

3035
ENTRYPOINT ["kid", "start"]

Makefile

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,25 @@ $(BUILD_TARGETS): go.sum $(BUILDDIR)/
109109
$(BUILDDIR)/:
110110
mkdir -p $(BUILDDIR)/
111111

112-
build-reproducible: go.sum
113-
$(DOCKER) rm latest-build || true
114-
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
115-
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64 windows/amd64' \
116-
--env APP=kid \
117-
--env VERSION=$(VERSION) \
118-
--env COMMIT=$(COMMIT) \
119-
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
120-
--name latest-build cosmossdk/rbuilder:latest
121-
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
112+
build-reproducible-all: build-reproducible-amd64 build-reproducible-arm64
113+
114+
build-reproducible-amd64:
115+
ARCH=x86_64 PLATFORM=linux/amd64 $(MAKE) build-reproducible-generic
116+
117+
build-reproducible-arm64:
118+
ARCH=aarch64 PLATFORM=linux/arm64 $(MAKE) build-reproducible-generic
119+
120+
build-reproducible-generic: go.sum
121+
$(DOCKER) rm $(subst /,-,latest-build-$(PLATFORM)) || true
122+
DOCKER_BUILDKIT=1 $(DOCKER) build -t latest-build-$(PLATFORM) \
123+
--build-arg ARCH=$(ARCH) \
124+
--build-arg PLATFORM=$(PLATFORM) \
125+
--build-arg BUILD_TARGET_PREFIX="$(BUILD_TARGET_PREFIX)" \
126+
--build-arg VERSION="$(VERSION)" \
127+
-f Dockerfile .
128+
$(DOCKER) create -ti --name $(subst /,-,latest-build-$(PLATFORM)) latest-build-$(PLATFORM) kid
129+
mkdir -p $(CURDIR)/build/$(NETWORK)/$(PLATFORM)/
130+
$(DOCKER) cp -a $(subst /,-,latest-build-$(PLATFORM)):/usr/local/bin/kid $(CURDIR)/build/$(NETWORK)/$(PLATFORM)/kid
122131

123132
build-linux: go.sum
124133
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
@@ -150,10 +159,17 @@ distclean: clean
150159
### Testnet ###
151160
###############################################################################
152161

162+
build-testnet-reproducible-all: build-testnet-reproducible-amd64 build-testnet-reproducible-arm64
163+
164+
build-testnet-reproducible-amd64:
165+
ARCH=x86_64 PLATFORM=linux/amd64 NETWORK=Testnet ADDRESS_PREFIX=tki BUILD_TARGET_PREFIX="-testnet" $(MAKE) build-reproducible-generic
166+
167+
build-testnet-reproducible-arm64:
168+
ARCH=aarch64 PLATFORM=linux/arm64 NETWORK=Testnet ADDRESS_PREFIX=tki BUILD_TARGET_PREFIX="-testnet" $(MAKE) build-reproducible-generic
169+
153170
build-testnet: go.sum
154171
NETWORK=Testnet ADDRESS_PREFIX=tki $(MAKE) build
155172

156-
157173
###############################################################################
158174
### Devdoc ###
159175
###############################################################################
@@ -203,7 +219,7 @@ benchmark:
203219
@go test -mod=readonly -bench=. ./...
204220

205221
docker-build-debug:
206-
@docker build -t cosmos/kid-e2e --build-arg IMG_TAG=debug -f e2e.Dockerfile .
222+
@docker build -t cosmos/kid-e2e --build-arg IMG_TAG=debug -f Dockerfile .
207223

208224
###############################################################################
209225
### Linting ###

README.md

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
</p>
44

55
# Ki Tools
6-
This repository hosts `ki-tools`, a set of tools that allow to deploy and run Kichain nodes.
76

7+
This repository hosts `kid`, the implementation of the kichain protocol, based on Cosmos-SDK.
88

99
## Quick Start
1010

11-
### Install Golang
11+
### Install Golang (linux)
12+
1213
To install Go, visit the Go download page and copy the link of the latest Go release for Linux systems, download and unzip the archive file as follows:
1314

14-
```
15-
wget https://dl.google.com/go/go1.16.linux-amd64.tar.gz
16-
sudo tar -C /usr/local -xzf go1.16.linux-amd64.tar.gz
15+
```bash
16+
wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz
17+
sudo tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz
1718
```
1819

1920
Finally, export the Go paths like so:
2021

21-
```
22+
```bash
2223
mkdir -p $HOME/go/bin
2324
PATH=$PATH:/usr/local/go/bin
2425
echo "export PATH=$PATH:$(go env GOPATH)/bin" >> ~/.bash_profile
@@ -27,46 +28,141 @@ source ~/.bash_profile
2728

2829
To test the Go installation, use the `version` command to check the downloaded version as follows :
2930

30-
```
31+
```bash
3132
go version
3233
```
3334

3435
This should output :
3536

36-
```
37-
go version go1.16 linux/amd64
37+
```bash
38+
go version go1.17 linux/amd64
3839
```
3940

40-
### Install ki-tools
41-
Start by clone this repository. If you are here, you most likely have git installed already, otherwise just run:
41+
### Build kid (linux)
4242

43-
```
43+
Start by cloning this repository. If you are here, you most likely have git installed already, otherwise just run:
44+
45+
```bash
4446
sudo apt install git
4547
```
4648

4749
And now you can clone the repository as follows:
48-
```
50+
51+
```bash
4952
git clone https://github.com/KiFoundation/ki-tools.git
5053
```
5154

5255
If your are starting with a clean ubuntu install you might need to install the `build-essential` package:
5356

54-
```
57+
```bash
5558
sudo apt update
5659
sudo apt install build-essential
5760
```
5861

5962
Finally, navigate to the repository folder and install the tools as follows:
6063

61-
```
64+
```bash
6265
cd ki-tools
6366
make install
6467
```
6568

66-
To test the installation, check the downloaded version as follows :
67-
```
69+
To test the installation, check the downloaded version as follows:
70+
71+
```bash
6872
kid version --long
6973
```
7074

75+
### Building for testnet
76+
77+
Testnet token name (tki) is different from mainnet (xki). Testnet binaries need to support this difference.
78+
To build a testnet binary, run as follows:
79+
80+
```bash
81+
cd ki-tools
82+
make build-testnet
83+
```
84+
85+
You can also build a static testnet binary as explained in the following section.
86+
87+
### Build a static kid binary
88+
89+
#### **Why building static binaries ?**
90+
91+
Static binaries hermetically contain libraries that they are using. Dynamic binaries rely on libraries located elsewhere on the system, the binary only containing the address of the library.
92+
There are multiple pro and cons of **static vs dynamic**.
93+
94+
For `kid`, we provide a set a tool to build static binaries, as we want to ensure that:
95+
96+
* Binaries and dependencies are consistent accross the validators set.
97+
* Build result is reproducible and can be verified by every user.
98+
99+
Using static, verified, binaries ensures that all nodes mainteners are running the same version of dependencies, the `cosmwasm` particulary.
100+
You can see this as a protection against unexpected consensus failures due to binary dependency mismatch.
101+
102+
Static binaries integrity can be checked by comparing sha256sum.
103+
104+
#### **Requirements**
105+
106+
To build a static binary, we rely on `Docker` and `alpine` docker images.
107+
108+
##### **Install docker**
109+
110+
To install docker, follow [the official procedure for your platform](https://docs.docker.com/get-docker/)
111+
112+
##### **Install Qemu (Optional)**
113+
114+
If you want to build `kid` to run on a platform different from your build platform, you will need to install `Qemu`:
115+
116+
For linux users:
117+
118+
```bash
119+
sudo apt-get install qemu binfmt-support qemu-user-static
120+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
121+
```
122+
123+
For macOS users, `Qemu` should already be installed and configured when installing `Docker Desktop`.
124+
125+
##### **Build**
126+
127+
```bash
128+
cd ki-tools
129+
```
130+
131+
Build an `amd64` static binary
132+
133+
```bash
134+
make build-reproducible-amd64 # For mainnet
135+
make build-reproducible-testnet-amd64 # For testnet
136+
```
137+
138+
Build an `arm64` static binary
139+
140+
```bash
141+
make build-reproducible-arm64 # For mainnet
142+
make build-reproducible-testnet-arm64 # For testnet
143+
```
144+
145+
**Note:** arm64 compatiblity is proposed but not guaranteed. We recommend users to run on amd64 platforms.
146+
147+
Built binaries can then be found in the **build** folder
148+
149+
```bash
150+
$ tree build
151+
build
152+
├── Mainnet
153+
│ └── linux
154+
│ ├── amd64
155+
│ │ └── kid
156+
│ └── arm64
157+
│ └── kid
158+
└── Testnet
159+
└── linux
160+
├── amd64
161+
│ └── kid
162+
└── arm64
163+
└── kid
164+
```
165+
71166
## Disclaimer
72-
The `ki-tools` is a modified clone of the `gaia` project. More about the latter can be found [here](https://github.com/cosmos/gaia).
167+
168+
The `ki-tools` is a modified clone of the `gaia` project. More about the latter can be found [here](https://github.com/cosmos/gaia).

0 commit comments

Comments
 (0)