Skip to content

Commit

Permalink
new theme, start ripping out auth0, bring in improvements from CurseFund
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Dec 16, 2024
1 parent afae1c1 commit 0294a9a
Show file tree
Hide file tree
Showing 365 changed files with 30,151 additions and 163,902 deletions.
12 changes: 9 additions & 3 deletions .devcontainer/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
MONGO_DB_USERNAME=chilicilantro
MONGO_DB_PASSWORD=db!Passw0rd
MONGO_INITDB_ROOT_USERNAME=chilicilantro
MONGO_INITDB_ROOT_PASSWORD=db!Passw0rd
MONGO_INITDB_DATABASE=chilicilantro
MONGO_REPLICA_SET_NAME=rs0
MONGO_PORT=27017
MONGO_KEYFILE=/tmp/replica.key
MONGO_DB_PATH=/data/db
FONTAWESOME_KEY=XXXXXXXXXXXXXX
GRAPHITE_KEY=XXXXXXXXXXXXXX

COMPOSE_PROJECT_NAME=chili-and-cilantro_devcontainer
COMPOSE_PROJECT_NAME=chili-and-cilantro_devcontainer
25 changes: 25 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm

# Install MongoDB command line tools - though mongo-database-tools not available on arm64
ARG MONGO_TOOLS_VERSION=6.0
RUN . /etc/os-release \
&& curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y mongodb-mongosh \
&& if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"



21 changes: 21 additions & 0 deletions .devcontainer/Mongo.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# db/Mongo.Dockerfile

FROM mongo:latest

# Generate a secure key for the replica set
RUN openssl rand -base64 756 > "/tmp/replica.key" \
&& chmod 600 /tmp/replica.key \
&& chown mongodb:mongodb /tmp/replica.key

# Remove any existing init scripts to prevent conflicts
RUN rm -rf /docker-entrypoint-initdb.d/*

# Copy the updated entrypoint script
COPY mongodb_entrypoint.sh /usr/local/bin/mongodb_entrypoint.sh
RUN chmod +x /usr/local/bin/mongodb_entrypoint.sh

# Override the default entrypoint
ENTRYPOINT ["/usr/local/bin/mongodb_entrypoint.sh"]

# Expose MongoDB port
EXPOSE 27017
94 changes: 49 additions & 45 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
"forwardPorts": [27017],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
"forwardPorts": [3000, 27017],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./setup-nvm.sh && ./fontawesome-npmrc.sh && ./do-yarn.sh && git config --global --add safe.directory /workspace",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./setup-nvm.sh && ./fontawesome-npmrc.sh && ./npm-install-globals.sh && ./do-yarn.sh && git config --global --add safe.directory /workspaces/chili-and-cilantro",

// Configure tool-specific properties.
// "customizations": {},
"customizations": {
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"mongodb.mongodb-vscode",
"rangav.vscode-thunder-client",
"github.vscode-github-actions",
"eamodio.gitlens",
"ms-azuretools.vscode-docker",
"esbenp.prettier-vscode",
"ms-vscode-remote.remote-containers",
"firsttris.vscode-jest-runner",
"ms-playwright.playwright",
"nrwl.angular-console",
"TabNine.tabnine-vscode",
"GitHub.copilot",
"GitHub.copilot-chat"
],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/usr/bin/zsh"
},
},
},
// Configure tool-specific properties.
// "customizations": {},
"customizations": {
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"mongodb.mongodb-vscode",
"rangav.vscode-thunder-client",
"github.vscode-github-actions",
"eamodio.gitlens",
"ms-azuretools.vscode-docker",
"esbenp.prettier-vscode",
"ms-vscode-remote.remote-containers",
"firsttris.vscode-jest-runner",
"ms-playwright.playwright",
"nrwl.angular-console",
"GitHub.copilot",
"GitHub.copilot-chat",
"Codeium.codeium",
"bruno-api-client.bruno",
"GitHub.vscode-pull-request-github",
"MermaidChart.vscode-mermaid-chart",
"Graphite.gti-vscode"
],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/usr/bin/zsh"
}
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
60 changes: 35 additions & 25 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
version: '3'
services:
app:
image: mcr.microsoft.com/devcontainers/typescript-node:0-20-bullseye
build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/workspace:cached
command: /bin/sh -c "while sleep 1000; do :; done"
environment:
NODE_ENV: development
FONTAWESOME_KEY: ${FONTAWESOME_KEY}
- ../..:/workspaces:cached
command: sleep infinity
env_file:
- .env
network_mode: host
depends_on:
- mongo
networks:
- node_app
- db

mongo:
restart: always
image: mongo:6.0.7
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_DB_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_DB_PASSWORD}
volumes:
- mongo_data:/data/db
networks:
- node_app
db:
build:
context: .
dockerfile: ./Mongo.Dockerfile
container_name: db # Ensures the container name is 'db'
hostname: db # Sets the internal hostname to 'db'
restart: unless-stopped
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
ports:
- 27017:27017
- "27017:27017"
volumes:
- mongodb-data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE}
- MONGO_REPLICA_SET_NAME=${MONGO_REPLICA_SET_NAME}
- MONGO_PORT=${MONGO_PORT}
- MONGO_KEYFILE=${MONGO_KEYFILE}
- MONGO_DB_PATH=${MONGO_DB_PATH}
- DB_HOST=127.0.0.1:27017
network_mode: host

volumes:
mongo_data:

networks:
node_app:
mongodb-data:
100 changes: 100 additions & 0 deletions .devcontainer/mongodb_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
set -e
set -x # Enable debug mode for logging each command

echo "Hostname: $(hostname)"

# Environment Variables with Defaults
MONGO_LOG="/var/log/mongodb/mongod.log"
MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME:-"root"}
MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD:-"rootpassword"}
MONGO_REPLICA_SET_NAME=${MONGO_REPLICA_SET_NAME:-"rs0"}
MONGO_BIND_IP=${MONGO_BIND_IP:-"0.0.0.0"}
MONGO_PORT=${MONGO_PORT:-27017}
MONGO_KEYFILE=${MONGO_KEYFILE:-"/tmp/replica.key"}
MONGO_DB_PATH=${MONGO_DB_PATH:-"/data/db"}

start_mongo_noauth() {
echo "Starting MongoDB without authentication..."
mongod --replSet "$MONGO_REPLICA_SET_NAME" --bind_ip_all --dbpath "$MONGO_DB_PATH" --logpath "$MONGO_LOG" --fork
}

start_mongo_auth_foreground() {
echo "Starting MongoDB with authentication in the foreground..."
exec mongod --auth --replSet "$MONGO_REPLICA_SET_NAME" --bind_ip_all --dbpath "$MONGO_DB_PATH" --keyFile "$MONGO_KEYFILE"
}

stop_mongo() {
echo "Stopping MongoDB..."
mongosh --quiet --eval 'db.getSiblingDB("admin").shutdownServer({ force: true });' || true
sleep 5
}

wait_for_mongo() {
echo "Waiting for MongoDB to be ready..."
until mongosh --quiet --eval 'db.runCommand({ ping: 1 })' >/dev/null 2>&1; do
echo "MongoDB not ready yet, retrying..."
sleep 2
done
echo "MongoDB is ready."
}

create_root_user() {
echo "Creating root user if it does not exist..."
mongosh --quiet --eval "
const adminDb = db.getSiblingDB('admin');
if (!adminDb.getUser('$MONGO_INITDB_ROOT_USERNAME')) {
adminDb.createUser({
user: '$MONGO_INITDB_ROOT_USERNAME',
pwd: '$MONGO_INITDB_ROOT_PASSWORD',
roles: [{ role: 'root', db: 'admin' }]
});
print('Root user created.');
} else {
print('Root user already exists.');
}
"
}

initialize_replica_set() {
echo "Initializing replica set..."
mongosh --quiet --eval "
const status = rs.status();
if (status.codeName === 'NotYetInitialized') {
rs.initiate({
_id: '$MONGO_REPLICA_SET_NAME',
members: [{ _id: 0, host: 'localhost:$MONGO_PORT' }]
});
print('Replica set initialized.');
} else {
print('Replica set already initialized.');
}
"
}

wait_for_primary() {
echo "Waiting for replica set to become PRIMARY..."
until mongosh --quiet --eval 'db.isMaster().ismaster' | grep -q 'true'; do
echo "Replica set is not PRIMARY yet, retrying..."
sleep 2
done
echo "Replica set is now PRIMARY."
}

# Main Execution Flow
echo "Starting MongoDB setup..."

# Start MongoDB without authentication
start_mongo_noauth
wait_for_mongo

# Initialize the replica set
initialize_replica_set
wait_for_primary

# Create the root user
create_root_user

# Restart MongoDB with authentication
stop_mongo
start_mongo_auth_foreground
17 changes: 17 additions & 0 deletions .devcontainer/mongodb_healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Wait for MongoDB to start
until mongosh --quiet --eval 'db.runCommand({ ping: 1 })' >/dev/null 2>&1; do
echo "Waiting for MongoDB to start..."
sleep 5
done

# Check if MongoDB replica set is ready
is_master=$(mongosh --quiet --eval 'db.isMaster().ismaster' --authenticationDatabase admin -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD")
if [ "$is_master" != "true" ]; then
echo "MongoDB replica set is not yet ready."
exit 1
fi

echo "MongoDB is up and running with replica set."
exit 0
Loading

0 comments on commit 0294a9a

Please sign in to comment.