Skip to content

Commit

Permalink
feat: Update Docker image build process
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiD2ta committed Sep 25, 2024
1 parent fd2f56e commit bb6f17f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
nethermindeth/${{env.APP_NAME}}:${{env.VERSION}}
nethermindeth/${{env.APP_NAME}}:latest
build-args: |
APP_NAME=${{ env.APP_NAME }}
VERSION=${{ env.VERSION }}
- name: Log out of Docker Hub
Expand Down
29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
# Builder stage
FROM golang:1.23-alpine AS builder

ENV APP_NAME=app
ARG APP_NAME
ARG VERSION

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy the source code into the container
COPY --link . .
# Copy go.mod and go.sum first for better caching
COPY go.mod go.sum ./
RUN go mod download

# Now copy the rest of the source code
COPY . .

# Build the Go app with version argument
ARG VERSION
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o ./bin/${APP_NAME}
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o ./bin/${APP_NAME} ./cmd/${APP_NAME}/main.go

# Final stage
FROM debian:buster-slim
#FROM debian:buster-slim
FROM alpine:latest

ARG APP_NAME
ENV APP_NAME=${APP_NAME}

# Install CA certificates
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates gnupg curl
#RUN apt-get update && apt-get install -y apt-transport-https ca-certificates gnupg curl
RUN apk update && apk add --no-cache ca-certificates curl

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/bin .

# Copy the entrypoint script
COPY scripts/docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

# Command to run the executable
ENTRYPOINT ["./${APP_NAME}"]
ENTRYPOINT ["./docker-entrypoint.sh"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build-linux: generate ## Compile the binary for linux
@env GOOS=linux go build -o bin/$(APP_NAME) cmd/$(APP_NAME)/main.go

build-docker: build-linux ## Build docker image
@docker build -t $(APP_NAME) .
@docker build --build-arg APP_NAME=$(APP_NAME) --build-arg VERSION=$(VERSION) -t $(APP_NAME) .

install: build ## compile the binary and copy it to PATH
@sudo cp build/sedge /usr/local/bin
Expand Down
5 changes: 5 additions & 0 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e

# Execute the application with the APP_NAME environment variable
exec /app/"$APP_NAME" "$@"

0 comments on commit bb6f17f

Please sign in to comment.