-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (29 loc) · 884 Bytes
/
Copy pathDockerfile
File metadata and controls
42 lines (29 loc) · 884 Bytes
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
# Build stage
FROM golang:1.26-alpine AS builder
# Accept version as build argument
ARG VERSION=dev
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application with version information
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w -X github.com/j75689/goscraper/cmd/goscraper/cmd.Version=${VERSION}" \
-o goscraper cmd/goscraper/main.go
# Final stage
FROM alpine:latest
# Create a non-root user
RUN adduser -u 10001 -D appuser
WORKDIR /app
# Install certificates for HTTPS requests
RUN apk --no-cache add ca-certificates
# Copy the binary from the builder stage
COPY --from=builder /app/goscraper .
# Change the ownership of the binary to the appuser
RUN chown appuser:appuser /app/goscraper
# Switch to the appuser
USER appuser
# Run the application
ENTRYPOINT ["./goscraper"]