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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM debian:trixie

# Install dependencies
RUN apt-get update && apt-get install -y \
gnupg \
curl \
git \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 18 from NodeSource
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install MongoDB from official repository
RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor && \
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 && \
apt-get update && \
apt-get install -y mongodb-org && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy all files
COPY . .

# Install dependencies in correct order
WORKDIR /app/common
RUN npm install

WORKDIR /app/backend
RUN npm install

WORKDIR /app/frontend
RUN npm install && npm run build

# Create startup script
RUN echo '#!/bin/bash' > /start.sh && \
echo 'mkdir -p /data/db' >> /start.sh && \
echo 'mongod --fork --logpath /var/log/mongodb.log --dbpath /data/db' >> /start.sh && \
echo 'sleep 5' >> /start.sh && \
echo 'cd /app/backend' >> /start.sh && \
echo 'if [ ! -f /data/db/.db_initialized ]; then' >> /start.sh && \
echo ' echo "Initializing database..."' >> /start.sh && \
echo ' npm run db-build && touch /data/db/.db_initialized' >> /start.sh && \
echo ' echo "Database initialization complete"' >> /start.sh && \
echo 'else' >> /start.sh && \
echo ' echo "Database already initialized, skipping..."' >> /start.sh && \
echo 'fi' >> /start.sh && \
echo 'npm run dev' >> /start.sh && \
chmod +x /start.sh

EXPOSE 80

CMD ["/start.sh"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ To work on the codebase, execute in parallel:

* In `frontend/`, execute `npm run dev` to build and pack the frontend JavaScript files in watch mode.

* Finally, you can access the page through `http://127.0.0.1`.
* Finally, you can access the page through `http://127.0.0.1`.

## Docker Deployment

You can run the app using Docker with:

```
docker compose up --build
```
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: jisho-app
restart: unless-stopped
environment:
- PORT=80
- MONGODB_URL=mongodb://localhost:27017/jisho
ports:
- "80:80"
volumes:
- ./data/db:/data/db