-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
42 lines (29 loc) · 889 Bytes
/
Dockerfile
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
FROM golang:alpine as builder
# Set the current working directory inside the container
WORKDIR /app
# Copy the go mod and sum files
COPY go.mod go.sum ./
# Download the dependencies
RUN go mod download
RUN go mod verify
# Copy the source code
COPY . .
# Declare the build argument
ARG VERSION=latest
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o app ./src/
# Run the tests in the container
FROM builder AS tester
# Run the tests
RUN go test -v ./...
# Build the final app image
# FROM scratch <-- This is the smallest image possible but cannot connect a shell for debugging
FROM alpine:latest
# May be useful for debugging installs curl utility
# RUN apk add --no-cache curl
# Copy the binary from the builder stage
COPY --from=builder /app/app .
# Expose port for the app
EXPOSE 8080
# Run the app binary
CMD ["./app"]