Skip to content

Commit

Permalink
feat: add docker build (#128)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Martin-Cocher <martincocher.jeremy@gmail.com>
  • Loading branch information
shifty11 and jmc000 authored Oct 19, 2023
1 parent 934eb5d commit 4c51a36
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
.vscode
node_modules
release
.DS_Store
/scripts/
test/.env
chain

build
16 changes: 16 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ You can verify the build information using the following command:
```shell
kyved info
```

### Building docker image

#### Root
To create a regular `kyve-network/kyve:${VERSION}` docker image with `kyved` binary only execute:
```bash
make docker-image
```
To create the corresponding debug image containing a `sh` shell execute `make docker-image-debug`.

#### Nonroot
To create a nonroot docker image `kyve-network/kyve:${VERSION}-nonroot` running with user `nonroot:65532`:
```bash
make docker-image-nonroot
```
To create the corresponding debug image `kyve-network/kyve:${VERSION}-debug-nonroot` execute `make docker-image-debug-nonroot`.
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG IMG_TAG=latest

# Compile the kyved binary
FROM golang:1.20-alpine AS kyved-builder

# Install make
RUN apk add --no-cache make

WORKDIR /go/src

# Install dependencies
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
COPY . .

ENV ENV=mainnet
RUN make install

# Copy binary to a distroless container
FROM gcr.io/distroless/static-debian11:$IMG_TAG

COPY --from=kyved-builder "/go/bin/kyved" /usr/local/bin/
EXPOSE 26656 26657 1317 9090

ENTRYPOINT ["kyved"]
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
COMMIT := $(shell git log -1 --format='%H')
GO_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1,2)
VERSION := v1.4.0 # $(shell echo $(shell git describe --tags) | sed 's/^v//')

# VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
VERSION := v1.4.0

TEAM_ALLOCATION := 165000000000000
ifeq ($(ENV),kaon)
Expand Down Expand Up @@ -73,6 +75,36 @@ release: ensure_environment ensure_version
@rm kyved
@echo "✅ Completed release creation!"

###############################################################################
### Docker Build ###
###############################################################################

# Build a release image
docker-image:
@DOCKER_BUILDKIT=1 docker build -t kyve-network/kyve:${VERSION} .
@echo "✅ Completed docker image build!"

# Build a release nonroot image
docker-image-nonroot:
@DOCKER_BUILDKIT=1 docker build \
--build-arg IMG_TAG="nonroot" \
-t kyve-network/kyve:${VERSION}-nonroot .
@echo "✅ Completed docker image build! (nonroot)"

# Build a release debug image
docker-image-debug:
@DOCKER_BUILDKIT=1 docker build \
--build-arg IMG_TAG="debug" \
-t kyve-network/kyve:${VERSION}-debug .
@echo "✅ Completed docker image build! (debug)"

# Build a release debug-nonroot image
docker-image-debug-nonroot:
@DOCKER_BUILDKIT=1 docker build \
--build-arg IMG_TAG="debug-nonroot" \
-t kyve-network/kyve:${VERSION}-debug-nonroot .
@echo "✅ Completed docker image build! (debug-nonroot)"

###############################################################################
### Checks ###
###############################################################################
Expand Down

0 comments on commit 4c51a36

Please sign in to comment.