Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .devcontainer/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ensure shell scripts always use LF line endings (required for Linux/Codespaces)
*.sh text eol=lf
216 changes: 216 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# dotCMS GitHub Codespaces Configuration

This directory contains the configuration for running dotCMS in GitHub Codespaces, providing a complete development environment in the cloud.

## What's Included

The Codespaces environment includes:

- **dotCMS** (latest) - Latest release
- **PostgreSQL 18** with pgvector extension
- **OpenSearch 1.x** - Search and indexing engine
- **Java 21** - Development runtime
- **Node.js LTS** - Frontend tooling
- **Maven** - Build tool
- **GitHub CLI** - Repository management
- **Docker-in-Docker** - Container management

## Getting Started

### 1. Create a Codespace

There are three ways to create a Codespace:

**From GitHub Web UI**
1. Navigate to the repository on github.com
2. Click the green "Code" button
3. Select "Codespaces" tab
4. Click "Create codespace on [branch-name]"

### 2. Wait for Initialization

The first startup takes **5-10 minutes** as it:
- Downloads Docker images (~2-3 minutes)
- Initializes PostgreSQL database (~2-3 minutes)
- Starts OpenSearch (~1-2 minutes)
- Starts dotCMS and loads initial data (~3-5 minutes)

You'll see a notification when dotCMS is ready!

### 3. Access dotCMS

Once ready, click on the "Ports" tab in VS Code and you'll see:

| Port | Service | URL |
|------|---------|-----|
| 8082 | dotCMS HTTP | `http://localhost:8082` |
| 8443 | dotCMS HTTPS | `https://localhost:8443` |
| 9200 | OpenSearch | `http://localhost:9200` |
| 5432 | PostgreSQL | `localhost:5432` |

**Default Admin Credentials:**
- Username: `admin@dotcms.com`
- Password: `admin`

### Debugging in Codespaces

GitHub Codespaces fully supports debugging Java applications with breakpoints using VS Code's built-in debugger.

#### Debugging Running dotCMS Container

To debug the live dotCMS application running in Docker:

1. **Enable remote debugging** in docker-compose.yml:

Edit `docker/docker-compose-examples/single-node-demo-site/docker-compose.yml`:
```yaml
dotcms:
image: dotcms/dotcms:latest
environment:
CMS_JAVA_OPTS: '-Xmx1g -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'
ports:
- "8082:8082"
- "8443:8443"
- "5005:5005" # Debug port
```

2. **Restart dotCMS to apply changes:**
```bash
cd docker/docker-compose-examples/single-node-demo-site
docker-compose down
docker-compose up -d
```

3. **Forward the debug port** (Codespaces does this automatically, but verify):
- Check the **Ports** tab in VS Code
- Ensure port **5005** is forwarded

4. **Attach debugger:**
- Open **Run and Debug** panel (Cmd/Ctrl + Shift + D)
- Select **"Debug dotCMS (Docker)"**
- Click the green play button

5. **Set breakpoints** in your Java source code
6. **Trigger the code path** by accessing dotCMS in the browser
7. **Debugger pauses** at your breakpoints!

### Working with the Database

```bash
# Connect to PostgreSQL
docker exec -it db psql -U dotcmsdbuser -d dotcms
```

## Troubleshooting

### dotCMS won't start

**Check if services are running:**
```bash
docker ps
```

You should see three containers: `dotcms`, `db`, and `opensearch`.

**Check logs for errors:**
```bash
docker logs dotcms
docker logs db
docker logs opensearch
```

**Restart services:**
```bash
cd /workspace
docker-compose -f docker/docker-compose-examples/single-node-demo-site/docker-compose.yml restart
```

## Advanced Configuration

### Changing the dotCMS Docker Image

The dotCMS Docker image is configured in the docker-compose file:

**Location:** `docker/docker-compose-examples/single-node-demo-site/docker-compose.yml`

#### How to Change the Image

1. **Edit the docker-compose file:**
```bash
# Open in your editor
code docker/docker-compose-examples/single-node-demo-site/docker-compose.yml

# Or use vim/nano
vim docker/docker-compose-examples/single-node-demo-site/docker-compose.yml
```

2. **Locate line 48 and change the image:**
```yaml
dotcms:
image: dotcms/dotcms:YOUR_DESIRED_VERSION
```

3. **Apply the changes:**
```bash
cd docker/docker-compose-examples/single-node-demo-site

# Stop current services
docker-compose down

# Pull the new image
docker-compose pull dotcms

# Start with new image
docker-compose up -d
```

4. **Verify the new image is running:**
```bash
docker ps | grep dotcms
docker logs -f dotcms
```

#### Finding Available Images

To see all available dotCMS images on Docker Hub:
```bash
# Search Docker Hub
docker search dotcms/dotcms

# View tags on Docker Hub website
# https://hub.docker.com/r/dotcms/dotcms/tags
```

#### Important Notes

- **Data persistence:** Your database and shared data are stored in Docker volumes and will persist across image changes
- **Breaking changes:** Major version upgrades may require database migrations
- **Testing:** Always test image changes in a development environment first
- **Rollback:** If something goes wrong, change back to the previous image and restart

### Customizing Environment Variables

In the same docker-compose.yml file, you can modify dotCMS settings (starting at line 49):

```yaml
dotcms:
environment:
CMS_JAVA_OPTS: '-Xmx1g' # Java heap size
DOT_INITIAL_ADMIN_PASSWORD: 'admin' # Admin password
CUSTOM_STARTER_URL: 'https://...' # Starter site URL
# Add more environment variables as needed
```

Common environment variables:
- `CMS_JAVA_OPTS`: JVM options (memory, GC settings)
- `DOT_INITIAL_ADMIN_PASSWORD`: Initial admin password
- `CUSTOM_STARTER_URL`: Custom starter site ZIP URL
- `DOT_DOTCMS_CLUSTER_ID`: Cluster identifier
- `DOT_ES_ENDPOINTS`: OpenSearch endpoint URL

After making any changes, restart the services:
```bash
cd docker/docker-compose-examples/single-node-demo-site
docker-compose down
docker-compose up -d
```
144 changes: 144 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"name": "dotCMS Development Environment",

// Use a base Ubuntu image with development tools
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",

// REQUIRED for docker-in-docker
"privileged": true,

// Forward ports for dotCMS, OpenSearch, PostgreSQL, and Debug
"forwardPorts": [
8082, // dotCMS HTTP
8443, // dotCMS HTTPS
9200, // OpenSearch REST API
9600, // OpenSearch Performance Analyzer
5432, // PostgreSQL (for direct DB access if needed)
5005 // Java Debug Port (JDWP)
],

// Port attributes for better UX
"portsAttributes": {
"8082": {
"label": "dotCMS HTTP",
"onAutoForward": "notify",
"protocol": "http"
},
"8443": {
"label": "dotCMS HTTPS",
"onAutoForward": "notify",
"protocol": "https"
},
"9200": {
"label": "OpenSearch API",
"onAutoForward": "silent",
"protocol": "http"
},
"9600": {
"label": "OpenSearch Performance",
"onAutoForward": "silent",
"protocol": "http"
},
"5432": {
"label": "PostgreSQL",
"onAutoForward": "silent"
},
"5005": {
"label": "Java Debug (JDWP)",
"onAutoForward": "silent"
}
},

// Features to add to the dev container
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "21",
"jdkDistro": "tem",
"installMaven": "true"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "20",
"nodeGypDependencies": true,
"nvmVersion": "latest"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "latest",
"ppa": true
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"installOhMyZsh": true,
"upgradePackages": true,
"username": "vscode",
"userUid": "1000",
"userGid": "1000"
}
},

// VS Code customizations
"customizations": {
"vscode": {
"extensions": [
// Java development
"vscjava.vscode-java-pack",
"vscjava.vscode-maven",
"vscjava.vscode-java-debug",
"vscjava.vscode-java-test",

// Web development
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"angular.ng-template",

// Docker & Docker Compose
"ms-azuretools.vscode-docker",

// Git
"eamodio.gitlens",

// REST API testing
"humao.rest-client",

// YAML support
"redhat.vscode-yaml",

// Additional useful extensions
"streetsidesoftware.code-spell-checker",
"EditorConfig.EditorConfig"
],
"settings": {
"maven.executable.path": "mvn",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"files.eol": "\n",
"terminal.integrated.defaultProfile.linux": "zsh"
}
}
},

// Post-create command to set up the environment and start services
"postCreateCommand": "bash .devcontainer/setup.sh",

// Post-start command to show helpful information
"postStartCommand": "bash .devcontainer/post-start.sh",

// Environment variables
"remoteEnv": {
"PATH": "${containerEnv:PATH}:/usr/local/sdkman/candidates/java/current/bin"
},

// Run as vscode user (non-root)
"remoteUser": "vscode",

// Container environment variables
"containerEnv": {
"DOCKER_BUILDKIT": "1",
"COMPOSE_DOCKER_CLI_BUILD": "1"
}
}
Loading
Loading