1- # Use an official Node.js runtime as a base image
2- FROM node:18
3-
4- # Set the working directory in the container
5- WORKDIR /usr/src/microsoft-rewards-script
6-
7- # Install necessary dependencies for Playwright and cron
8- RUN apt-get update && apt-get install -y \
9- jq \
10- cron \
11- gettext-base \
12- xvfb \
13- libgbm-dev \
14- libnss3 \
15- libasound2 \
16- libxss1 \
17- libatk-bridge2.0-0 \
18- libgtk-3-0 \
19- tzdata \
20- wget \
21- && rm -rf /var/lib/apt/lists/*
22-
23- # Copy all files to the working directory
24- COPY . .
25-
26- # Install dependencies, set permissions, and build the script
27- RUN npm install && \
28- chmod -R 755 /usr/src/microsoft-rewards-script/node_modules && \
29- npm run pre-build && \
30- npm run build
31-
32- # Copy cron file to cron directory
33- COPY src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
34-
35- # Create the log file to be able to run tail
36- RUN touch /var/log/cron.log
37-
38- # Define the command to run your application with cron optionally
39- CMD ["sh" , "-c" , "echo \" $TZ\" > /etc/timezone && \
40- ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
41- dpkg-reconfigure -f noninteractive tzdata && \
42- envsubst < /etc/cron.d/microsoft-rewards-cron.template > /etc/cron.d/microsoft-rewards-cron && \
43- chmod 0644 /etc/cron.d/microsoft-rewards-cron && \
44- crontab /etc/cron.d/microsoft-rewards-cron && \
45- cron -f & \
46- ([ \" $RUN_ON_START\" = \" true\" ] && npm start) && \
47- tail -f /var/log/cron.log" ]
1+ # ##############################################################################
2+ # Stage 1: Builder
3+ # ##############################################################################
4+ FROM node:22-slim AS builder
5+
6+ WORKDIR /usr/src/microsoft-rewards-script
7+
8+ ENV PLAYWRIGHT_BROWSERS_PATH=0
9+
10+ # Copy package files
11+ COPY package.json package-lock.json tsconfig.json ./
12+
13+ # Install all dependencies required to build the script
14+ RUN npm ci --ignore-scripts
15+
16+ # Copy source and build
17+ COPY . .
18+ RUN npm run build
19+
20+ # Remove build dependencies, and reinstall only runtime dependencies
21+ RUN rm -rf node_modules \
22+ && npm ci --omit=dev --ignore-scripts \
23+ && npm cache clean --force
24+
25+ # Install Chromium Headless Shell, and cleanup
26+ RUN npx playwright install --with-deps --only-shell chromium \
27+ && rm -rf /root/.cache /tmp/* /var/tmp/*
28+
29+ # ##############################################################################
30+ # Stage 2: Runtime
31+ # ##############################################################################
32+ FROM node:22-slim AS runtime
33+
34+ WORKDIR /usr/src/microsoft-rewards-script
35+
36+ # Set production environment variables
37+ ENV NODE_ENV=production \
38+ TZ=UTC \
39+ PLAYWRIGHT_BROWSERS_PATH=0 \
40+ FORCE_HEADLESS=1
41+
42+ # Install minimal system libraries required for Chromium headless to run
43+ RUN apt-get update && apt-get install -y --no-install-recommends \
44+ cron \
45+ gettext-base \
46+ tzdata \
47+ ca-certificates \
48+ libglib2.0-0 \
49+ libdbus-1-3 \
50+ libexpat1 \
51+ libfontconfig1 \
52+ libgtk-3-0 \
53+ libnspr4 \
54+ libnss3 \
55+ libasound2 \
56+ libflac12 \
57+ libatk1.0-0 \
58+ libatspi2.0-0 \
59+ libdrm2 \
60+ libgbm1 \
61+ libdav1d6 \
62+ libx11-6 \
63+ libx11-xcb1 \
64+ libxcomposite1 \
65+ libxcursor1 \
66+ libxdamage1 \
67+ libxext6 \
68+ libxfixes3 \
69+ libxi6 \
70+ libxrandr2 \
71+ libxrender1 \
72+ libxss1 \
73+ libxtst6 \
74+ libdouble-conversion3 \
75+ && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
76+
77+ # Copy compiled application and dependencies from builder stage
78+ COPY --from=builder /usr/src/microsoft-rewards-script/dist ./dist
79+ COPY --from=builder /usr/src/microsoft-rewards-script/package*.json ./
80+ COPY --from=builder /usr/src/microsoft-rewards-script/node_modules ./node_modules
81+
82+ # Copy runtime scripts with proper permissions from the start
83+ COPY --chmod=755 src/run_daily.sh ./src/run_daily.sh
84+ COPY --chmod=644 src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
85+ COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
86+
87+ # Entrypoint handles TZ, initial run toggle, cron templating & launch
88+ ENTRYPOINT ["/usr/local/bin/entrypoint.sh" ]
89+ CMD ["sh" , "-c" , "echo 'Container started; cron is running.'" ]
0 commit comments