Spaces:
Sleeping
Sleeping
coyotte508
commited on
Commit
·
1d46bd1
1
Parent(s):
3199efb
easier mongo setup
Browse files- .devcontainer/Dockerfile +9 -0
- .devcontainer/devcontainer.json +12 -1
- docker-compose.yml +21 -0
- src/lib/jobs/refresh-conversation-stats.ts +4 -0
.devcontainer/Dockerfile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm
|
| 2 |
+
|
| 3 |
+
# Install MongoDB tools (mongosh, mongorestore, mongodump) directly from MongoDB repository
|
| 4 |
+
RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg && \
|
| 5 |
+
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list && \
|
| 6 |
+
apt-get update && \
|
| 7 |
+
apt-get install -y mongodb-mongosh mongodb-database-tools vim && \
|
| 8 |
+
apt-get autoremove -y && \
|
| 9 |
+
rm -rf /var/lib/apt/lists/*
|
.devcontainer/devcontainer.json
CHANGED
|
@@ -3,12 +3,23 @@
|
|
| 3 |
{
|
| 4 |
"name": "Node.js & TypeScript",
|
| 5 |
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
| 6 |
-
"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
"customizations": {
|
| 9 |
"vscode": {
|
| 10 |
"extensions": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "svelte.svelte-vscode"]
|
| 11 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
|
|
| 3 |
{
|
| 4 |
"name": "Node.js & TypeScript",
|
| 5 |
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
| 6 |
+
"build": {
|
| 7 |
+
"dockerfile": "Dockerfile"
|
| 8 |
+
},
|
| 9 |
|
| 10 |
"customizations": {
|
| 11 |
"vscode": {
|
| 12 |
"extensions": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "svelte.svelte-vscode"]
|
| 13 |
}
|
| 14 |
+
},
|
| 15 |
+
|
| 16 |
+
"features": {
|
| 17 |
+
// Install docker in container
|
| 18 |
+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
|
| 19 |
+
// Use proprietary docker engine. I get a timeout error when using the default moby engine and loading
|
| 20 |
+
// microsoft's PGP keys
|
| 21 |
+
"moby": false
|
| 22 |
+
}
|
| 23 |
}
|
| 24 |
|
| 25 |
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# For development only
|
| 2 |
+
# Set MONGODB_URL=mongodb://localhost:27017 in .env.local to use this container
|
| 3 |
+
services:
|
| 4 |
+
mongo:
|
| 5 |
+
image: mongo:8
|
| 6 |
+
hostname: mongodb
|
| 7 |
+
ports:
|
| 8 |
+
- ${LOCAL_MONGO_PORT:-27017}:27017
|
| 9 |
+
command: --replSet rs0 --bind_ip_all #--setParameter notablescan=1
|
| 10 |
+
mem_limit: "5g"
|
| 11 |
+
mem_reservation: "3g"
|
| 12 |
+
healthcheck:
|
| 13 |
+
# need to specify the hostname here because the default is the container name, and we run the app outside of docker
|
| 14 |
+
test: test $$(mongosh --quiet --eval 'try {rs.status().ok} catch(e) {rs.initiate({_id:"rs0",members:[{_id:0,host:"127.0.0.1:${LOCAL_MONGO_PORT:-27017}"}]}).ok}') -eq 1
|
| 15 |
+
interval: 5s
|
| 16 |
+
volumes:
|
| 17 |
+
- mongodb-data:/data/db
|
| 18 |
+
restart: always
|
| 19 |
+
|
| 20 |
+
volumes:
|
| 21 |
+
mongodb-data:
|
src/lib/jobs/refresh-conversation-stats.ts
CHANGED
|
@@ -33,6 +33,10 @@ async function computeStats(params: {
|
|
| 33 |
span: ConversationStats["date"]["span"];
|
| 34 |
type: ConversationStats["type"];
|
| 35 |
}) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
const lastComputed = await collections.conversationStats.findOne(
|
| 37 |
{ "date.field": params.dateField, "date.span": params.span, type: params.type },
|
| 38 |
{ sort: { "date.at": -1 } }
|
|
|
|
| 33 |
span: ConversationStats["date"]["span"];
|
| 34 |
type: ConversationStats["type"];
|
| 35 |
}) {
|
| 36 |
+
if (!(await collections.conversations.estimatedDocumentCount())) {
|
| 37 |
+
return;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
const lastComputed = await collections.conversationStats.findOne(
|
| 41 |
{ "date.field": params.dateField, "date.span": params.span, type: params.type },
|
| 42 |
{ sort: { "date.at": -1 } }
|