Dockerfile refactoring (#167)

* Docker updates and maintenance

- Update run_daily.sh to use compose.yaml env var overrides if present on scheduled jobs, not just first run. Defaults back to config.json values if no override specified.
- update sample compose.yaml with volume mapping to keep config.json, accounts.json, and sessions folder persistent on local machine (e.g., to keep data persistent through updates).

* Refactored dockerfile

Combining various steps to reduce layers. Should improve build time and image size.
This commit is contained in:
mgrimace
2024-10-17 15:46:54 -04:00
committed by GitHub
parent 7151f2351a
commit 8b489d50f7

View File

@@ -4,14 +4,11 @@ FROM node:18
# Set the working directory in the container # Set the working directory in the container
WORKDIR /usr/src/microsoft-rewards-script WORKDIR /usr/src/microsoft-rewards-script
# Install jq, cron, and gettext-base # Install jq, cron, gettext-base, Playwright dependencies
RUN apt-get update && apt-get install -y jq cron gettext-base RUN apt-get update && apt-get install -y \
jq \
# Copy all files to the working directory cron \
COPY . . gettext-base \
# Install dependencies including Playwright
RUN apt-get install -y \
xvfb \ xvfb \
libgbm-dev \ libgbm-dev \
libnss3 \ libnss3 \
@@ -19,16 +16,20 @@ RUN apt-get install -y \
libxss1 \ libxss1 \
libatk-bridge2.0-0 \ libatk-bridge2.0-0 \
libgtk-3-0 \ libgtk-3-0 \
tzdata \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy all files to the working directory
COPY . .
# Install application dependencies # Install application dependencies
RUN npm install RUN npm install && \
# Ensure correct permissions for node_modules
# Ensure correct permissions for node_modules chmod -R 755 /usr/src/microsoft-rewards-script/node_modules && \
RUN chmod -R 755 /usr/src/microsoft-rewards-script/node_modules # Install Playwright Chromium directly from local node_modules
./node_modules/.bin/playwright install chromium && \
# Install Playwright Chromium directly from local node_modules # Ensure correct permissions for the working directory
RUN ./node_modules/.bin/playwright install chromium chmod -R 755 /usr/src/microsoft-rewards-script
# Build the script # Build the script
RUN npm run build RUN npm run build
@@ -39,8 +40,11 @@ COPY src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
# Create the log file to be able to run tail # Create the log file to be able to run tail
RUN touch /var/log/cron.log RUN touch /var/log/cron.log
# Ensure correct permissions for the working directory
RUN chmod -R 755 /usr/src/microsoft-rewards-script
# Define the command to run your application with cron optionally # Define the command to run your application with cron optionally
CMD sh -c 'node src/updateConfig.js && echo "$TZ" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata && if [ "$RUN_ON_START" = "true" ]; then npm start; fi && envsubst < /etc/cron.d/microsoft-rewards-cron.template > /etc/cron.d/microsoft-rewards-cron && crontab /etc/cron.d/microsoft-rewards-cron && cron && tail -f /var/log/cron.log' CMD ["sh", "-c", "node src/updateConfig.js && \
echo \"$TZ\" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata && \
if [ \"$RUN_ON_START\" = \"true\" ]; then npm start; fi && \
envsubst < /etc/cron.d/microsoft-rewards-cron.template > /etc/cron.d/microsoft-rewards-cron && \
crontab /etc/cron.d/microsoft-rewards-cron && \
cron && tail -f /var/log/cron.log"]