-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
61 lines (42 loc) · 1.36 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
# Stage 1: Build the Go application
FROM golang:1.22.4 AS builder
ARG VERSION=dev
ENV VERSION=${VERSION}
# Set working directory
WORKDIR /app
# Copy go.mod and go.sum for dependency resolution
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy the rest of the application code
COPY . .
# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o goshort ./cmd/server
# Stage 2: Build the SvelteKit web application
FROM node:18 AS web-builder
# Set working directory
WORKDIR /web
# Copy the SvelteKit project files
COPY web/package.json web/package-lock.json ./
COPY web/ ./
# Install dependencies and build the web app
RUN npm install
RUN npm run build
# Stage 3: Production
FROM alpine:latest AS production
# Install Nginx and Supervisord
RUN apk add --no-cache nginx supervisor
# Set up working directories
WORKDIR /app
# Copy the Go application binary
COPY --from=builder /app/goshort /app/goshort
# Copy the SvelteKit build output to Nginx HTML folder
COPY --from=web-builder /web/build /usr/share/nginx/html
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy supervisord configuration
COPY supervisord.conf /etc/supervisord.conf
# Expose ports
EXPOSE 80 8080
# Command to run both Nginx and the Go application
CMD ["supervisord", "-c", "/etc/supervisord.conf"]