-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
68 lines (47 loc) · 1.86 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
# Use an official Golang runtime as a parent image for the backend build
FROM golang:1.21.5-alpine AS backend-builder
# Set the Current Working Directory inside the container
WORKDIR /app/backend
# Copy the backend source code
COPY . .
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Build the Go app
RUN go build -o app .
# Use an official Node.js runtime as a parent image for the frontend build
FROM node:18-alpine AS frontend-builder
# Set the Current Working Directory inside the container
WORKDIR /app/frontend
# Copy the package.json and yarn.lock files
COPY ui/package.json ./
# Install dependencies
RUN npm install
RUN npm install postcss-cli autoprefixer
# Copy the frontend source code
COPY ui/ .
# Build the React app
RUN npm run build
# Use a minimal Docker image for the final stage
FROM alpine:3.14
LABEL org.opencontainers.image.author="[email protected]"
# LABEL org.opencontainers.image.description DESCRIPTION
ENV AUTH_USERNAME=root
ENV AUTH_PASSWORD=rootr00t
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy the backend executable from the backend builder stage
COPY --from=backend-builder /app/backend/app ./backend/
# Copy the frontend build files from the frontend builder stage
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# Install a simple web server for serving the frontend files
RUN apk add --no-cache nginx
# Copy nginx and env configuration
COPY ./deployment/etc/nginx.conf /etc/nginx/nginx.conf
COPY ./deployment/scripts/env.sh /docker-entrypoint.d/env.sh
RUN chmod +x /docker-entrypoint.d/env.sh
# Expose port 2121 for the backend
EXPOSE 2121
# Expose port 80 for the frontend
EXPOSE 80
# Start both the backend and frontend servers
CMD ["/bin/sh", "-c","/docker-entrypoint.d/env.sh && ./backend/app & nginx -g 'daemon off;'"]