Skip to content

Commit 3de1782

Browse files
committed
github codespaces - docker attempt
1 parent d4a2337 commit 3de1782

File tree

9 files changed

+431
-3
lines changed

9 files changed

+431
-3
lines changed

.devcontainer/devcontainer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "Memcode Development",
3+
"dockerComposeFile": "../docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/app",
6+
7+
// Configure tool-specific properties
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"dbaeumer.vscode-eslint"
12+
],
13+
"settings": {
14+
"editor.codeActionsOnSave": {
15+
"source.fixAll.eslint": true
16+
}
17+
}
18+
}
19+
},
20+
21+
22+
// Use 'forwardPorts' to make a list of ports inside the container available locally
23+
"forwardPorts": [3000, 5432],
24+
"portsAttributes": {
25+
"3000": {
26+
"label": "Memcode App",
27+
"onAutoForward": "openBrowser"
28+
},
29+
"5432": {
30+
"label": "PostgreSQL Database"
31+
}
32+
},
33+
34+
// Use 'postCreateCommand' to run commands after the container is created
35+
"postCreateCommand": "chmod +x docker-setup.sh && ./docker-setup.sh setup && ./docker-setup.sh start-bg",
36+
37+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root
38+
"remoteUser": "node"
39+
}
File renamed without changes.

Contributing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ Feel free to ask questions/propose features in github issues, or email contact@m
3939
<div align="center">
4040
<img width="50px" src="https://user-images.githubusercontent.com/7578559/154219522-280c4f96-4e3d-45e9-9beb-671b339b3f92.png" alt="Memcode Logo"/>
4141
</div>
42+
43+
___

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Use Node.js 22 as specified in package.json
2+
FROM node:22-alpine
3+
4+
# Install system dependencies
5+
RUN apk add --no-cache \
6+
python3 \
7+
make \
8+
g++ \
9+
postgresql-client \
10+
bash
11+
12+
# Create app directory
13+
WORKDIR /app
14+
15+
# Copy package files
16+
COPY package*.json ./
17+
18+
# Install dependencies
19+
RUN npm install --legacy-peer-deps
20+
21+
# Copy source code
22+
COPY . .
23+
24+
# Make entrypoint script executable
25+
COPY docker-entrypoint.sh /docker-entrypoint.sh
26+
RUN chmod +x /docker-entrypoint.sh
27+
28+
# Expose port 3000
29+
EXPOSE 3000
30+
31+
# Use custom entrypoint script
32+
ENTRYPOINT ["/docker-entrypoint.sh"]

README-DOCKER.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Memcode Docker Setup
2+
3+
## Quick Start
4+
5+
**Local Development:**
6+
```bash
7+
git clone https://github.com/lakesare/memcode.git
8+
cd memcode
9+
./docker-setup.sh setup
10+
./docker-setup.sh start
11+
```
12+
13+
**GitHub Codespaces:**
14+
Just open in Codespaces - automatically starts!
15+
16+
Open http://localhost:3000 when ready
17+
18+
## Commands
19+
20+
```bash
21+
./docker-setup.sh setup # First time setup
22+
./docker-setup.sh start # Start Memcode
23+
./docker-setup.sh stop # Stop Memcode
24+
./docker-setup.sh logs # View logs
25+
./docker-setup.sh reset # Reset everything
26+
```
27+
28+
## Manual Docker Commands
29+
30+
```bash
31+
docker-compose up # Start
32+
docker-compose down # Stop
33+
docker-compose down -v # Reset (deletes data)
34+
```

backend/db/services/getConnectionString.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const getConnectionString = () => {
33
// pgweb: postgres://postgres:§1§1§1@localhost:5432/memcode
44
case 'development':
55
return {
6-
host: 'localhost', // 'localhost' is the default;
7-
port: 5432, // 5432 is the default;
8-
database: 'memcode',
6+
host: process.env['DB_HOST'] || 'localhost',
7+
port: parseInt(process.env['DB_PORT']) || 5432,
8+
database: process.env['DB_NAME'] || 'memcode',
99
user: process.env['DB_USER'],
1010
password: process.env['DB_PASSWORD']
1111
};

docker-compose.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build: .
6+
ports:
7+
- "3000:3000"
8+
depends_on:
9+
- postgres
10+
environment:
11+
- NODE_ENV=development
12+
# Database connection
13+
- DB_USER=memcode
14+
- DB_PASSWORD=memcode
15+
- DB_NAME=memcode
16+
- DB_HOST=postgres
17+
- DB_PORT=5432
18+
# Required application settings
19+
- JWT_SECRET=docker_development_secret_not_for_production
20+
- CONTACT_EMAIL=contact@memcode.com
21+
# OAuth providers (empty for Docker development)
22+
- GITHUB_OAUTH_ID=
23+
- GITHUB_OAUTH_SECRET=
24+
- GOOGLE_OAUTH_ID=
25+
- GOOGLE_OAUTH_SECRET=
26+
- GOOGLE_OAUTH_CALLBACK=http://localhost:3000/api/auth/google/callback
27+
# AWS S3 (empty for Docker development)
28+
- AWS_ACCESS_KEY_ID=
29+
- AWS_SECRET_ACCESS_KEY=
30+
- AWS_REGION=
31+
- AWS_BUCKET_NAME=
32+
# OpenAI (empty for Docker development)
33+
- OPENAI_API_KEY=
34+
volumes:
35+
# Mount source code for development
36+
- ./backend:/app/backend
37+
- ./frontend:/app/frontend
38+
# Exclude node_modules from being overwritten
39+
- /app/node_modules
40+
# Mount webpacked files
41+
- ./backend/webpacked:/app/backend/webpacked
42+
restart: unless-stopped
43+
44+
postgres:
45+
image: postgres:13-alpine
46+
environment:
47+
POSTGRES_DB: memcode
48+
POSTGRES_USER: memcode
49+
POSTGRES_PASSWORD: memcode
50+
ports:
51+
- "5432:5432"
52+
volumes:
53+
- postgres_data:/var/lib/postgresql/data
54+
# Mount schema for initialization
55+
- ./backend/db/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
56+
restart: unless-stopped
57+
58+
volumes:
59+
postgres_data:

docker-entrypoint.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🚀 Starting Memcode Docker container..."
5+
6+
# Create empty env.js file (app will use environment variables)
7+
echo "// Environment variables are set via Docker\nexport default {};" > /app/env.js
8+
9+
# Function to wait for PostgreSQL to be ready
10+
wait_for_postgres() {
11+
echo "⏳ Waiting for PostgreSQL to be ready..."
12+
until pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER"; do
13+
echo "PostgreSQL is unavailable - sleeping"
14+
sleep 2
15+
done
16+
echo "✅ PostgreSQL is ready!"
17+
}
18+
19+
# Function to check if database exists and has tables
20+
check_database_initialized() {
21+
TABLES_COUNT=$(psql "postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME" -t -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';" 2>/dev/null || echo "0")
22+
if [ "$TABLES_COUNT" -gt 0 ]; then
23+
echo "✅ Database already initialized with $TABLES_COUNT tables"
24+
return 0
25+
else
26+
echo "📋 Database needs initialization"
27+
return 1
28+
fi
29+
}
30+
31+
# Function to build frontend
32+
build_frontend() {
33+
echo "🏗️ Building frontend..."
34+
cd /app/frontend
35+
NODE_OPTIONS="--openssl-legacy-provider" ../node_modules/.bin/webpack --config ./webpack/development.config.js
36+
echo "✅ Frontend built successfully!"
37+
cd /app
38+
}
39+
40+
# Wait for database
41+
wait_for_postgres
42+
43+
# Check if database is initialized, if not the schema will be loaded by PostgreSQL init scripts
44+
if ! check_database_initialized; then
45+
echo "🔄 Database will be initialized by PostgreSQL init scripts..."
46+
# Give PostgreSQL a moment to run the init scripts
47+
sleep 5
48+
fi
49+
50+
# Build frontend if webpacked directory doesn't exist or is empty
51+
if [ ! -d "/app/backend/webpacked" ] || [ -z "$(ls -A /app/backend/webpacked 2>/dev/null)" ]; then
52+
build_frontend
53+
else
54+
echo "✅ Frontend already built"
55+
fi
56+
57+
echo "🎯 Starting Memcode application..."
58+
59+
# Start the application
60+
exec node backend/index.js

0 commit comments

Comments
 (0)