-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
57 lines (39 loc) · 1.28 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
# Use the official Go image as the base image
FROM golang:1.22.5-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Install make and other necessary tools, including gcc and musl-dev for CGO
RUN apk add --no-cache make git nodejs npm gcc musl-dev
# Enable CGO
ENV CGO_ENABLED=1
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies
RUN go mod download
# Copy package.json and package-lock.json (if you have them)
COPY package*.json ./
# Install npm dependencies
RUN npm install
# Copy the source code into the container
COPY . .
# Build the application with CGO enabled
RUN make build
# Start a new stage from scratch
FROM alpine:latest
# Install necessary runtime libraries
RUN apk add --no-cache libc6-compat
# Set the working directory inside the container
WORKDIR /root/
# Copy the binary from the builder stage
COPY --from=builder /app/main .
# Copy any other necessary files (e.g., templates, static files)
#COPY --from=builder /app/templates ./templates
#COPY --from=builder /app/static ./static
# Create directories for persistent storage
RUN mkdir -p /public /db
# Expose the port the app runs on
EXPOSE 8080
# Command to run the application
CMD ["./main"]