|
1 | | -FROM debian:unstable-20250811-slim AS base |
| 1 | +# Use a more specific and stable base image |
| 2 | +FROM debian:bookworm-slim AS base |
2 | 3 |
|
| 4 | +# Add metadata labels |
| 5 | +LABEL maintainer="AllThingsLinux IRC Infrastructure" \ |
| 6 | + description="Optimized IRC services with UnrealIRCd and Atheme" \ |
| 7 | + version="1.0.0" \ |
| 8 | + org.opencontainers.image.source="https://github.com/allthingslinux/irc.atl.chat" |
3 | 9 |
|
| 10 | +# Set environment variables for non-interactive package installation |
4 | 11 | ENV DEBIAN_FRONTEND=noninteractive \ |
5 | | - DEBCONF_NONINTERACTIVE_SEEN=true |
| 12 | + DEBCONF_NONINTERACTIVE_SEEN=true \ |
| 13 | + # Set build arguments as environment variables for better caching |
| 14 | + UNREALIRCD_VERSION="6.1.10" \ |
| 15 | + ATHEME_VERSION="7.2.12" |
6 | 16 |
|
| 17 | +# Install system dependencies in a single layer with cleanup |
7 | 18 | RUN apt-get update && \ |
8 | 19 | apt-get upgrade -y && \ |
9 | | - apt-get install -y \ |
10 | | - build-essential \ |
11 | | - gdb \ |
12 | | - gettext \ |
13 | | - libargon2-dev \ |
14 | | - libc-ares-dev \ |
15 | | - libcurl4-openssl-dev \ |
16 | | - libpcre2-dev \ |
17 | | - libssl-dev \ |
18 | | - libsodium-dev \ |
19 | | - pkg-config \ |
20 | | - wget && \ |
| 20 | + apt-get install -y --no-install-recommends \ |
| 21 | + build-essential=12.9 \ |
| 22 | + gdb=13.1-3 \ |
| 23 | + gettext=0.21-12 \ |
| 24 | + libargon2-dev=0~20171227-0.3+deb12u1 \ |
| 25 | + libc-ares-dev=1.18.1-3 \ |
| 26 | + libcurl4-openssl-dev=7.88.1-10+deb12u12 \ |
| 27 | + libpcre2-dev=10.42-1 \ |
| 28 | + libssl-dev=3.0.17-1~deb12u2 \ |
| 29 | + libsodium-dev=1.0.18-1 \ |
| 30 | + pkg-config=1.8.1-1 \ |
| 31 | + wget=1.21.3-1+deb12u1 \ |
| 32 | + ca-certificates=20230311+deb12u1 \ |
| 33 | + git=1:2.39.2-1.1 \ |
| 34 | + # Additional Atheme dependencies for better functionality |
| 35 | + libidn2-dev=2.3.3-1+b1 \ |
| 36 | + nettle-dev=3.8.1-2 \ |
| 37 | + libqrencode-dev=4.1.1-1 \ |
| 38 | + # Development tools for better builds |
| 39 | + autoconf=2.71-3 \ |
| 40 | + automake=1:1.16.5-1.3 \ |
| 41 | + libtool=2.4.7-7~deb12u1 && \ |
21 | 42 | apt-get clean && \ |
22 | | - rm -rf /var/cache/apt/archives/* && \ |
23 | | - rm -rf /var/lib/apt/lists/* |
| 43 | + rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* |
24 | 44 |
|
| 45 | +# Builder stage for compiling UnrealIRCd and Atheme |
25 | 46 | FROM base AS builder |
26 | 47 |
|
| 48 | +# Create non-root user for building |
27 | 49 | RUN groupadd --system --gid 1001 builder && \ |
28 | 50 | useradd --create-home --system --uid 1001 --gid builder builder |
29 | 51 |
|
30 | | -ARG UNREALIRCD_VERSION="6.1.10" |
31 | | -ARG ATHEME_VERSION="7.2.12" |
32 | | - |
33 | | -ENV UNREALIRCD_BASENAME="unrealircd-${UNREALIRCD_VERSION}" |
34 | | -ENV ATHEME_BASENAME="atheme-services-v${ATHEME_VERSION}" |
35 | | - |
| 52 | +# Set build arguments |
| 53 | +ARG UNREALIRCD_VERSION |
| 54 | +ARG ATHEME_VERSION |
| 55 | + |
| 56 | +# Set environment variables for the build |
| 57 | +ENV UNREALIRCD_BASENAME="unrealircd-${UNREALIRCD_VERSION}" \ |
| 58 | + ATHEME_BASENAME="atheme-services-v${ATHEME_VERSION}" \ |
| 59 | + # Compiler optimization flags |
| 60 | + CFLAGS="-O2 -march=native -mtune=native -fstack-protector-strong -D_FORTIFY_SOURCE=2" \ |
| 61 | + CXXFLAGS="-O2 -march=native -mtune=native -fstack-protector-strong -D_FORTIFY_SOURCE=2" \ |
| 62 | + LDFLAGS="-Wl,-z,relro,-z,now" \ |
| 63 | + # Build optimization |
| 64 | + MAKEFLAGS="-j$(nproc)" \ |
| 65 | + # Atheme-specific build flags |
| 66 | + ATHEME_CFLAGS="-O2 -march=native -mtune=native" \ |
| 67 | + ATHEME_LDFLAGS="-Wl,-z,relro,-z,now" |
| 68 | + |
| 69 | +# Create necessary directories |
36 | 70 | RUN mkdir -p /usr/src/unrealircd /usr/src/atheme /usr/local/unrealircd /usr/local/atheme |
| 71 | + |
| 72 | +# Download and extract UnrealIRCd (with better error handling) |
37 | 73 | WORKDIR /usr/src/unrealircd |
38 | | -RUN wget --quiet https://www.unrealircd.org/downloads/${UNREALIRCD_BASENAME}.tar.gz && \ |
39 | | - tar xvf "$UNREALIRCD_BASENAME".tar.gz && \ |
| 74 | +RUN wget --quiet --show-progress --timeout=30 --tries=3 \ |
| 75 | + "https://www.unrealircd.org/downloads/${UNREALIRCD_BASENAME}.tar.gz" && \ |
| 76 | + tar xf "${UNREALIRCD_BASENAME}.tar.gz" && \ |
| 77 | + rm "${UNREALIRCD_BASENAME}.tar.gz" && \ |
40 | 78 | chown -R builder:builder /usr/src/unrealircd /usr/local/unrealircd |
41 | 79 |
|
| 80 | +# Download and extract Atheme (with better error handling) |
42 | 81 | WORKDIR /usr/src/atheme |
43 | | -RUN wget --quiet https://github.com/atheme/atheme/releases/download/v${ATHEME_VERSION}/${ATHEME_BASENAME}.tar.xz && \ |
44 | | - tar xvf "$ATHEME_BASENAME".tar.xz && \ |
| 82 | +RUN wget --quiet --show-progress --timeout=30 --tries=3 \ |
| 83 | + "https://github.com/atheme/atheme/releases/download/v${ATHEME_VERSION}/${ATHEME_BASENAME}.tar.xz" && \ |
| 84 | + tar xf "${ATHEME_BASENAME}.tar.xz" && \ |
| 85 | + rm "${ATHEME_BASENAME}.tar.xz" && \ |
45 | 86 | chown -R builder:builder /usr/src/atheme /usr/local/atheme |
46 | 87 |
|
| 88 | +# Ensure proper ownership |
47 | 89 | RUN chown builder:builder /usr/local/unrealircd |
48 | 90 |
|
| 91 | +# Switch to builder user |
49 | 92 | USER builder:builder |
50 | 93 |
|
51 | | -WORKDIR /usr/src/unrealircd/"$UNREALIRCD_BASENAME" |
52 | | -COPY ./unrealircd/config.settings . |
| 94 | +# Build UnrealIRCd |
| 95 | +WORKDIR "/usr/src/unrealircd/${UNREALIRCD_BASENAME}" |
| 96 | +COPY --chown=builder:builder ./unrealircd/config.settings . |
53 | 97 | RUN ./Config -quick && \ |
54 | | - make && \ |
| 98 | + make -j"$(nproc)" && \ |
55 | 99 | make install && \ |
56 | 100 | make clean |
57 | 101 |
|
58 | | -WORKDIR /usr/src/atheme/"$ATHEME_BASENAME" |
59 | | -RUN ./configure --prefix=/usr/local/atheme && \ |
60 | | - make && \ |
| 102 | +# Set up UnrealIRCd contrib modules repository |
| 103 | +WORKDIR /usr/local/unrealircd |
| 104 | +RUN git clone --depth 1 https://github.com/unrealircd/unrealircd-contrib.git contrib && \ |
| 105 | + chown -R builder:builder contrib |
| 106 | + |
| 107 | +# Build Atheme with optimized configuration |
| 108 | +WORKDIR "/usr/src/atheme/${ATHEME_BASENAME}" |
| 109 | +RUN ./configure \ |
| 110 | + --prefix=/usr/local/atheme \ |
| 111 | + --enable-compiler-sanitizers \ |
| 112 | + --disable-heap-allocator \ |
| 113 | + --disable-linker-defs \ |
| 114 | + --enable-fhs-paths \ |
| 115 | + --enable-large-net \ |
| 116 | + --enable-contrib \ |
| 117 | + --enable-nls \ |
| 118 | + --enable-reproducible-builds \ |
| 119 | + --with-perl \ |
| 120 | + --with-pkg-config && \ |
| 121 | + make -j"$(nproc)" && \ |
61 | 122 | make install && \ |
62 | 123 | make clean |
63 | 124 |
|
64 | | -FROM base AS dev |
| 125 | +# Final runtime stage |
| 126 | +FROM base AS runtime |
65 | 127 |
|
| 128 | +# Create runtime user |
66 | 129 | RUN groupadd --system --gid 1001 ircd && \ |
67 | 130 | useradd --system --uid 1001 --gid ircd ircd |
68 | 131 |
|
69 | | -RUN mkdir -p /usr/local |
| 132 | +# Create necessary directories |
| 133 | +RUN mkdir -p /usr/local /var/log /var/run |
| 134 | + |
| 135 | +# Copy compiled binaries from builder stage |
70 | 136 | COPY --from=builder --chown=ircd:ircd /usr/local/atheme /usr/local/atheme |
71 | 137 | COPY --from=builder --chown=ircd:ircd /usr/local/unrealircd /usr/local/unrealircd |
| 138 | + |
| 139 | +# Copy startup script |
| 140 | +COPY --chown=ircd:ircd scripts/start-services.sh /usr/local/bin/start-services |
| 141 | + |
| 142 | +# Copy module management scripts |
| 143 | +COPY --chown=ircd:ircd scripts/manage-modules.sh /usr/local/bin/manage-modules |
| 144 | +COPY --chown=ircd:ircd scripts/module-config.sh /usr/local/bin/module-config |
| 145 | + |
| 146 | +# Set proper permissions and create necessary symlinks |
| 147 | +RUN chmod 755 /usr/local/atheme/bin/* /usr/local/unrealircd/bin/* && \ |
| 148 | + chown -R ircd:ircd /var/log /var/run && \ |
| 149 | + # Create symlinks for easier access |
| 150 | + ln -sf /usr/local/atheme/bin/atheme-services /usr/local/bin/atheme-services && \ |
| 151 | + ln -sf /usr/local/unrealircd/bin/unrealircd /usr/local/bin/unrealircd && \ |
| 152 | + # Ensure proper ownership of configuration directories |
| 153 | + mkdir -p /usr/local/atheme/etc /usr/local/unrealircd/conf && \ |
| 154 | + chown -R ircd:ircd /usr/local/atheme/etc /usr/local/unrealircd/conf && \ |
| 155 | + # Create Atheme database directory |
| 156 | + mkdir -p /usr/local/atheme/var && \ |
| 157 | + chown -R ircd:ircd /usr/local/atheme/var |
| 158 | + |
| 159 | +# Switch to runtime user |
| 160 | +USER ircd:ircd |
| 161 | + |
| 162 | +# Set working directory |
| 163 | +WORKDIR /usr/local/unrealircd |
| 164 | + |
| 165 | +# Expose default IRC ports |
| 166 | +EXPOSE 6667 6697 |
| 167 | + |
| 168 | +# Health check for both services |
| 169 | +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ |
| 170 | + CMD pgrep -f unrealircd && pgrep -f atheme-services || exit 1 |
| 171 | + |
| 172 | +# Add Atheme-specific environment variables |
| 173 | +ENV ATHEME_CONF="/usr/local/atheme/etc/atheme.conf" \ |
| 174 | + ATHEME_DATA="/usr/local/atheme/var" \ |
| 175 | + ATHEME_MODULES="/usr/local/atheme/modules" \ |
| 176 | + # UnrealIRCd module management |
| 177 | + UNREALIRCD_CONTRIB="/usr/local/unrealircd/contrib" \ |
| 178 | + UNREALIRCD_MODULES="/usr/local/unrealircd/modules" |
| 179 | + |
| 180 | +# Default command - use our startup script |
| 181 | +CMD ["/usr/local/bin/start-services", "start"] |
0 commit comments