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
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Git
.git
.gitignore

# Docker files (not needed inside container)
Dockerfile*
docker-compose*.yml
.dockerignore
DOCKER.md

# Development/temp files
tmp/
log/
.byebug_history
.bundle
coverage/

# IDE
.idea/
.vscode/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Test artifacts
test/reports/

# Node (if any)
node_modules/
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Docker build settings - disable BuildKit (causes hangs with docker-compose v1)
DOCKER_BUILDKIT=0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required as it is exported in the Makefile.

COMPOSE_DOCKER_CLI_BUILD=0

DB_ENCODING = SQL_ASCII
DB_SEARCH_PATH = 'oh, fis, public'

Expand Down
159 changes: 159 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Docker Setup for Ohloh UI

## Quick Start (Development)

```bash
# Using Makefile (recommended - handles cleanup automatically)
make up-build # First time: build and start all services
make up # Subsequent runs (no rebuild)

# Or using docker-compose directly
docker-compose -f docker-compose.dev.yml up --build

# Access the app at: http://localhost:3000
```

The first run automatically:
- Creates the database
- Loads the schema from `db/structure.sql`
- Starts all services

## Subsequent Runs

```bash
# Just start (no rebuild needed, database persists)
make up

# Or in background
make up-d
```

You should see "Database ready, starting application..." on subsequent runs.

## Makefile Commands

The Makefile provides shortcuts with automatic cleanup of stuck processes:

| Command | Description |
|---------|-------------|
| `make up-build` | Clean, build, and start (recommended for first run) |
| `make up` | Start services (no rebuild) |
| `make up-d` | Start in background |
| `make down` | Stop services |
| `make restart` | Stop and start |
| `make build` | Build images only |
| `make clean` | Full cleanup (removes volumes/data) |
| `make logs` | Follow all logs |
| `make logs-web` | Follow web logs only |
| `make shell` | Bash shell in web container |
| `make console` | Rails console |
| `make test` | Run tests |

## Services and Ports

| Service | Port | Description |
|----------|------|-----------------------|
| web | 3000 | Rails application |
| postgres | 5432 | PostgreSQL database |
| redis | 6379 | Redis (cache/sidekiq) |

## Useful Commands

```bash
# View logs (or: make logs-web)
docker-compose -f docker-compose.dev.yml logs -f web

# Rails console (or: make console)
docker-compose -f docker-compose.dev.yml exec web bundle exec rails c

# Run tests (or: make test)
docker-compose -f docker-compose.dev.yml exec web bundle exec rake test

# Stop services (or: make down)
docker-compose -f docker-compose.dev.yml down

# Stop and reset database (or: make clean)
docker-compose -f docker-compose.dev.yml down -v
```

## Reset Database

To start fresh (removes all data):

```bash
docker-compose -f docker-compose.dev.yml down -v
docker-compose -f docker-compose.dev.yml up --build
```

## Production Build

```bash
# Build production image
docker build -f Dockerfile.prod -t ohloh-ui:latest .

# Run production container
docker run -d \
-p 3000:3000 \
-e RAILS_ENV=production \
-e SECRET_KEY_BASE=your_secret_key \
-e DB_HOST=your_db_host \
-e DB_NAME=your_db_name \
-e DB_USERNAME=your_db_user \
-e DB_PASSWORD=your_db_password \
-e REDIS_HOST=your_redis_host \
ohloh-ui:latest
```

## Troubleshooting

### Build seems stuck at "Building web"

**First, check for stuck processes** (most common cause):
```bash
# Kill any stuck docker build processes
make clean-builds

# Or manually:
pkill -f "docker build.*ohloh-ui"
pkill -f "docker-compose.*ohloh-ui.*build"
```

If no stuck processes, the initial build can take 15-20+ minutes due to gem installation. To see detailed progress:

```bash
# Build with verbose output
docker-compose -f docker-compose.dev.yml build --progress=plain web
```

Common slow steps:
- `bundle install` - compiles native extensions (nokogiri, pg, imagemagick)
- Package downloads from rubygems.org

If builds are consistently slow:
1. **Increase Docker resources** - Docker Desktop → Settings → Resources → increase CPU/RAM
2. **Check network** - slow gem downloads can cause timeouts
3. **Note**: BuildKit is disabled by default (in `.env`) because it causes hangs with docker-compose v1

### Database connection errors

If you see "connection refused" errors:
- Ensure the `db` service is healthy: `docker-compose -f docker-compose.dev.yml ps`
- Check postgres logs: `docker-compose -f docker-compose.dev.yml logs db`
- Try restarting: `docker-compose -f docker-compose.dev.yml restart db`

### Port already in use

If port 3000, 5432, or 6379 is already in use:
```bash
# Find what's using the port
lsof -i :3000

# Or change the port in docker-compose.dev.yml (e.g., "3001:3000")
```

## Environment Variables

The docker-compose.dev.yml sets defaults for local development. For production, configure:
- `DB_HOST`, `DB_NAME`, `DB_USERNAME`, `DB_PASSWORD` - PostgreSQL connection
- `REDIS_HOST`, `REDIS_PORT` - Redis connection
- `SECRET_KEY_BASE` - Rails secret (required for production)
62 changes: 62 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Dockerfile for Ohloh UI (OpenHub)
# Ruby on Rails 6.1 application with PostgreSQL

FROM ruby:3.1.7-slim-bullseye

# Set environment variables
ENV RAILS_ENV=development \
BUNDLE_PATH=/usr/local/bundle \
BUNDLE_WITHOUT=production:staging \
APP_HOME=/app \
RAILS_LOG_TO_STDOUT=true

# Install PostgreSQL 14 client (to match server version) and system dependencies
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
curl \
gnupg2 \
lsb-release \
&& echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg \
&& apt-get update -qq \
&& apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
postgresql-client-14 \
imagemagick \
libmagickwand-dev \
libsodium-dev \
libxml2-dev \
libxslt1-dev \
git \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR $APP_HOME

# Install bundler
RUN gem install bundler:2.3.6

# Copy Gemfile first for better layer caching
COPY Gemfile Gemfile.lock ./

# Install gems (verbose output to track progress)
RUN bundle install --jobs 4 --retry 3 --verbose

# Copy the rest of the application
COPY . .

# Copy and set entrypoint
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Expose port 3000 (Puma default)
EXPOSE 3000

# Use entrypoint for database setup
ENTRYPOINT ["docker-entrypoint.sh"]

# Default command - start Puma server
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.PHONY: build up down restart clean logs shell console test

# Disable BuildKit - causes hangs with docker-compose v1
export DOCKER_BUILDKIT=0

# Development commands
build: clean-builds
docker-compose -f docker-compose.dev.yml build

up:
docker-compose -f docker-compose.dev.yml up

up-build: clean-builds
docker-compose -f docker-compose.dev.yml up --build

up-d:
docker-compose -f docker-compose.dev.yml up -d

down:
docker-compose -f docker-compose.dev.yml down

restart: down up

# Clean up stuck build processes before building
clean-builds:
@echo "Cleaning up any stuck docker build processes..."
@pkill -f "docker build.*ohloh-ui" 2>/dev/null || true
@pkill -f "docker-compose.*ohloh-ui.*build" 2>/dev/null || true
@docker builder prune -f 2>/dev/null || true

# Full cleanup (removes volumes too)
clean: down
docker-compose -f docker-compose.dev.yml down -v --remove-orphans
docker system prune -f

# Logs
logs:
docker-compose -f docker-compose.dev.yml logs -f

logs-web:
docker-compose -f docker-compose.dev.yml logs -f web

# Shell access
shell:
docker-compose -f docker-compose.dev.yml exec web bash

console:
docker-compose -f docker-compose.dev.yml exec web bundle exec rails c

# Tests
test:
docker-compose -f docker-compose.dev.yml exec web bundle exec rake test
6 changes: 5 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A Ruby on Rails application for the Open Hub platform.
- [Testing](#testing)
- [Pull Request Checks](#pull-request-checks)
- [Contributing](#contributing)

- [Running the Application using Docker](#running-the-application-docker)
## 🔧 Prerequisites

Before you begin, ensure you have the following installed:
Expand Down Expand Up @@ -164,6 +164,10 @@ This includes:
After all the successful checks, CI pipeline will have success message like
`All checks has been passed`.

### Running the Application using Docker
You can also run the application using Docker if you prefer to set up ohloh-ui locally without installing all the required packages.
Refer to DOCKER.md for detailed instructions.

## 🤝 Contributing

1. Create a feature branch from `main`
Expand Down
Loading
Loading