Skip to content

Commit

Permalink
Made docker dev setup more accessible, added Quickstart to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
machisuji committed Nov 27, 2020
1 parent 175fed8 commit be2c5ed
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
36 changes: 36 additions & 0 deletions bin/compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e

if [ -f .env ]; then
export `grep -v '^#' .env | xargs`
else
export DEV_UID=$(id -u) DEV_GID=$(id -g) LOCAL_DEV_CHECK=1
fi

COMPOSE_FILE=docker-compose.yml

if [ $# -eq 0 ]; then
echo "Usage: bin/compose <command> [args*]"
echo
echo "Commands:"
echo " setup - Has to be run once intially. Installs backend and frontend dependencies. "
echo " start - Starts both backend and frontend in the background. Acccess via http://localhost:3000/ by default."
echo " run - Starts the frontend in the backround and backend in the foreground. Useful for debugging using pry."
echo " * - Everything else will be passed straight to \`docker-compose\`."
echo

exit 1
elif [[ "$@" = "start" ]]; then
# backend will be started automatically as a dependency of the frontend
docker-compose -f $COMPOSE_FILE up -d frontend
elif [[ "$@" = "run" ]]; then
docker-compose -f $COMPOSE_FILE up -d frontend
docker-compose -f $COMPOSE_FILE stop backend
docker-compose -f $COMPOSE_FILE run -p ${PORT:-3000}:3000 backend # run backend in TTY so you can debug using pry for instance
elif [[ "$1" = "setup" ]]; then
docker-compose -f $COMPOSE_FILE run backend setup
yes no | docker-compose -f $COMPOSE_FILE run frontend npm install
else
docker-compose -f $COMPOSE_FILE $*
fi
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ services:
volumes:
- "pgdata:/var/lib/postgresql/data"
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USERNAME:-postgres}
POSTGRES_PASSWORD: ${DB_PASSWORD:-postgres}
POSTGRES_DB: ${DB_DATABASE:-openproject}
networks:
- network

Expand All @@ -66,7 +66,7 @@ services:
RAILS_CACHE_STORE: memcache
OPENPROJECT_CACHE__MEMCACHE__SERVER: cache:11211
OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
DATABASE_URL: postgresql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}
DATABASE_URL: postgresql://${DB_USERNAME:-postgres}:${DB_PASSWORD:-postgres}@${DB_HOST:-db}:${DB_PORT:-5432}/${DB_DATABASE:-openproject}
volumes:
- ".:/home/dev/openproject"
- "opdata:/var/openproject/assets"
Expand Down
45 changes: 42 additions & 3 deletions docs/development/development-environment-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

The quickest way to get started developing OpenProject is to use the docker setup.

## Requirements

* docker

And nothhing else!

## Quickstart

To get right into it and just start the application you can just do the following:

```
git clone https://github.com/opf/openproject.git
cd openproject
bin/compose setup
bin/compose start
```

Once the containers are done booting you can access the application under http://localhost:3000.

If there is an `.env` file (see below) `bin/compose` will source it.
More details and options follow in the next section.

## Setup

### 1) Checkout the code
Expand All @@ -17,7 +39,7 @@ This will checkout the dev branch in `openproject`. **Change into that directory
If you have OpenProject checked out already make sure that you do not have a `config/database.yml`
as that will interfere with the database connection inside of the docker containers.

### 3) Configure environment
### 2) Configure environment

Copy the env example to `.env`

Expand All @@ -28,7 +50,7 @@ cp .env.example .env
Afterwards, set the environment variables to your liking. `DEV_UID` and `DEV_GID` are required to be set so your project
directory will not end up with files owned by root.

### 2) Setup database and install dependencies
### 3) Setup database and install dependencies

```
# Start the database. It needs to be running to run migrations and seeders
Expand All @@ -41,7 +63,7 @@ docker-compose run frontend npm i
docker-compose run backend setup
```

### 3) Start the stack
### 4) Start the stack

The docker compose file also has the test containers defined. The easiest way to start only the development stack, use

Expand Down Expand Up @@ -113,3 +135,20 @@ file to see which port each browser container is exposed on. The password is `se
Running the docker images will change some of your local files in the mounted code directory.
The file `frontend/npm-shrinkwrap.json` may be modified.
You can just reset these changes if you want to commit something or pull the latest changes.

## Debugging

It's common to just start a debugger whithin ruby code using `binding.pry`.
This **does not work** with the application running as shown above.

If you want to be able to do that, you can, however, simply run the following:

```
bin/compose run
```

If the frontend container is not running yet, it will be started.
If the backend container is already running, it will be stopped.
Instead it will be started in the foreground.
This way you can debug using pry just as if you had started the server locally using `rails s`.
You can stop it simply with Ctrl + C too.

0 comments on commit be2c5ed

Please sign in to comment.