Skip to content

Commit

Permalink
Merge pull request #629 from leepeuker/refactor-docker-setup
Browse files Browse the repository at this point in the history
Refactor docker (compose) setup
  • Loading branch information
leepeuker authored Feb 1, 2025
2 parents eec9d95 + c0ecdba commit 300b92e
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 170 deletions.
43 changes: 0 additions & 43 deletions .env.development.example

This file was deleted.

8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# More info here: https://docs.movary.org/configuration/

TIMEZONE="UTC"

TMDB_API_KEY=XXXXXXXXXXX
TMDB_ENABLE_IMAGE_CACHING=1

LOG_LEVEL=warning
38 changes: 0 additions & 38 deletions .env.production.example

This file was deleted.

28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ up:
docker compose up -d

up_mysql:
mkdir -p tmp/db
docker compose up -d mysql
docker compose -f docker-compose.yml -f docker-compose.mysql.yml up -d

up_app:
docker compose up -d app
up_docs:
docker compose -f docker-compose.docs.yml up -d

down:
docker compose down
up_development:
docker compose -f docker-compose.yml -f docker-compose.development.yml up -d

up_development_mysql:
docker compose -f docker-compose.yml -f docker-compose.development.yml -f docker-compose.mysql.yml up -d

reup: down up
down:
docker compose \
-f docker-compose.yml \
-f docker-compose.mysql.yml \
-f docker-compose.docs.yml \
down

logs:
docker compose logs -f

build:
docker compose build --no-cache
make up
build_development:
docker compose -f docker-compose.yml -f docker-compose.development.yml build --no-cache
make up_development
make composer_install
#make db_mysql_create_database
make app_database_migrate
make exec_app_cmd CMD="php bin/console.php storage:link"

Expand Down
10 changes: 10 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
app:
build:
context: ./
dockerfile: ./build/Dockerfile
target: development
args:
- USER_ID=${USER_ID:-1000}
volumes:
- ./:/app
7 changes: 7 additions & 0 deletions docker-compose.docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
mkdocs:
image: squidfunk/mkdocs-material:latest
ports:
- "${HTTP_PORT_DOCS:-8000}:8000"
volumes:
- ./:/docs:ro
25 changes: 25 additions & 0 deletions docker-compose.mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: ${DATABASE_MYSQL_ROOT_PASSWORD:-movary}
MYSQL_USER: ${DATABASE_MYSQL_USER:-movary}
MYSQL_PASSWORD: ${DATABASE_MYSQL_PASSWORD:-movary}
MYSQL_DATABASE: ${DATABASE_MYSQL_NAME:-movary}
MYSQL_PORT: ${DATABASE_MYSQL_PORT:-3306}
volumes:
- movary-database:/var/lib/mysql
ports:
- "${DATABASE_MYSQL_PORT:-3306}:3306"

app:
environment:
DATABASE_MODE: "${DATABASE_MODE:-mysql}"
DATABASE_MYSQL_HOST: "${DATABASE_MYSQL_HOST:-mysql}"
DATABASE_MYSQL_NAME: "${DATABASE_MYSQL_NAME:-movary}"
DATABASE_MYSQL_USER: "${DATABASE_MYSQL_USER:-movary}"
DATABASE_MYSQL_PASSWORD: "${DATABASE_MYSQL_PASSWORD:-movary}"
DATABASE_MYSQL_PORT: "${DATABASE_MYSQL_PORT:-3306}"

volumes:
movary-database:
24 changes: 0 additions & 24 deletions docker-compose.override.yml.example

This file was deleted.

7 changes: 7 additions & 0 deletions docker-compose.overwrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
app:
volumes:
- movary-storage:/app/storage

volumes:
movary-storage:
40 changes: 5 additions & 35 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,11 @@ services:
build:
context: ./
dockerfile: ./build/Dockerfile
target: development
target: production
args:
- USER_ID=$USER_ID
- USER_ID=${USER_ID:-3000}
ports:
- "${HTTP_PORT}:80"
volumes:
- ./:/app

# app_prod:
# build:
# context: ./
# dockerfile: build/Dockerfile
# target: production
# ports:
# - "8080:80"

mysql:
image: mysql:8.0
- "${HTTP_PORT:-80}:80"
environment:
MYSQL_ROOT_PASSWORD: ${DATABASE_MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${DATABASE_MYSQL_USER}
MYSQL_PASSWORD: ${DATABASE_MYSQL_PASSWORD}
MYSQL_DATABASE: ${DATABASE_MYSQL_NAME}
volumes:
- movary-database:/var/lib/mysql
- ./storage/:/tmp/host
ports:
- "${DATABASE_MYSQL_PORT}:3306"

mkdocs:
image: squidfunk/mkdocs-material:latest
ports:
- 8000:8000
volumes:
- ./:/docs:ro

volumes:
movary-database:
TMDB_API_KEY: "${TMDB_API_KEY:-XXXXX}"
TMDB_ENABLE_IMAGE_CACHING: "${TMDB_ENABLE_IMAGE_CACHING:-0}"
47 changes: 28 additions & 19 deletions docs/development/setup.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
### Local development setup

To set up a basic local development environment follow these steps:

- clone the repository
- copy the file `.env.development.example` to `.env` and customize it for your local environment
- make sure the `USER_ID` matches your UID (`echo $UID`)
- adjust `DOCKER_COMPOSE_BIN` if you have the legacy docker-compose binary
- add your `TMDB_API_KEY`
- run `make build` to build the docker containers and to run all necessary steps for an initial setup like
- create the database
- install composer dependencies
- run database migrations
- create the storage symlink
First steps for local development setup:

- Clone the repository
- Copy the file `.env.example` to `.env` and customize it for your local environment
- Set `USER_ID` to the UID owning the local files (`echo $UID`)
- Add your `TMDB_API_KEY`
- Run `make build_development` to create your local development environment
- Build and start the development stage of the docker image from scratch
- Mount project files in to the docker container (changes to files affect application in realtime)
- Install composer dependencies
- Create the database (sqlite on default)
- Run database migrations
- Create the storage symlink

The application should be up-to-date and running locally now.

Use the following cli commands to manage your local environment:

- run `make up` to start all containers again (`build` is only for the initial setup!)
- run `make down` to stop all containers
- run `make reup` to stop and restart all containers
- run `make app_database_migrate` execute the database migrations
- run `make app_jobs_process` process the next job from the queue (see database table `job_queue`)
- `make up` to start the application in production stage using SQLite (using docker volumes)
- `make up_mysql` to start the application in production stage using MySQL (using docker volumes)
- `make up_development` to start the application in development stage using SQLite (mounting local files)
- `make up_development_myqsl` to start the application in development stage using MySQL (mounting local files)
- `make down` to stop all containers
- `make app_database_migrate` execute the database migrations
- `make app_jobs_process` process the next job from the queue (see database table `job_queue`)

### IDE recommendation: PhpStorm

Expand All @@ -44,19 +47,25 @@ Notes:

#### General

##### Description

We use [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for the documentation.

This is part of the default development docker compose setup and can be reached via `http://127.0.0.1:8000`.

To adjust the documentation files look into the `docs` directory and the configuration of MkDocs is in `mkdocs.yml`.

#### Api
##### Setup

Run `make up_docs` to start MkDocs. Set environment variable `HTTP_PORT_DOCS` to adjust host port.

#### REST-Api

Checkout the API docs via the url `http://127.0.0.1/docs/api`.

This uses the schema defined in the file `/docs/openapi.json`. Please adjust openapi schema if you change the API.

### Useful links
#### Useful links

- [Trakt API docs](https://trakt.docs.apiary.io/)
- [TMDB API docs](https://developers.themoviedb.org/3)
Expand Down

0 comments on commit 300b92e

Please sign in to comment.