-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (39 loc) · 1.11 KB
/
Dockerfile
File metadata and controls
57 lines (39 loc) · 1.11 KB
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
# Build stage
FROM golang:1.23-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache gcc musl-dev sqlite-dev
# Set required build flags for SQLite
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies
RUN go mod download
# Copy the source code
COPY . .
# Run swagger
RUN go install github.com/swaggo/swag/cmd/swag@latest && swag init -g main.go
# Build the application
RUN CGO_ENABLED=1 GOOS=linux go build -o main .
# Final stage
FROM alpine:latest
WORKDIR /app
# Install ca-certificates for HTTPS requests
RUN apk --no-cache add ca-certificates
# Create directory for database
RUN mkdir -p /data
# Copy the binary from builder
COPY --from=builder /app/main .
# Copy the config file
COPY --from=builder /app/.env.example .env
# Expose port
EXPOSE 8080
# Set environment variable for database path
ENV DB_PATH=/data/app.db
# Create a non-root user
RUN adduser -D -g '' appuser
RUN chown -R appuser:appuser /app /data
# Switch to non-root user
USER appuser
# Command to run the executable
CMD ["./main"]