|
1 |
| -FROM golang:1.22.4 as builder |
| 1 | +# Stage 1: Builder |
| 2 | +FROM golang:1.22.4 AS builder |
| 3 | + |
| 4 | +# Build arguments |
2 | 5 | ARG COMMIT_SHA
|
3 |
| -RUN echo "commit sha: ${COMMIT_SHA}" |
| 6 | +RUN echo "Commit SHA: ${COMMIT_SHA}" |
4 | 7 |
|
5 | 8 | # Set the working directory
|
6 | 9 | WORKDIR $GOPATH/src/github.com/diggerhq/digger
|
7 | 10 |
|
8 |
| -# Copy all required source, blacklist files that are not required through `.dockerignore` |
9 |
| -COPY . . |
10 |
| - |
11 |
| -# Get the vendor library |
12 |
| -RUN go version |
13 |
| - |
14 |
| -# RUN vgo install |
| 11 | +# Cache Go dependencies by copying only the go.mod and go.sum files |
| 12 | +COPY go.mod go.sum ./ |
| 13 | +RUN go mod download |
15 | 14 |
|
16 |
| -# https://github.com/ethereum/go-ethereum/issues/2738 |
17 |
| -# Build static binary "-getmode=vendor" does not work with go-ethereum |
| 15 | +# Copy the rest of the application code |
| 16 | +COPY . . |
18 | 17 |
|
| 18 | +# Build the static binary |
19 | 19 | RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o next_exe ./next/
|
20 | 20 |
|
21 |
| -# Multi-stage build will just copy the binary to an alpine image. |
22 |
| -FROM ubuntu:24.04 as runner |
23 |
| -ENV ATLAS_VERSION v0.28.0 |
| 21 | +# Stage 2: Runner |
| 22 | +FROM ubuntu:24.04-slim AS runner |
| 23 | +ENV ATLAS_VERSION v0.16.0 |
24 | 24 | ARG COMMIT_SHA
|
25 | 25 | WORKDIR /app
|
26 | 26 |
|
27 |
| -RUN apt-get update && apt-get install -y ca-certificates curl && apt-get install -y git && apt-get clean all |
28 |
| -RUN update-ca-certificates |
| 27 | +# Install necessary packages and clean up in a single step |
| 28 | +RUN apt-get update && \ |
| 29 | + apt-get install -y --no-install-recommends \ |
| 30 | + ca-certificates curl git && \ |
| 31 | + rm -rf /var/lib/apt/lists/* && \ |
| 32 | + update-ca-certificates |
29 | 33 |
|
30 |
| -RUN echo "commit sha: ${COMMIT_SHA}" |
| 34 | +# Print commit SHA |
| 35 | +RUN echo "Commit SHA: ${COMMIT_SHA}" |
31 | 36 |
|
32 |
| -# install atlas |
| 37 | +# Install Atlas |
33 | 38 | RUN curl -sSf https://atlasgo.sh | sh
|
34 | 39 |
|
35 |
| - |
36 |
| - |
37 |
| -# Set gin to production |
38 | 40 | #ENV GIN_MODE=release
|
39 | 41 |
|
40 | 42 | # Expose the running port
|
41 | 43 | EXPOSE 3000
|
42 | 44 |
|
43 |
| -# Copy the binary to the corresponding folder |
| 45 | +# Copy binary and entrypoint |
44 | 46 | COPY --from=builder /go/src/github.com/diggerhq/digger/next_exe /app/next
|
45 | 47 | COPY --from=builder /go/src/github.com/diggerhq/digger/next/scripts/entrypoint.sh /app/entrypoint.sh
|
46 | 48 | ADD next/templates ./templates
|
47 | 49 |
|
48 |
| -# Run the binary |
| 50 | +# Set entrypoint and permissions |
| 51 | +RUN chmod +x /app/entrypoint.sh |
49 | 52 | ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]
|
| 53 | + |
0 commit comments