-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (55 loc) · 1.96 KB
/
Dockerfile
File metadata and controls
75 lines (55 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ARG YAOCC_BASE_IMAGE=alpine:latest
ARG YAOCC_DOCKER_APK_PACKAGES=""
ARG YAOCC_DOCKER_RUN_COMMANDS=""
# Build Stage
FROM golang:alpine AS builder
# Version info injected at build time
ARG YAOCC_VERSION=dev
ARG YAOCC_COMMIT=unknown
ARG YAOCC_BUILD_DATE=unknown
# Install build dependencies
RUN apk add --no-cache git
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build binaries with version info
RUN LDFLAGS="-X github.com/dev-dhg/yaocc/pkg/version.Version=${YAOCC_VERSION} \
-X github.com/dev-dhg/yaocc/pkg/version.Commit=${YAOCC_COMMIT} \
-X github.com/dev-dhg/yaocc/pkg/version.BuildDate=${YAOCC_BUILD_DATE}" && \
go build -ldflags "$LDFLAGS" -o /app/build/yaocc-server ./cmd/yaocc-server && \
go build -ldflags "$LDFLAGS" -o /app/build/yaocc ./cmd/yaocc
# Final Stage
FROM ${YAOCC_BASE_IMAGE}
WORKDIR /app
# Install runtime dependencies if needed (e.g., ca-certificates for HTTPS)
RUN apk add --no-cache ca-certificates tzdata bash
RUN if [ -n "$YAOCC_DOCKER_APK_PACKAGES" ]; then \
apk add --no-cache $YAOCC_DOCKER_APK_PACKAGES; \
fi
RUN if [ -n "$YAOCC_DOCKER_RUN_COMMANDS" ]; then \
/bin/bash -c "$YAOCC_DOCKER_RUN_COMMANDS"; \
fi
# Copy binaries from builder
COPY --from=builder /app/build/yaocc-server /usr/local/bin/yaocc-server
COPY --from=builder /app/build/yaocc /usr/local/bin/yaocc
# Set environment variable defaults
ENV YAOCC_CONFIG_DIR=/app/data
ENV SERVER_TOKEN=
ENV TELEGRAM_BOT_TOKEN=
ENV LOG=false
ENV LOG_FILE=agent.log
# Expose server port
EXPOSE 8080
# Create data directory
RUN mkdir -p /app/data
ARG YAOCC_USER=root
# Set ownership of the application directory
RUN chown -R $YAOCC_USER:$YAOCC_USER /app
# Switch to specified user
USER $YAOCC_USER
# Default command with conditional logic for logging
CMD sh -c 'if [ "$LOG" = "true" ]; then exec yaocc-server -level verbose -file "$LOG_FILE"; else exec yaocc-server; fi'