Skip to content

feat(docker): Add Docker support for local development and automate #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
pb/pb_public/*
pb/LICENSE.md
pb/pocketbase
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Use a Node.js base image
FROM node:20.11.1-buster

# Set the working directory
WORKDIR /app

# Copy application files
COPY . /app

# Ensure entrypoint script is executable
RUN chmod +x /app/entrypoint.sh

# Install unzip utility
RUN apt-get update && apt-get install -y unzip

# Download PocketBase without extracting
ARG PB_VERSION=0.22.20
RUN mkdir -p /app/pb \
&& echo "Downloading PocketBase version ${PB_VERSION}" \
&& wget https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip -O /tmp/pb.zip \
&& ls -la /tmp

# Switch to the UI directory
WORKDIR /app/ui

# Update environment variable and build the frontend
RUN sed -i 's/^VITE_PROD_PB_URL=.*/VITE_PROD_PB_URL=http:\/\/127.0.0.1:8090/' .env \
&& npm install \
&& npm run build

# Expose the PocketBase port
EXPOSE 8090

# Use the script to start the application
ENTRYPOINT ["/app/entrypoint.sh"]
29 changes: 29 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use a Node.js base image
FROM node:20.11.1-buster

# Set the working directory
WORKDIR /app

# Copy application files
COPY . /app

# Ensure entrypoint script is executable
RUN chmod +x /app/entrypoint.dev.sh

# Install unzip utility and any dev dependencies
RUN apt-get update && apt-get install -y unzip

# Download PocketBase without extracting
ARG PB_VERSION=0.22.20
RUN mkdir -p /app/pb \
&& wget https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip -O /tmp/pb.zip

# Install dependencies for UI
WORKDIR /app/ui
RUN npm install

# Expose the PocketBase and Vite ports
EXPOSE 8090 5173

# Use the script to start the application
ENTRYPOINT ["/app/entrypoint.dev.sh"]
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,29 @@ Use the following credentials for testing the demo:

## Getting Started

Get started by running the project locally, simply follow these steps:
### Development Environment

1. Clone/download the repo.
2. Ensure Docker is installed and running on your system.
3. Start the development environment with Docker:

```bash
docker compose -f docker-compose.dev.yml up --build -d
```
This command will start both the PocketBase backend and the Vite development server for the frontend.

### Production Environment

1. Set the VITE_PROD_PB_URL in the .env file to the server URL where your PocketBase instance will be hosted.
2. Build and deploy the project using Docker:
```bash
docker compose up --build -d
```
This will build and deploy both the backend and frontend using the production-ready settings.

### Manual Deployment

If you prefer not to use Docker, you can manually deploy the application:

1. Clone/download the repo

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.9'

services:
ecourse-app:
build:
context: .
dockerfile: Dockerfile
15 changes: 15 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.9"

services:
ecourse-app:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "8090:8090" # PocketBase port
- "5173:5173" # Vite default port for dev server
volumes:
- ./pb:/app/pb
- ./ui:/app/ui
- /app/ui/node_modules # Avoid overwriting node_modules in the container
command: sh -c "/app/entrypoint.dev.sh"
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.9'

services:
ecourse-app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8090:5173"
restart: unless-stopped
environment:
VITE_PROD_PB_URL: http://127.0.0.1:8090
31 changes: 31 additions & 0 deletions entrypoint.dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Extract PocketBase if not already extracted
if [ ! -f "/app/pb/pocketbase" ]; then
echo "Extracting PocketBase DEV..."
unzip /tmp/pb.zip -d /app/pb
fi

# Start PocketBase in the background
if [ -f "/app/pb/pocketbase" ] && [ -x "/app/pb/pocketbase" ]; then
echo "Starting PocketBase DEV..."
/app/pb/pocketbase serve --http=0.0.0.0:8090 > /proc/1/fd/1 2>/proc/1/fd/2 &
PB_PID=$!
echo "PocketBase started with PID $PB_PID"
else
echo "Error: PocketBase not found or not executable"
ls -la /app/pb
exit 1
fi

# Start the Vite development server
echo "Starting Vite development server..."
cd /app/ui
npm run dev -- --host 0.0.0.0 > /proc/1/fd/1 2>/proc/1/fd/2 &

VITE_PID=$!
echo "Vite started with PID $VITE_PID"

# Wait for both processes to finish
wait $PB_PID
wait $VITE_PID
18 changes: 18 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Extract PocketBase if not already extracted
if [ ! -f "/app/pb/pocketbase" ]; then
echo "Extracting PocketBase PROD..."
unzip /tmp/pb.zip -d /app/pb
fi

# Check if PocketBase is executable
if [ -f "/app/pb/pocketbase" ] && [ -x "/app/pb/pocketbase" ]; then
echo "Starting PocketBase..."
/app/pb/pocketbase serve --http=0.0.0.0:8090
mv /app/ui/dist/* /app/pb/pb_public
else
echo "Error: PocketBase not found or not executable"
ls -la /app/pb
exit 1
fi
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading