diff --git a/.github/workflows/clean-db.yml b/.github/workflows/clean-db.yml index 98501c1..9c4b3b0 100644 --- a/.github/workflows/clean-db.yml +++ b/.github/workflows/clean-db.yml @@ -28,5 +28,4 @@ jobs: echo "$ENV_FILE_CONTENT" > .env - name: Clean - run: make dev_clean_db - \ No newline at end of file + run: make ci_install ci_clean_db diff --git a/Makefile b/Makefile index 7597309..7a86661 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ IMAGE_NAME=watchtogether.online -RUN_DEV_PARAMS=--workdir /app -v .:/app -it --rm +DEV_RUN_PARAMS=--workdir /app -v .:/app --rm -it +DEV_INSTALL_COMMAND=npm ci && npm i --no-save @rollup/rollup-linux-arm64-gnu firebase-admin +CI_RUN_PARAMS=--workdir /app -v .:/app --rm +CI_INSTALL_COMMAND=npm ci && npm i --no-save firebase-admin ENV_FILE=.env DOCKER_DEV_IMAGE_NAME=watch-together-dev DOCKER_STAGING_IMAGE_NAME=watch-together-staging @@ -16,18 +19,24 @@ build_prod_bundle_image: docker build $$(./buildargs.sh ${ENV_FILE}) --build-arg NODE_ENV=production -t ${DOCKER_PROD_BUNDLE_IMAGE_NAME} --target bundle . dev_install: build_dev_image - docker run ${RUN_DEV_PARAMS} ${DOCKER_DEV_IMAGE_NAME} sh -c "npm ci && npm i --no-save @rollup/rollup-linux-arm64-gnu" + docker run ${DEV_RUN_PARAMS} ${DOCKER_DEV_IMAGE_NAME} sh -c "${DEV_INSTALL_COMMAND}" dev_serve: - docker run ${RUN_DEV_PARAMS} -p 5173:5173 --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} npm run dev -- --host + docker run ${DEV_RUN_PARAMS} -p 5173:5173 --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} npm run dev -- --host dev_enter: - docker run ${RUN_DEV_PARAMS} --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} bash + docker run ${DEV_RUN_PARAMS} --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} bash -dev_stats: build_dev_image - docker run ${RUN_DEV_PARAMS} --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} npm run stats -- --host > stats.tsv +dev_stats: + docker run ${DEV_RUN_PARAMS} --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} npm run stats -- --host > stats.tsv -dev_clean_db: build_dev_image +dev_clean_db: + docker run --workdir /app -v .:/app --rm --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} npm run clean-db -- 2678400 # 31 day + +ci_install: build_dev_image + docker run ${CI_RUN_PARAMS} ${DOCKER_DEV_IMAGE_NAME} sh -c "${CI_INSTALL_COMMAND}" + +ci_clean_db: docker run --workdir /app -v .:/app --rm --env-file ${ENV_FILE} ${DOCKER_DEV_IMAGE_NAME} npm run clean-db -- 2678400 # 31 day staging_serve: build_staging_image diff --git a/clean-db.js b/clean-db.js index 46323a6..a1065e2 100644 --- a/clean-db.js +++ b/clean-db.js @@ -21,9 +21,9 @@ const main = async function() { if (typeof updatedAt !== 'number') { process.stdout.write(`room#${childSnapshot.key}\twrong type: ${typeof updatedAt}\n`); } else if (updatedAt < now - diff) { - process.stdout.write(`room#${childSnapshot.key}\tupdated ${Math.round((now - updatedAt) / 60 / 60 / 24)} hours ago\n`); + process.stdout.write(`room#${childSnapshot.key}\tupdated ${Math.round((now - updatedAt) / 60 / 60 / 24)} days ago\n`); } else if (updatedAt > now + diff) { - process.stdout.write(`room#${childSnapshot.key}\tupdated ${Math.round((updatedAt - now) / 60 / 60 / 24)} hours ahead (in future)\n`); + process.stdout.write(`room#${childSnapshot.key}\tupdated ${Math.round((updatedAt - now) / 60 / 60 / 24)} days ahead (in future)\n`); } else { return; } diff --git a/stats.js b/stats.js index 2b616be..f3d9977 100644 --- a/stats.js +++ b/stats.js @@ -1,5 +1,5 @@ import admin from 'firebase-admin'; -import { ref, onValue, get } from 'firebase/database'; +import { get } from 'firebase/database'; import serviceAccount from './service-account-key.json' assert { type: "json" }; admin.initializeApp({