Skip to content

Commit

Permalink
Restructure Dockerfiles to leverage caching (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjndw authored Dec 5, 2023
1 parent 114c6f6 commit e465189
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
15 changes: 11 additions & 4 deletions HadesAPI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions HadesCloneContainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions HadesScheduler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit e465189

Please sign in to comment.