Skip to content

Commit

Permalink
Correct clean-db
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-asriyan committed Aug 24, 2024
1 parent 8c1722d commit 806377e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/clean-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ jobs:
echo "$ENV_FILE_CONTENT" > .env
- name: Clean
run: make dev_clean_db

run: make ci_install ci_clean_db
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clean-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion stats.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down

0 comments on commit 806377e

Please sign in to comment.