-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
75 lines (52 loc) · 1.61 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
# First stage:
# Building a frontend.
#
FROM alpine:3.17 AS frontend
# Move to a working directory (/static).
WORKDIR /static
# https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
ENV NODE_OPTIONS=--openssl-legacy-provider
# Update repositories and install npm (with latest nodejs)
RUN apk update && apk add --no-cache nodejs npm
# Log npm and node versions for debugging purposes
RUN node -v && npm -v
# Copy only ./ui folder to the working directory.
COPY ui .
# Run npm scripts (install & build).
RUN npm install && npm run build
#
# Second stage:
# Building a backend.
#
FROM golang:1.18-alpine AS backend
# Move to a working directory (/build).
WORKDIR /build
# Install build dependencies
RUN apk add --no-cache gcc musl-dev
# Copy and download dependencies.
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code to the container.
COPY . .
# Copy frontend static files from /static to the root folder of the backend container.
COPY --from=frontend /static/dist ui/dist
# Build the Go binary
RUN go build -tags=prod -o /build/fitwave ./cmd/fitwave
# Verify the binary is built
RUN ls -l /build/fitwave
#
# Third stage:
# Creating and running a new container with the backend binary.
#
FROM alpine:3.17
# Install necessary runtime dependencies
RUN apk add --no-cache ca-certificates
# Copy binary from /build to the root folder of the container.
COPY --from=backend /build/fitwave /
# Verify the binary is copied correctly
RUN ls -l /fitwave
# Expose the application port
EXPOSE 9000
# Command to run when starting the container.
ENTRYPOINT ["/fitwave"]