2020-06-05 13:54:40 +00:00
|
|
|
# Setup your development environment <!-- omit in toc -->
|
|
|
|
|
|
|
|
## Table of contents <!-- omit in toc -->
|
|
|
|
|
|
|
|
- [Introduction](#introduction)
|
|
|
|
- [Prerequisites](#prerequisites)
|
|
|
|
- [Start docker containers](#start-docker-containers)
|
|
|
|
- [Initialize and populate database](#initialize-and-populate-database)
|
|
|
|
- [Install/Update app dependencies](#installupdate-app-dependencies)
|
|
|
|
- [Start hacking](#start-hacking)
|
|
|
|
- [Going Further](#going-further)
|
|
|
|
- [Useful docker / docker-compose commands](#useful-docker--docker-compose-commands)
|
|
|
|
- [Developing inside a Container](#developing-inside-a-container)
|
2021-04-02 17:20:02 +00:00
|
|
|
- [Known issues](#known-issues)
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
Castopod is a web app based on the `php` framework
|
|
|
|
[CodeIgniter 4](https://codeigniter.com).
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
To setup a dev environment, we use [Docker](https://www.docker.com/). A
|
|
|
|
`docker-compose.yml` and `Dockerfile` are included in the project's root folder
|
|
|
|
to help you kickstart your contribution.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
> Know that you don't need any prior knowledge of Docker to follow the next
|
|
|
|
> steps. However, if you wish to use your own environment, feel free to do so!
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-04-23 17:07:01 +00:00
|
|
|
## Pre-requisites
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
0. Install [docker desktop](https://www.docker.com/products/docker-desktop).
|
|
|
|
|
|
|
|
1. Clone castopod project by running:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
git clone https://code.podlibre.org/podlibre/castopod.git
|
|
|
|
```
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
2. Create a `.env` file with the minimum required config to connect the app to
|
2021-04-09 13:43:37 +00:00
|
|
|
the database and use redis as a cache handler:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```ini
|
2021-04-02 17:20:02 +00:00
|
|
|
CI_ENVIRONMENT="development"
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-04-23 17:07:01 +00:00
|
|
|
# By default, this is set to true in the app config.
|
|
|
|
# For development, this must be set to false as it is
|
|
|
|
# on a local environment
|
|
|
|
app.forceGlobalSecureRequests=false
|
|
|
|
|
2021-04-09 13:43:37 +00:00
|
|
|
app.baseURL="http://localhost:8080/"
|
|
|
|
app.mediaBaseURL="http://localhost:8080/"
|
|
|
|
|
|
|
|
app.adminGateway="cp-admin"
|
|
|
|
app.authGateway="cp-auth"
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
database.default.hostname="mariadb"
|
|
|
|
database.default.database="castopod"
|
|
|
|
database.default.username="podlibre"
|
|
|
|
database.default.password="castopod"
|
2021-04-09 13:43:37 +00:00
|
|
|
|
|
|
|
cache.handler="redis"
|
|
|
|
cache.redis.host = "redis"
|
|
|
|
|
|
|
|
# You may not want to use redis as your cache handler
|
|
|
|
# Comment/remove the two lines above and uncomment
|
|
|
|
# the next line for file caching.
|
|
|
|
#cache.handler="file"
|
2020-06-05 13:54:40 +00:00
|
|
|
```
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
> _NB._ You can tweak your environment by setting more environment variables in
|
|
|
|
> your custom `.env` file. See the `env` for examples or the
|
|
|
|
> [CodeIgniter4 User Guide](https://codeigniter.com/user_guide/index.html) for
|
|
|
|
> more info.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
3. Add the repository you've cloned to docker desktop's `Settings` >
|
|
|
|
`Resources` > `File Sharing`.
|
2020-06-05 13:54:40 +00:00
|
|
|
4. Install castopod's php dependencies
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
> The project's php dependencies aren't included in the repository, you have to
|
|
|
|
> download them using the composer service defined in `docker-compose.yml`
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
docker-compose run --rm composer install --ignore-platform-reqs
|
|
|
|
```
|
|
|
|
|
|
|
|
5. Install castopod's js dependencies
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
> The project's js dependencies aren't included in the repository, you have to
|
|
|
|
> download them using the node service defined in `docker-compose.yml`
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
docker-compose run --rm node npm install
|
|
|
|
```
|
|
|
|
|
2020-07-28 15:57:48 +00:00
|
|
|
6. Build assets: javascript, styles, icons and svg images
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-07-28 15:57:48 +00:00
|
|
|
> To generate public assets, you must run the following commands.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
2020-07-28 15:57:48 +00:00
|
|
|
docker-compose run --rm node npm run build:js
|
2020-06-05 13:54:40 +00:00
|
|
|
docker-compose run --rm node npm run build:css
|
2020-07-28 15:57:48 +00:00
|
|
|
docker-compose run --rm node npm run build:icons
|
|
|
|
docker-compose run --rm node npm run build:svg
|
2021-04-02 17:20:02 +00:00
|
|
|
docker-compose run --rm node npm run copy:images
|
|
|
|
docker-compose run --rm node npm run copy:fonts
|
2020-06-05 13:54:40 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Start docker containers
|
|
|
|
|
|
|
|
Go to project's root folder and run:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# starts all services declared in docker-compose.yml file
|
|
|
|
# -d option starts the containers in the background
|
|
|
|
docker-compose up -d
|
|
|
|
|
|
|
|
# See all running processes (you should see 3 processes running)
|
2021-04-14 15:58:40 +00:00
|
|
|
docker-compose ps
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-04-14 15:58:40 +00:00
|
|
|
# Alternatively, you can check all docker processes (you should see composer and npm with an Exited status)
|
2020-06-05 13:54:40 +00:00
|
|
|
docker ps -a
|
2021-04-09 13:43:37 +00:00
|
|
|
|
2020-06-05 13:54:40 +00:00
|
|
|
```
|
|
|
|
|
2021-04-09 13:43:37 +00:00
|
|
|
> The `docker-compose up -d` command will boot 4 containers in the background:
|
2020-06-05 13:54:40 +00:00
|
|
|
>
|
2021-04-09 13:43:37 +00:00
|
|
|
> - `castopod_app`: a php based container with CodeIgniter4 requirements
|
2020-10-12 14:47:21 +00:00
|
|
|
> installed
|
2021-04-09 13:43:37 +00:00
|
|
|
> - `castopod_redis`: a [redis](https://redis.io/) database to handle queries
|
|
|
|
> and pages caching
|
2020-10-12 14:47:21 +00:00
|
|
|
> - `castopod_mariadb`: a [mariadb](https://mariadb.org/) server for persistent
|
|
|
|
> data
|
2021-04-09 13:43:37 +00:00
|
|
|
> - `castopod_phpmyadmin`: a phpmyadmin server to visualize the mariadb
|
|
|
|
> database.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
## Initialize and populate database
|
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
1. Build the database with the migrate command:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# loads the database schema during first migration
|
2020-07-10 12:20:25 +00:00
|
|
|
docker-compose run --rm app php spark migrate -all
|
2020-06-05 13:54:40 +00:00
|
|
|
```
|
|
|
|
|
2020-10-06 15:39:27 +00:00
|
|
|
In case you need to roll back, use this command:
|
|
|
|
|
|
|
|
```
|
|
|
|
# rolls back database schema loading (deletes all tables and their content)
|
|
|
|
docker-compose run --rm app php spark migrate:rollback
|
|
|
|
```
|
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
2. Populate the database with the required data:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-08-21 08:41:09 +00:00
|
|
|
```bash
|
|
|
|
# Populates all required data
|
|
|
|
docker-compose run --rm app php spark db:seed AppSeeder
|
|
|
|
```
|
|
|
|
|
|
|
|
You may also add only data you chose:
|
|
|
|
|
2020-06-05 13:54:40 +00:00
|
|
|
```bash
|
|
|
|
# Populates all categories
|
|
|
|
docker-compose run --rm app php spark db:seed CategorySeeder
|
2020-08-21 08:41:09 +00:00
|
|
|
# Populates all Languages
|
2020-06-05 13:54:40 +00:00
|
|
|
docker-compose run --rm app php spark db:seed LanguageSeeder
|
2020-08-21 08:41:09 +00:00
|
|
|
# Populates all podcasts platforms
|
2020-07-31 16:05:10 +00:00
|
|
|
docker-compose run --rm app php spark db:seed PlatformSeeder
|
2020-08-21 08:41:09 +00:00
|
|
|
# Populates all Authentication data (roles definition…)
|
2020-07-31 16:05:10 +00:00
|
|
|
docker-compose run --rm app php spark db:seed AuthSeeder
|
2020-06-05 13:54:40 +00:00
|
|
|
```
|
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
3. (optionnal) Populate the database with test data:
|
|
|
|
|
|
|
|
```bash
|
2021-04-14 15:58:40 +00:00
|
|
|
# Populates test data (login: admin / password: AGUehL3P)
|
2020-07-31 16:05:10 +00:00
|
|
|
docker-compose run --rm app php spark db:seed TestSeeder
|
2021-04-14 15:58:40 +00:00
|
|
|
# Populates with fake podcast analytics
|
|
|
|
docker-compose run --rm app php spark db:seed FakePodcastsAnalyticsSeeder
|
|
|
|
# Populates with fake website analytics
|
|
|
|
docker-compose run --rm app php spark db:seed FakeWebsiteAnalyticsSeeder
|
2020-07-31 16:05:10 +00:00
|
|
|
```
|
|
|
|
|
2021-04-14 15:58:40 +00:00
|
|
|
TestSeeder will add an active superadmin user with the following credentials:
|
2020-07-31 16:05:10 +00:00
|
|
|
|
|
|
|
- username: **admin**
|
|
|
|
- password: **AGUehL3P**
|
|
|
|
|
2020-06-05 13:54:40 +00:00
|
|
|
## Install/Update app dependencies
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
Castopod uses `composer` to manage php dependencies and `npm` to manage
|
|
|
|
javascript dependencies.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
You can install / update the project's dependencies using both `composer` and
|
|
|
|
`node` services:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# install php dependencies
|
2020-06-26 14:34:52 +00:00
|
|
|
docker-compose run --rm composer install --ignore-platform-reqs
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
# update php dependencies
|
|
|
|
docker-compose run --rm composer update --ignore-platform-reqs
|
|
|
|
```
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
> _NB._ composer commands look for the `composer.json` file to find castopod's
|
|
|
|
> php dependencies, all of which live in the `vendor/` folder. For more info,
|
|
|
|
> check out [Composer documentation](https://getcomposer.org/doc/).
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# install js dependencies
|
|
|
|
docker-compose run --rm node npm install
|
|
|
|
|
|
|
|
# update js dependencies
|
|
|
|
docker-compose run --rm node npm update
|
|
|
|
```
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
> _NB._ npm commands look for the `package.json` file to find castopod's js
|
|
|
|
> dependencies, all of which live in the `node_modules/` folder. For more info,
|
|
|
|
> check out [NPM documentation](https://docs.npmjs.com/).
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
## Start hacking
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
You're all set! Start working your magic by updating the project's files! Help
|
|
|
|
yourself to the
|
|
|
|
[CodeIgniter4 User Guide](https://codeigniter.com/user_guide/index.html) for
|
|
|
|
more insights.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
To see your changes, go to:
|
|
|
|
|
|
|
|
- [localhost:8080](http://localhost:8080/) for the castopod app
|
|
|
|
- [localhost:8888](http://localhost:8888/) for the phpmyadmin interface:
|
|
|
|
|
2021-04-14 15:58:40 +00:00
|
|
|
- username: **podlibre**
|
|
|
|
- password: **castopod**
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## Going Further
|
|
|
|
|
|
|
|
### Useful docker / docker-compose commands
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# monitor the app container
|
2021-04-14 15:58:40 +00:00
|
|
|
docker-compose logs --tail 50 --follow --timestamps app
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-04-09 13:43:37 +00:00
|
|
|
# interact with redis server using included redis-cli command
|
|
|
|
docker exec -it castopod_redis redis-cli
|
|
|
|
|
|
|
|
# monitor the redis container
|
|
|
|
docker-compose logs --tail 50 --follow --timestamps redis
|
|
|
|
|
2020-06-05 13:54:40 +00:00
|
|
|
# monitor the mariadb container
|
2021-04-14 15:58:40 +00:00
|
|
|
docker-compose logs --tail 50 --follow --timestamps mariadb
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
# monitor the phpmyadmin container
|
2021-04-14 15:58:40 +00:00
|
|
|
docker-compose logs --tail 50 --follow --timestamps phpmyadmin
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
# restart docker containers
|
|
|
|
docker-compose restart
|
|
|
|
|
|
|
|
# Destroy all containers, opposite of `up` command
|
|
|
|
docker-compose down
|
2021-04-14 15:58:40 +00:00
|
|
|
|
|
|
|
# Rebuild app container
|
|
|
|
docker-compose build app
|
2020-06-05 13:54:40 +00:00
|
|
|
```
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
Check [docker](https://docs.docker.com/engine/reference/commandline/docker/) and
|
|
|
|
[docker-compose](https://docs.docker.com/compose/reference/) documentations for
|
|
|
|
more insights.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
## Developing inside a Container
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
If you're working in VSCode, you can take advantage of the `./.devcontainer/`
|
|
|
|
folder. It defines a development container with preinstalled VSCode extensions
|
|
|
|
so you don't have to worry about them. The container will be loaded with php,
|
|
|
|
composer and git:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
1. Install the VSCode extension
|
|
|
|
[Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
|
2020-06-05 13:54:40 +00:00
|
|
|
2. `Ctrl/Cmd + Shift + P` > `Open in container`
|
|
|
|
|
|
|
|
The VSCode window will reload inside the dev container.
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
You can check that the required packages are running in the console
|
|
|
|
(`Terminal` > `New Terminal`):
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
php -v
|
|
|
|
|
|
|
|
composer -V
|
|
|
|
|
|
|
|
git version
|
|
|
|
```
|
|
|
|
|
2020-10-12 14:47:21 +00:00
|
|
|
For more info, see
|
|
|
|
[VSCode Remote Containers](https://code.visualstudio.com/docs/remote/containers)
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
## Known issues
|
|
|
|
|
|
|
|
- `Allocation failed - JavaScript heap out of memory` when running `npm install`
|
|
|
|
|
|
|
|
👉 By default, docker might not have access to enough RAM. Allocate more
|
|
|
|
memory and run `npm install` again.
|