-
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.
Add Dockerfile for building and running Go application
- Loading branch information
1 parent
df8b426
commit c003a33
Showing
1 changed file
with
32 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Use the official Go image | ||
FROM golang:1.19 AS build | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy go mod and sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download dependencies | ||
RUN go mod download | ||
|
||
# Copy source code | ||
COPY . . | ||
|
||
# Build the application | ||
RUN go build -o main . | ||
|
||
# Use a lightweight image for deployment | ||
FROM alpine:latest AS runtime | ||
|
||
# Install necessary libraries | ||
RUN apk --no-cache add ca-certificates | ||
|
||
# Copy binary | ||
COPY --from=build /app/main /app/ | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Run the application | ||
CMD [". --download-only"] |