Address Sonar warnings and harden runtime
This commit is contained in:
parent
9e2bc89ff2
commit
69282c63d5
5 changed files with 25 additions and 9 deletions
17
Dockerfile
17
Dockerfile
|
|
@ -45,6 +45,8 @@ RUN apt-get update \
|
||||||
/var/lib/apt/lists/* \
|
/var/lib/apt/lists/* \
|
||||||
/var/tmp/*
|
/var/tmp/*
|
||||||
|
|
||||||
|
RUN useradd -ms /bin/bash fgc
|
||||||
|
|
||||||
# RUN node --version
|
# RUN node --version
|
||||||
# RUN npm --version
|
# RUN npm --version
|
||||||
|
|
||||||
|
|
@ -61,10 +63,16 @@ RUN npm install
|
||||||
# From 1.38 Playwright will no longer install browser automatically for playwright, but apparently still for playwright-firefox: https://github.com/microsoft/playwright/releases/tag/v1.38.0
|
# From 1.38 Playwright will no longer install browser automatically for playwright, but apparently still for playwright-firefox: https://github.com/microsoft/playwright/releases/tag/v1.38.0
|
||||||
# RUN npx playwright install firefox
|
# RUN npx playwright install firefox
|
||||||
|
|
||||||
COPY . .
|
# Only copy the files we actually need in the image to avoid accidentally adding secrets.
|
||||||
|
COPY *.js ./
|
||||||
|
COPY eslint.config.js jsconfig.json sonar-project.properties ./
|
||||||
|
COPY src ./src
|
||||||
|
COPY test ./test
|
||||||
|
COPY docker-entrypoint.sh ./
|
||||||
|
|
||||||
# Shell scripts need Linux line endings. On Windows, git might be configured to check out dos/CRLF line endings, so we convert them for those people in case they want to build the image. They could also use --config core.autocrlf=input
|
# Shell scripts need Linux line endings. On Windows, git might be configured to check out dos/CRLF line endings, so we convert them for those people in case they want to build the image. They could also use --config core.autocrlf=input
|
||||||
RUN dos2unix ./*.sh && chmod +x ./*.sh
|
RUN dos2unix ./*.sh && chmod +x ./*.sh
|
||||||
|
RUN chown -R fgc:fgc /fgc
|
||||||
COPY docker-entrypoint.sh /usr/local/bin/
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
|
||||||
ARG COMMIT=""
|
ARG COMMIT=""
|
||||||
|
|
@ -87,8 +95,9 @@ LABEL org.opencontainers.image.title="free-games-claimer" \
|
||||||
# Configure VNC via environment variables:
|
# Configure VNC via environment variables:
|
||||||
ENV VNC_PORT 5900
|
ENV VNC_PORT 5900
|
||||||
ENV NOVNC_PORT 6080
|
ENV NOVNC_PORT 6080
|
||||||
EXPOSE 5900
|
# Ports are not exposed by default; publish explicitly with -p when you really need GUI access.
|
||||||
EXPOSE 6080
|
# EXPOSE 5900
|
||||||
|
# EXPOSE 6080
|
||||||
|
|
||||||
# Configure Xvfb via environment variables:
|
# Configure Xvfb via environment variables:
|
||||||
ENV WIDTH 1920
|
ENV WIDTH 1920
|
||||||
|
|
@ -98,6 +107,8 @@ ENV DEPTH 24
|
||||||
# Show browser instead of running headless
|
# Show browser instead of running headless
|
||||||
ENV SHOW 1
|
ENV SHOW 1
|
||||||
|
|
||||||
|
USER fgc
|
||||||
|
|
||||||
# Script to setup display server & VNC is always executed.
|
# Script to setup display server & VNC is always executed.
|
||||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
# Default command to run. This is replaced by appending own command, e.g. `docker run ... node prime-gaming` to only run this script.
|
# Default command to run. This is replaced by appending own command, e.g. `docker run ... node prime-gaming` to only run this script.
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ const auth = async url => {
|
||||||
console.log('auth', url);
|
console.log('auth', url);
|
||||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||||
// redirects to https://login.aliexpress.com/?return_url=https%3A%2F%2Fwww.aliexpress.com%2Fp%2Fcoin-pc-index%2Findex.html
|
// redirects to https://login.aliexpress.com/?return_url=https%3A%2F%2Fwww.aliexpress.com%2Fp%2Fcoin-pc-index%2Findex.html
|
||||||
await Promise.any([page.waitForURL(/.*login\.aliexpress.com.*/).then(async () => {
|
await Promise.any([page.waitForURL(url => url.includes('login.aliexpress.com')).then(async () => {
|
||||||
// manual login
|
// manual login
|
||||||
console.error('Not logged in! Will wait for 120s for you to login...');
|
console.error('Not logged in! Will wait for 120s for you to login...');
|
||||||
// await page.waitForTimeout(120*1000);
|
// await page.waitForTimeout(120*1000);
|
||||||
|
|
|
||||||
|
|
@ -385,7 +385,9 @@ try {
|
||||||
const detailLoc = page.locator('[data-a-target="DescriptionItemDetails"], [data-testid="DescriptionItemDetails"]');
|
const detailLoc = page.locator('[data-a-target="DescriptionItemDetails"], [data-testid="DescriptionItemDetails"]');
|
||||||
if (await detailLoc.count()) {
|
if (await detailLoc.count()) {
|
||||||
const item_text = await detailLoc.first().innerText();
|
const item_text = await detailLoc.first().innerText();
|
||||||
store = item_text.toLowerCase().replace(/.* on /, '').slice(0, -1);
|
const lower = item_text.toLowerCase();
|
||||||
|
const onPos = lower.lastIndexOf(' on ');
|
||||||
|
if (onPos >= 0) store = lower.slice(onPos + 4).replace(/[.!]$/, '');
|
||||||
} else if (url.includes('/claims/')) {
|
} else if (url.includes('/claims/')) {
|
||||||
const slug = url.split('/claims/')[1]?.split('/')[0] || '';
|
const slug = url.split('/claims/')[1]?.split('/')[0] || '';
|
||||||
if (slug.includes('gog')) store = 'gog.com';
|
if (slug.includes('gog')) store = 'gog.com';
|
||||||
|
|
|
||||||
|
|
@ -121,10 +121,11 @@ export const notify = html => new Promise(resolve => {
|
||||||
if (cfg.debug) console.debug('notify: NOTIFY is not set!');
|
if (cfg.debug) console.debug('notify: NOTIFY is not set!');
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
|
const appriseBin = process.env.APPRISE_BIN || '/usr/local/bin/apprise';
|
||||||
const args = [cfg.notify, '-i', 'html', '-b', `'${html}'`];
|
const args = [cfg.notify, '-i', 'html', '-b', `'${html}'`];
|
||||||
if (cfg.notify_title) args.push('-t', cfg.notify_title);
|
if (cfg.notify_title) args.push('-t', cfg.notify_title);
|
||||||
if (cfg.debug) console.debug(`apprise ${args.join(' ')}`); // this also doesn't escape, but it's just for info
|
if (cfg.debug) console.debug(`${appriseBin} ${args.join(' ')}`); // this also doesn't escape, but it's just for info
|
||||||
execFile('apprise', args, (error, stdout, stderr) => {
|
execFile(appriseBin, args, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(`error: ${error.message}`);
|
console.log(`error: ${error.message}`);
|
||||||
if (error.message.includes('command not found')) {
|
if (error.message.includes('command not found')) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
// check if running the latest version
|
// check if running the latest version
|
||||||
|
|
||||||
import { log } from 'console';
|
import { log } from 'console';
|
||||||
import { execFile } from 'child_process';
|
import { execFile } from 'node:child_process';
|
||||||
|
|
||||||
|
const gitBin = process.env.GIT_BIN || '/usr/bin/git';
|
||||||
|
|
||||||
const runGit = (...args) => new Promise((resolve, reject) => {
|
const runGit = (...args) => new Promise((resolve, reject) => {
|
||||||
execFile('git', args, { cwd: process.cwd() }, (error, stdout, stderr) => {
|
execFile(gitBin, args, { cwd: process.cwd() }, (error, stdout, stderr) => {
|
||||||
if (stderr) console.error(`stderr: ${stderr}`);
|
if (stderr) console.error(`stderr: ${stderr}`);
|
||||||
// if (stdout) console.log(`stdout: ${stdout}`);
|
// if (stdout) console.log(`stdout: ${stdout}`);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue