-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
86 lines (66 loc) · 2.48 KB
/
Dockerfile
File metadata and controls
86 lines (66 loc) · 2.48 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
76
77
78
79
80
81
82
83
84
85
# Bot Shock Docker Image
#
# This builds a small, secure container for running the bot.
# Uses a two-stage build to keep the final image size down.
# Build arguments for versioning
ARG VERSION=dev
ARG BUILD_DATE=unknown
ARG VCS_REF=unknown
# Stage 1: Build dependencies
FROM python:3.12-slim AS builder
WORKDIR /app
# Install build tools needed for some Python packages
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# Stage 2: Production image
FROM python:3.12-slim
# Re-declare ARGs after FROM (they don't persist across stages)
ARG VERSION
ARG BUILD_DATE
ARG VCS_REF
# OCI Image Format labels
# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.title="Bot Shock" \
org.opencontainers.image.description="Discord bot for managing OpenShock and PiShock devices" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.source="https://github.com/TastelessVoid/Bot-Shock" \
org.opencontainers.image.licenses="MIT"
# Create a non-root user for security
# The bot runs as this user instead of root
RUN groupadd -r botshock && useradd -r -g botshock botshock
WORKDIR /app
# Copy the installed packages from the build stage
COPY --from=builder /root/.local /home/botshock/.local
# Copy the application code
COPY botshock/ ./botshock/
COPY pyproject.toml .
COPY README.md .
# Install the bot package
RUN pip install --no-cache-dir -e .
# Create directories for data and logs
# These should be mounted as volumes to persist data
RUN mkdir -p /app/data /app/logs && \
chown -R botshock:botshock /app && \
chmod 755 /app/data /app/logs
# Switch to the non-root user
USER botshock
# Make sure Python packages are accessible
ENV PATH=/home/botshock/.local/bin:$PATH
# Python settings for better container behavior
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
DATABASE_PATH=/app/data/botshock.db \
LOG_DIR=/app/logs \
BOTSHOCK_VERSION=${VERSION}
# Health check to verify the bot is working
# Docker will restart the container if this fails repeatedly
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import botshock" || exit 1
# Start the bot
CMD ["python", "-m", "botshock"]