From e465189b8a4fc15c390a463c2b1e4ab41717ed0f Mon Sep 17 00:00:00 2001 From: Robert Jandow <38583713+robertjndw@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:35:03 +0100 Subject: [PATCH] Restructure Dockerfiles to leverage caching (#32) --- HadesAPI/Dockerfile | 15 +++++++++++---- HadesCloneContainer/Dockerfile | 8 ++++++-- HadesScheduler/Dockerfile | 19 +++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/HadesAPI/Dockerfile b/HadesAPI/Dockerfile index f790c85..87a9436 100644 --- a/HadesAPI/Dockerfile +++ b/HadesAPI/Dockerfile @@ -4,22 +4,29 @@ FROM golang:1.21-alpine AS builder # Set the working directory inside the container WORKDIR /app +# Copy go.mod and go.sum files +COPY ./HadesAPI/go.mod ./HadesAPI/go.sum ./HadesAPI/ +COPY ./shared/go.mod ./shared/go.sum ./shared/ +RUN cd HadesAPI && go mod download + # Copy the Go application source code into the container -COPY . . +COPY ./HadesAPI ./HadesAPI +COPY ./shared ./shared # Build the Go application -RUN go build -o hadesCI-api ./HadesAPI +WORKDIR /app/HadesAPI +RUN go build -o hadesCI-api . # Start a new stage for the minimal runtime container FROM alpine:latest -RUN apk update && apk add ca-certificates libc6-compat +RUN apk update && apk add --no-cache ca-certificates libc6-compat # Set the working directory inside the minimal runtime container WORKDIR /app # Copy the built binary from the builder container into the minimal runtime container -COPY --from=builder /app/hadesCI-api . +COPY --from=builder /app/HadesAPI/hadesCI-api . # Ensure the binary is executable RUN chmod +x /app/hadesCI-api diff --git a/HadesCloneContainer/Dockerfile b/HadesCloneContainer/Dockerfile index d2d77e9..b1080fe 100644 --- a/HadesCloneContainer/Dockerfile +++ b/HadesCloneContainer/Dockerfile @@ -4,11 +4,15 @@ FROM golang:1.21-alpine AS builder # Set the working directory inside the container WORKDIR /app +# Copy go.mod and go.sum files +COPY ./HadesCloneContainer/go.mod ./HadesCloneContainer/go.sum ./ +RUN go mod download + # Copy the Go application source code into the container -COPY . . +COPY ./HadesCloneContainer ./ # Build the Go application -RUN go build -o hades-clone ./HadesCloneContainer +RUN go build -o hades-clone . # Start a new stage for the minimal runtime container FROM alpine:latest diff --git a/HadesScheduler/Dockerfile b/HadesScheduler/Dockerfile index 38c7358..8c1b7a3 100644 --- a/HadesScheduler/Dockerfile +++ b/HadesScheduler/Dockerfile @@ -4,25 +4,32 @@ FROM golang:1.21-alpine AS builder # Set the working directory inside the container WORKDIR /app +# Copy go.mod and go.sum files +COPY ./HadesScheduler/go.mod ./HadesScheduler/go.sum ./HadesScheduler/ +COPY ./shared/go.mod ./shared/go.sum ./shared/ +RUN cd HadesScheduler && go mod download + # Copy the Go application source code into the container -COPY . . +COPY ./HadesScheduler ./HadesScheduler +COPY ./shared ./shared # Build the Go application -RUN go build -o hadesCI-scheduler-k8s ./HadesScheduler +WORKDIR /app/HadesScheduler +RUN go build -o hadesCI-scheduler . # Start a new stage for the minimal runtime container FROM alpine:latest -RUN apk update && apk add ca-certificates libc6-compat +RUN apk update && apk add --no-cache ca-certificates libc6-compat # Set the working directory inside the minimal runtime container WORKDIR /app # Copy the built binary from the builder container into the minimal runtime container -COPY --from=builder /app/hadesCI-scheduler-k8s . +COPY --from=builder /app/HadesScheduler/hadesCI-scheduler . # Ensure the binary is executable -RUN chmod +x /app/hadesCI-scheduler-k8s +RUN chmod +x /app/hadesCI-scheduler # Run your Go application -CMD ["/app/hadesCI-scheduler-k8s"] +CMD ["/app/hadesCI-scheduler"]