Skip to content

Commit

Permalink
build: correct dockerfile second stage
Browse files Browse the repository at this point in the history
  • Loading branch information
SomethingSexy committed Nov 19, 2024
1 parent a90ea10 commit f735402
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions internal/chronicle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@ RUN go mod download
RUN go get github.com/SomethingSexy/chronicle/internal/common

# Build the Go application
RUN go build -o chronicle .
RUN go build -o chronicle

# Use a smaller base image for the final image
FROM scratch
# bookworm includes GLIBC
FROM debian:bookworm-slim

# Copy the built binary to the final image
COPY --from=builder /app/chronicle /chronicle
# Set up a non-root user (optional, but recommended for security)
RUN useradd -m appuser

# Set the entrypoint to execute the binary when the container starts
ENTRYPOINT ["/chronicle"]
# Set the working directory
WORKDIR /app

# Copy the binary from the builder stage
COPY --from=builder /app/chronicle .

# Change ownership of the binary (if using a non-root user)
RUN chown appuser:appuser /app/chronicle

# Switch to the non-root user
USER appuser

# Command to run the binary
CMD ["./chronicle"]
2 changes: 1 addition & 1 deletion internal/chronicle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
log.Println("No .env file included")
}

err = chronicleService.NewService()
Expand Down

0 comments on commit f735402

Please sign in to comment.