mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-10 18:36:17 +00:00
Port Dockerfile optimizations from v2 to v1.53, no functionality changes. (#386)
* port v2 optimizations to v1.5 Updated dockerfile with v2 optimizations. Ported Login.ts no dialogs fix. * Update entrypoint.sh Fix playwright path in entrypoint as well
This commit is contained in:
committed by
GitHub
parent
14492b27cb
commit
86f65b448d
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,7 +1,6 @@
|
|||||||
sessions/
|
sessions/
|
||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
package-lock.json
|
|
||||||
accounts.json
|
accounts.json
|
||||||
notes
|
notes
|
||||||
accounts.dev.json
|
accounts.dev.json
|
||||||
|
|||||||
101
Dockerfile
101
Dockerfile
@@ -1,68 +1,89 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# Stage 1: Builder (compile TypeScript)
|
# Stage 1: Builder
|
||||||
###############################################################################
|
###############################################################################
|
||||||
FROM node:18-slim AS builder
|
FROM node:22-slim AS builder
|
||||||
|
|
||||||
WORKDIR /usr/src/microsoft-rewards-script
|
WORKDIR /usr/src/microsoft-rewards-script
|
||||||
|
|
||||||
# Install minimal tooling if needed
|
ENV PLAYWRIGHT_BROWSERS_PATH=0
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends ca-certificates \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy package manifests
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package.json package-lock.json tsconfig.json ./
|
||||||
|
|
||||||
# Conditional install: npm ci if lockfile exists, else npm install
|
# Install all dependencies required to build the script
|
||||||
RUN if [ -f package-lock.json ]; then \
|
RUN npm ci --ignore-scripts
|
||||||
npm ci; \
|
|
||||||
else \
|
|
||||||
npm install; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy source code
|
# Copy source and build
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build TypeScript
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# Remove build dependencies, and reinstall only runtime dependencies
|
||||||
|
RUN rm -rf node_modules \
|
||||||
|
&& npm ci --omit=dev --ignore-scripts \
|
||||||
|
&& npm cache clean --force
|
||||||
|
|
||||||
|
# Install Chromium Headless Shell, and cleanup
|
||||||
|
RUN npx playwright install --with-deps --only-shell chromium \
|
||||||
|
&& rm -rf /root/.cache /tmp/* /var/tmp/*
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Stage 2: Runtime (Playwright image)
|
# Stage 2: Runtime
|
||||||
###############################################################################
|
###############################################################################
|
||||||
FROM mcr.microsoft.com/playwright:v1.52.0-jammy
|
FROM node:22-slim AS runtime
|
||||||
|
|
||||||
WORKDIR /usr/src/microsoft-rewards-script
|
WORKDIR /usr/src/microsoft-rewards-script
|
||||||
|
|
||||||
# Install cron, gettext-base (for envsubst), tzdata noninteractively
|
# Set production environment variables
|
||||||
RUN apt-get update \
|
ENV NODE_ENV=production \
|
||||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
TZ=UTC \
|
||||||
cron gettext-base tzdata \
|
PLAYWRIGHT_BROWSERS_PATH=0 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
FORCE_HEADLESS=1
|
||||||
|
|
||||||
# Ensure Playwright uses preinstalled browsers
|
# Install minimal system libraries required for Chromium headless to run
|
||||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
cron \
|
||||||
|
gettext-base \
|
||||||
|
tzdata \
|
||||||
|
ca-certificates \
|
||||||
|
libglib2.0-0 \
|
||||||
|
libdbus-1-3 \
|
||||||
|
libexpat1 \
|
||||||
|
libfontconfig1 \
|
||||||
|
libgtk-3-0 \
|
||||||
|
libnspr4 \
|
||||||
|
libnss3 \
|
||||||
|
libasound2 \
|
||||||
|
libflac12 \
|
||||||
|
libatk1.0-0 \
|
||||||
|
libatspi2.0-0 \
|
||||||
|
libdrm2 \
|
||||||
|
libgbm1 \
|
||||||
|
libdav1d6 \
|
||||||
|
libx11-6 \
|
||||||
|
libx11-xcb1 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxcursor1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxext6 \
|
||||||
|
libxfixes3 \
|
||||||
|
libxi6 \
|
||||||
|
libxrandr2 \
|
||||||
|
libxrender1 \
|
||||||
|
libxss1 \
|
||||||
|
libxtst6 \
|
||||||
|
libdouble-conversion3 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
|
||||||
|
|
||||||
# Copy package files first for better caching
|
# Copy compiled application and dependencies from builder stage
|
||||||
COPY --from=builder /usr/src/microsoft-rewards-script/package*.json ./
|
|
||||||
|
|
||||||
# Install only production dependencies, with fallback
|
|
||||||
RUN if [ -f package-lock.json ]; then \
|
|
||||||
npm ci --omit=dev --ignore-scripts; \
|
|
||||||
else \
|
|
||||||
npm install --production --ignore-scripts; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy built application
|
|
||||||
COPY --from=builder /usr/src/microsoft-rewards-script/dist ./dist
|
COPY --from=builder /usr/src/microsoft-rewards-script/dist ./dist
|
||||||
|
COPY --from=builder /usr/src/microsoft-rewards-script/package*.json ./
|
||||||
|
COPY --from=builder /usr/src/microsoft-rewards-script/node_modules ./node_modules
|
||||||
|
|
||||||
# Copy runtime scripts with proper permissions from the start
|
# Copy runtime scripts with proper permissions from the start
|
||||||
COPY --chmod=755 src/run_daily.sh ./src/run_daily.sh
|
COPY --chmod=755 src/run_daily.sh ./src/run_daily.sh
|
||||||
COPY --chmod=644 src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
|
COPY --chmod=644 src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
|
||||||
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
# Default TZ (overridden by user via environment)
|
|
||||||
ENV TZ=UTC
|
|
||||||
|
|
||||||
# Entrypoint handles TZ, initial run toggle, cron templating & launch
|
# Entrypoint handles TZ, initial run toggle, cron templating & launch
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
CMD ["sh", "-c", "echo 'Container started; cron is running.'"]
|
CMD ["sh", "-c", "echo 'Container started; cron is running.'"]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Ensure Playwright uses preinstalled browsers
|
# Ensure Playwright uses preinstalled browsers
|
||||||
export PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
export PLAYWRIGHT_BROWSERS_PATH=0
|
||||||
|
|
||||||
# 1. Timezone: default to UTC if not provided
|
# 1. Timezone: default to UTC if not provided
|
||||||
: "${TZ:=UTC}"
|
: "${TZ:=UTC}"
|
||||||
|
|||||||
3126
package-lock.json
generated
Normal file
3126
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -347,6 +347,10 @@ export class Login {
|
|||||||
const targetHostname = 'rewards.bing.com'
|
const targetHostname = 'rewards.bing.com'
|
||||||
const targetPathname = '/'
|
const targetPathname = '/'
|
||||||
|
|
||||||
|
const start = Date.now()
|
||||||
|
const maxWaitMs = Number(process.env.LOGIN_MAX_WAIT_MS || 180000) // default 3 minutes
|
||||||
|
let guidanceLogged = false
|
||||||
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
await this.dismissLoginMessages(page)
|
await this.dismissLoginMessages(page)
|
||||||
@@ -354,6 +358,18 @@ export class Login {
|
|||||||
if (currentURL.hostname === targetHostname && currentURL.pathname === targetPathname) {
|
if (currentURL.hostname === targetHostname && currentURL.pathname === targetPathname) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we keep looping without prompts for too long, advise and fail fast
|
||||||
|
const elapsed = Date.now() - start
|
||||||
|
if (elapsed > maxWaitMs) {
|
||||||
|
if (!guidanceLogged) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'LOGIN-GUIDE', 'Login taking too long without prompts.')
|
||||||
|
this.bot.log(this.bot.isMobile, 'LOGIN-GUIDE', 'Tip: Enable passwordless sign-in (Microsoft Authenticator "number match") or add a TOTP secret in accounts.json to auto-fill OTP.')
|
||||||
|
this.bot.log(this.bot.isMobile, 'LOGIN-GUIDE', 'You can also set LOGIN_MAX_WAIT_MS to increase this timeout if needed.')
|
||||||
|
guidanceLogged = true
|
||||||
|
}
|
||||||
|
throw this.bot.log(this.bot.isMobile, 'LOGIN-TIMEOUT', `Login timed out after ${Math.round(elapsed/1000)}s without completing`, 'error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for login to complete
|
// Wait for login to complete
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
export PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
export PLAYWRIGHT_BROWSERS_PATH=0
|
||||||
export TZ="${TZ:-UTC}"
|
export TZ="${TZ:-UTC}"
|
||||||
|
|
||||||
cd /usr/src/microsoft-rewards-script
|
cd /usr/src/microsoft-rewards-script
|
||||||
|
|||||||
Reference in New Issue
Block a user