-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainerfile
55 lines (38 loc) · 1.15 KB
/
Containerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Start from the latest golang base image
FROM golang:1.18-alpine as build-env
# Set the Current Working Directory inside the container
WORKDIR /src
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source from the current directory to the Working Directory inside the container
COPY . .
# Build the Go app
RUN go build -o app .
# Final stage
FROM alpine:latest
# Updated the Image
RUN apk update && rm -rf /var/cache/apk/*
# Image info
LABEL \
maintainer="Muhammed Iqbal <iquzart@hotmail.com>" \
description="Go Gin Application"
# Set GIN Mode as Release
ENV GIN_MODE=release
# Container PORT
ENV PORT="8080"
# Create non-root account to run the container
RUN adduser go -h /app -u 1000 -D
# Switch to non-root user
USER go
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy app
COPY --from=build-env /src/app .
# Copy public HTML files
# COPY public public --> Uncommend this when using public files
# Expose port 8080 to the outside world
EXPOSE ${PORT}
# ENTRYPOINT ["./app"]
CMD ./app