Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"waitFor": "onCreateCommand",
"updateContentCommand": "/bin/bash .devcontainer/updateContent.sh",
"postCreateCommand": "",
"name": "MongoDB Library Sample App - Nodejs version",
"dockerComposeFile": "docker-compose.yml",
"service": "server", // container defined in docker-compose
"updateContentCommand": "bash .devcontainer/install-mongodb-db-tools.sh && bash .devcontainer/import.sh && bash .devcontainer/updateContent.sh", // included in prebuilt
// this will open 3 bash sessions, each one running the specified command
"postAttachCommand": {
"server": "cd server && npm start",
"client": "export NG_CLI_ANALYTICS=\"false\"; cd client && npm start",
"portSetup": "/bin/bash .devcontainer/portSetup.sh"
"portSetup": "sleep 5 && .devcontainer/portSetup.sh"
},
"customizations": {
"codespaces": {
"openFiles": [
"server/.env"
]
},
"vscode": {
"extensions": [
"mongodb.mongodb-vscode"
]
}
},
"portsAttributes": {
"4200": {
"label": "Client",
"onAutoForward": "openPreview"
},
"5000": {
"50000": {
"label": "Server"
},
"27017": {
"label": "MongoDB Atlas"
}
},
"forwardPorts": [4200, 5000]
"forwardPorts": [
4200,
50000,
27017
],
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
}
39 changes: 39 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
services:
server:
image: mcr.microsoft.com/vscode/devcontainers/javascript-node:dev-16-bullseye
volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:mongodb
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

depends_on:
- mongodb

mongodb:
image: mongodb/mongodb-atlas-local:8.0.3-20250506T093411Z
environment:
- MONGODB_INITDB_ROOT_USERNAME=admin
- MONGODB_INITDB_ROOT_PASSWORD=mongodb
- MONGO_INITDB_DATABASE=library
restart: unless-stopped
volumes:
- mongodb-data:/data/db
- ../..:/workspaces:cached
ports:
- 27017:27017
# To connect to library: from inside the container:
# mongosh mongodb://localhost/library --username admin --password mongodb --authenticationDatabase=admin
# From MongoDB extension:
# mongodb://admin:mongodb@localhost:27017/?directConnection=true

# Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
mongodb-data:
8 changes: 8 additions & 0 deletions .devcontainer/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd .devcontainer/data

# Import Library data WITHOUT embeddings

mongorestore --uri mongodb://localhost:27017/library --username admin --password mongodb --drop --authenticationDatabase=admin library

34 changes: 34 additions & 0 deletions .devcontainer/install-mongodb-db-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Install MongoDB command line tools

# We need to download MongoDB Database Tools to import data. In Linux we have two architectures:
# Linux identifies as amd64, in MongoDB the file has ARM64 for Mac M1
# https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-arm64-100.11.0.tgz
# Linux identifies as aarch64, in MongoDB the file has x86_64 for intel
# https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.11.0.tgz
# NOTE: changed Ubuntu version to 20.04, as 22.04 is not supported by the Image used in the devcontainer
# See: https://www.mongodb.com/community/forums/t/cant-run-mongorestore-with-glibc-2-31/267909

export MONGO_TOOLS_VERSION=100.11.0
export ARCH=$(dpkg --print-architecture)
if [ $ARCH = "amd64" ]; then export TARGET_ARCH="x86_64"; else export TARGET_ARCH="arm64"; fi
export TARGET="mongodb-database-tools-ubuntu2004-${TARGET_ARCH}-${MONGO_TOOLS_VERSION}.deb"
echo "Installing tools for architecture $ARCH, linux/${TARGET_ARCH}, target file=${TARGET}"
echo "curl https://fastdl.mongodb.org/tools/db/${TARGET}"
curl "https://fastdl.mongodb.org/tools/db/${TARGET}" --output "${TARGET}"
sudo apt-get install -y "./${TARGET}"
rm "./${TARGET}"

# Install mongosh

# https://downloads.mongodb.com/compass/mongosh-2.4.0-linux-x64.tgz
# https://downloads.mongodb.com/compass/mongosh-2.4.0-linux-arm64.tgz

echo "Installing mongosh"
if [ ARCH = "amd64" ]; then export MONGO_SHELL="mongosh-2.4.0-linux-x64"; else export MONGO_SHELL="mongosh-2.4.0-linux-arm64"; fi
curl "https://downloads.mongodb.com/compass/${MONGO_SHELL}.tgz" --output "${MONGO_SHELL}.tgz"
tar xvfz "${MONGO_SHELL}.tgz"
rm "./${MONGO_SHELL}.tgz"
sudo cp mongosh-2.4.0-linux-arm64/bin/* /usr/local/bin/
rm -rf "./${MONGO_SHELL}"
21 changes: 19 additions & 2 deletions .devcontainer/portSetup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
echo "Exposing port 5000"
gh codespace ports visibility 5000:public -c $CODESPACE_NAME
if [ -z "$CODESPACE_NAME" ]; then
echo "Not running in a codespace, exiting."
exit
fi

echo "Installing GH"

(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

echo "Exposing ports"
gh codespace ports visibility 4200:public 27017:public 50000:public -c $CODESPACE_NAME
2 changes: 2 additions & 0 deletions .devcontainer/updateContent.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export NG_CLI_ANALYTICS="false"

cd client
npm install
cd ../server
npm install

9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"mdb.presetConnections": [
{
"name": "Library DB",
"connectionString": "mongodb://admin:mongodb@localhost:27017"
}
],
"mdb.showOverviewPageAfterInstall": false
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is a library management system built with the MEAN (MongoDB, Express, Angul

**library/server/.env**
```
PORT="5000"
PORT="50000"
DATABASE_URI="mongodb+srv://<username>:<password>@m0.kwqkoewm.mongodb.net"
DATABASE_NAME="library"
SECRET="secret"
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const backendPort = "5000";
const backendPort = "50000";
const URL = `${location.protocol}//${location.hostname.replace('-4200', `-${backendPort}`)}${location.port ? `:${backendPort}` : ""}`;
// const URL = `https://library-management-system-930413307030.us-central1.run.app/`;

Expand Down
4 changes: 2 additions & 2 deletions server/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PORT=5000
DATABASE_URI=mongodb+srv://user:password@cluster
PORT=50000
DATABASE_URI=mongodb://admin:mongodb@localhost:27017/?directConnection=true
DATABASE_NAME=library
SECRET=secret
11 changes: 0 additions & 11 deletions server/Dockerfile

This file was deleted.