Skip to content

Commit

Permalink
Merge pull request #479 from jhkimqd/jihwan/dockerfile
Browse files Browse the repository at this point in the history
fix: dockerfile build
  • Loading branch information
jhkimqd authored Jan 20, 2025
2 parents fd31b1e + 228120a commit 07275ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp/
40 changes: 17 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
FROM golang:1.22 AS builder
# Build stage
FROM --platform=${BUILDPLATFORM} golang:1.22 AS builder

# Set the workspace for the build
WORKDIR /workspace

# Copy only necessary Go module files for caching dependencies
COPY go.mod go.sum ./
RUN go mod download

COPY abi/ abi/
COPY bindings/ bindings/
COPY cmd/ cmd/
COPY dashboard/ dashboard/
COPY gethkeystore/ gethkeystore/
COPY hdwallet/ hdwallet/
COPY metrics/ metrics/
COPY p2p/ p2p/
COPY proto/ proto/
COPY rpctypes/ rpctypes/
COPY util/ util/
COPY main.go ./
RUN CGO_ENABLED=0 go build -o polycli main.go
# Copy the necessary source code
COPY . ./

# Build the Go binary
RUN go build -o /workspace/polycli main.go

# Final stage: minimal base image
FROM --platform=${BUILDPLATFORM} debian:bookworm-slim

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
# Copy only the necessary files from the builder image
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /workspace/polycli /usr/bin/polycli
USER 65532:65532
ENTRYPOINT ["polycli"]
CMD ["--help"]

# How to test this image?
# https://github.com/0xPolygon/polygon-cli/pull/189#discussion_r1464486344
# Default cmd for the container
ENTRYPOINT ["polycli"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ $(BUILD_DIR): ## Create the build folder.
build: $(BUILD_DIR) ## Build go binary.
go build -ldflags "$(VERSION_FLAGS)" -o $(BUILD_DIR)/$(BIN_NAME) main.go

.PHONY: build-docker
build-docker: ## Builds a docker image with the polycli binary
docker build -t polycli -f ./Dockerfile .

.PHONY: install
install: build ## Install the go binary.
$(RM) $(INSTALL_DIR)/$(BIN_NAME)
Expand Down

0 comments on commit 07275ea

Please sign in to comment.