Skip to content

Commit

Permalink
Fixed problems with the Docker-based development environment. Closes …
Browse files Browse the repository at this point in the history
…#1244
  • Loading branch information
chartjes committed Feb 28, 2020
1 parent ab75de2 commit d8b5433
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LABEL Description="This is the docker image for OpenCFP, a PHP-based conference
RUN docker-php-ext-install pdo_mysql

ENV CFP_ENV ${CFP_ENV:-development}
ENV CFP_DB_HOST ${CFP_DB_HOST:-"127.0.0.1"}
ENV CFP_DB_HOST ${CFP_DB_HOST:-database}
ENV CFP_DB_PASS ${CFP_DB_PASS:-root}

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,17 @@ mail:
auth_mode: ~
```

As the project migrates from using Eloquent to Doctrine, you also need to edit the following files to ensure the database
credentials are correct:
As the project migrates from using Eloquent to Doctrine you also need to edit the following files to ensure the database
credentials are correct, creating a version of the modified file in the same location but without the `.dist` suffix.

`resources/config/config_testing.yml`
`resources/config/config_development.yml`
`resources/config/config_production.yml`
`resources/config/config_testing.yml.dist`
`resources/config/config_development.yml.dist`
`resources/config/config_production.yml.dist`


### [Running behind a trusted proxy](#run-trusted-proxy)

If you are running OpenCFP behing a proxy server which adds X-Forwarded-For headers (this could be a cloud based load balancer or a service such as Cloudflare) you will need to set the environment variable TRUST_PROXIES to true this will ensure that OpenCFP trusts the headers set by these proxies for the original IP address and ssl mode. Setting this will trust these headers regardless of where the original request originates, so it's advisable to either lock down your instance so that only the trusted proxy can access it or modify the list of trusted proxies in the index.php file to only include the ip addresses of your proxies.
If you are running OpenCFP behind a proxy server which adds X-Forwarded-For headers (this could be a cloud based load balancer or a service such as Cloudflare) you will need to set the environment variable TRUST_PROXIES to true this will ensure that OpenCFP trusts the headers set by these proxies for the original IP address and ssl mode. Setting this will trust these headers regardless of where the original request originates, so it's advisable to either lock down your instance so that only the trusted proxy can access it or modify the list of trusted proxies in the index.php file to only include the ip addresses of your proxies.


### [OpenCFP Central](#opencfp-central)
Expand Down Expand Up @@ -365,39 +365,36 @@ settings that machine might have that could differ from the machine used for wri
#### Build & Run the image

Please remember to edit the file `config/docker.yml.dist` to match your environment, then you can build your own
docker image by executing:
docker image by using a [docker-compose](https://docs.docker.com/compose/install/) command which will build the
image and run the containers automatically for you:

```
$ ./.docker/build latest
$ docker-compose -f docker-compose.yml.dist up --build -d
```

And the result will be an image called `opencfp/opencfp:latest`.
So now if you head over to `http://localhost:8080` you will be greeted with a running version of OpenCFP in
`development` mode.

Or if you like you can run [docker-compose](https://docs.docker.com/compose/install/) command which will build the
image and run the containers automatically for you:
After building and running the Docker image you'll need to use the docker-compose [exec](https://docs.docker.com/compose/reference/exec/)
command to configure things inside the container:

```bash
$ docker-compose -f docker-compose.yml.dist exec app composer run setup-docker
```
$ docker-compose -f docker-compose.yml.dist up --build -d
```

So now if you head over to `http://localhost:8080` you will be greeted with a running version of OpenCFP.

After building and running the Docker image you'll need to [Run Migrations](#run-migrations) and [Add an Admin User](#user-management) before logging-in.
and then [Add an Admin User](#user-management) before logging-in.

#### Run PHP commands within the Container

To run any command in the app container you can use the docker-compose
[exec](https://docs.docker.com/compose/reference/exec/) command, for example to run the `setup` script you run:
[exec](https://docs.docker.com/compose/reference/exec/) command, for example to clear the cache for your
environment:

```bash
$ docker-compose -f docker-compose.yml.dist exec app composer run setup-env
$ docker-compose -f docker-compose.yml.dist exec app bin/console cache:clear
```
OR

```bash
$ docker-compose -f docker-compose.yml.dist exec app ./script/setup
```

#### Running the image directly

You can run the image (after you build it) and link it to an already running database container using the docker
Expand All @@ -412,7 +409,7 @@ Where `database` is the name of the running database container.

#### Access MySQL container

To access MySQL you can use the following information:
To access the MySQL container from outside the application container you can use the following information:

- **Host**: 127.0.0.1
- **User**: root
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
]
},
"scripts": {
"setup-docker": "./script/docker",
"fix": "php vendor/bin/php-cs-fixer fix --config=.php_cs.dist --using-cache=no",
"make": "make",
"migrate": "./script/migrate",
Expand Down
6 changes: 3 additions & 3 deletions config/development.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ application:
user_image_size: 300

database:
host: 127.0.0.1
host: database
database: cfp
dsn: mysql:dbname=cfp;host=127.0.0.1
dsn: mysql:dbname=cfp;host=database
user: root
password: ~
password: root

log:
level: debug
Expand Down
39 changes: 0 additions & 39 deletions docker-compose.yml.dist

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ oneup_flysystem:

doctrine:
dbal:
url: mysql://root:@127.0.0.1:3306/cfp
url: mysql://root:root@database:3306/cfp
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ oneup_flysystem:

doctrine:
dbal:
url: mysql://root:@127.0.0.1:3306/cfp
url: mysql://root:root@database:3306/cfp
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
Expand Down
29 changes: 29 additions & 0 deletions resources/config/config_production.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
imports:
- { resource: config.yml }

oneup_flysystem:
adapters:
uploads:
local:
directory: "%kernel.root_dir%/../web/uploads"

filesystems:
uploads:
adapter: uploads
alias: upload_filesystem

doctrine:
dbal:
url: mysql://root:root@database:3306/cfp
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
orm:
auto_mapping: true
auto_generate_proxy_classes: true
mappings:
OpenCFP\Domain\Entity:
type: annotation
dir: "%kernel.root_dir%/../src/Domain/Entity"
prefix: OpenCFP\Domain\Entity

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ swiftmailer:

doctrine:
dbal:
url: mysql://cfp_test:cfp_test@127.0.0.1:3306/cfp_test
url: mysql://root:root@127.0.0.1:3306/cfp
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
Expand Down
4 changes: 4 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ if [ ! -f "config/$CFP_ENV.yml" ]; then
echo "Missing config/$CFP_ENV.yml, be sure to copy from config/$CFP_ENV.yml.dist and update config"
exit 1
fi


echo "==> Clearing caches..."
bin/console --env=$CFP_ENV cache:clear
23 changes: 23 additions & 0 deletions script/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# script/docker: Set things up so the app will run in the Docker container

set -e

cd "$(dirname "$0")/.."

echo "==> Installing dependencies..."
if command -v composer &>/dev/null; then
composer install
elif [ -f "composer.phar" ]; then
php composer.phar install
else
echo "ERROR: Composer path unknown. Please install composer or download composer.phar"
exit 1
fi

echo "==> Clearing caches..."
bin/console --env=$CFP_ENV cache:clear

echo "==> Running migrations..."
bin/console doctrine:migrations:migrate --env=$CFP_ENV

0 comments on commit d8b5433

Please sign in to comment.