-
Notifications
You must be signed in to change notification settings - Fork 60
OTWO-7608 Add docker setup for ohloh-ui #1890
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
ashutok036221
wants to merge
1
commit into
main
Choose a base branch
from
OTWO-7608
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.