From 3f739f08ea859132e5c436033577232303452bcf Mon Sep 17 00:00:00 2001 From: Trung Le Date: Fri, 11 Jun 2021 22:35:54 +0700 Subject: [PATCH 1/4] feat: dockerize the app * change loop config to false, or container will run forever * support latest node on latest alpine, smallest size possible * fix format issue using eslint (default config) * added @babel/core since this is needed for eslint-parser --- .dockerignore | 26 ++++++++++++++++++++++++++ Dockerfile | 24 ++++++++++++++++++++++++ config.json | 2 +- logger.js | 10 +++++----- package.json | 1 + 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..26e4025 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# From gitignore (modified) +*.bat +*.log +*.lnk +node_modules +package-lock.json +DeviceAuthGenerator.exe +device_auths.json +.egstore +.vscode +*.code-workspace +.idea +.github + +# Folders +.git +test + +# Other files +*Dockerfile* +*dockerignore* +.gitignore +LICENSE +README* +.eslintrc.json +.editorconfig \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b74751 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Builder stage +FROM node:16-alpine3.13 as builder +# Install dependencies for building node modules +# python3, g++, make: required by node-gyp +# git: required by check-update-github +WORKDIR /app +COPY ./package.json ./package.json +RUN apk add --no-cache --virtual \ + .gyp \ + python3=~3.8 \ + make=~4.3 \ + g++=~10.2 \ + git=~2.30 \ + && npm install --only=production \ + && apk del .gyp + +# App stage +FROM node:16-alpine3.13 as app + +WORKDIR /app +COPY . /app +COPY --from=builder /app/node_modules ./node_modules + +CMD ["npm", "start", "--no-update-notifier"] diff --git a/config.json b/config.json index b10cbe7..5fc6493 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { "options": {}, "delay": 1440, - "loop": true + "loop": false } diff --git a/logger.js b/logger.js index 33b92a4..b5e81ca 100644 --- a/logger.js +++ b/logger.js @@ -12,9 +12,9 @@ module.exports = { "debug": colors.blue, "info": colors.green, "warn": colors.magenta, - "error": [colors.red, colors.bold] + "error": [colors.red, colors.bold], }, - "preprocess": data => { + "preprocess": (data) => { data.title = data.title.toUpperCase(); while (data.title.length < 5) { data.title += " "; } data.args = [...data.args]; @@ -23,17 +23,17 @@ module.exports = { data.args.shift(); } }, - "transport": data => { + "transport": (data) => { // eslint-disable-next-line no-console console.log(data.output); const streamoptions = { "flags": "a", - "encoding": "utf8" + "encoding": "utf8", }; fs.createWriteStream(path.join(__dirname, "claimer.log"), streamoptions).write(`\r\n${data.rawoutput}`); if (data.logpath) { fs.createWriteStream(data.logpath, streamoptions).write(`\r\n${data.rawoutput}`); } - } + }, }; diff --git a/package.json b/package.json index 4357226..b85ccc9 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "homepage": "https://github.com/revadike/epicgames-freebies-claimer", "url": "https://github.com/revadike/epicgames-freebies-claimer", "devDependencies": { + "@babel/core": "latest", "@babel/eslint-parser": "latest", "chai": "*", "eslint": "latest", From 15076b13b6b0c784437beaa3b07f16f3e314b9e6 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Sat, 12 Jun 2021 00:06:09 +0700 Subject: [PATCH 2/4] feat: add github actions pipeline Build, lint, test on Windows/Linux with Node 12, 14, 16 --- .github/workflows/node.yml | 34 ++++++++++++++++++++++++++++++++++ .gitignore | 3 +-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/node.yml diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml new file mode 100644 index 0000000..099a2dd --- /dev/null +++ b/.github/workflows/node.yml @@ -0,0 +1,34 @@ +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + node_version: + - 12 + - 14 + - 16 + name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Setup node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node_version }} + architecture: ${{ matrix.architecture }} + - name: Install dependencies + run: npm install + - name: Linting + run: eslint . + - name: Test + run: npm test diff --git a/.gitignore b/.gitignore index f7043ee..046e1f6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,4 @@ device_auths.json !.vscode/launch.json !.vscode/extensions.json *.code-workspace -.idea -.github \ No newline at end of file +.idea \ No newline at end of file From 1bdee3a86eb3e1116702bb486e445c2344172ca2 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Sat, 12 Jun 2021 00:58:31 +0700 Subject: [PATCH 3/4] fix: calling eslint & reduce build env * fix calling eslint via npx * remove windows & node 14 --- .github/workflows/node.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 099a2dd..4999fd7 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -13,10 +13,8 @@ jobs: matrix: os: - ubuntu-latest - - windows-latest node_version: - 12 - - 14 - 16 name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} steps: @@ -29,6 +27,6 @@ jobs: - name: Install dependencies run: npm install - name: Linting - run: eslint . + run: npx eslint . - name: Test run: npm test From 51408bc54348fcabc8cebad8b4b8b96262d58f00 Mon Sep 17 00:00:00 2001 From: Trung Le Date: Wed, 23 Jun 2021 00:42:11 +0700 Subject: [PATCH 4/4] remove github actions workflow --- .github/workflows/node.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/node.yml diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml deleted file mode 100644 index 4999fd7..0000000 --- a/.github/workflows/node.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - ubuntu-latest - node_version: - - 12 - - 16 - name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node_version }} - architecture: ${{ matrix.architecture }} - - name: Install dependencies - run: npm install - - name: Linting - run: npx eslint . - - name: Test - run: npm test