-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
# Stage 1: Build the Go app | ||
FROM golang:1.20-alpine AS builder | ||
# Stage 1: Build the Go binary | ||
FROM golang:1.20-alpine as builder | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy only go.mod and go.sum to cache dependency download step | ||
# Copy go.mod and go.sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download Go dependencies, caching the result | ||
# Download Go dependencies | ||
RUN go mod download | ||
|
||
# Copy the rest of the application code | ||
# Copy the source code into the container | ||
COPY . . | ||
|
||
# Build the application | ||
# Build the Go application | ||
RUN go build -o main . | ||
|
||
# Stage 2: Create a minimal image to run the application | ||
FROM alpine:3.18 | ||
# Stage 2: Create a minimal runtime image | ||
FROM alpine:latest | ||
|
||
WORKDIR /app | ||
# Set the working directory | ||
WORKDIR /root/ | ||
|
||
# Copy the binary from the builder stage | ||
# Copy the Go binary from the builder stage | ||
COPY --from=builder /app/main . | ||
|
||
# Expose the port that the app listens on | ||
# Copy the index.html file | ||
COPY index.html ./ | ||
|
||
# Expose the port the application runs on | ||
EXPOSE 8005 | ||
|
||
# Command to run the app | ||
# Command to run the Go application | ||
CMD ["./main"] |