2020-06-05 13:54:40 +00:00
|
|
|
# Setup your development environment <!-- omit in toc -->
|
|
|
|
|
|
|
|
## Table of contents <!-- omit in toc -->
|
|
|
|
|
|
|
|
- [Introduction](#introduction)
|
2021-05-06 14:00:48 +00:00
|
|
|
- [Pre-requisites](#pre-requisites)
|
|
|
|
- [(recommended) Develop inside the app Container with VSCode](#recommended-develop-inside-the-app-container-with-vscode)
|
|
|
|
- [(not-recommended) Develop outside the app container](#not-recommended-develop-outside-the-app-container)
|
|
|
|
- [Install Castopod Host's dependencies](#install-castopod-hosts-dependencies)
|
2020-06-05 13:54:40 +00:00
|
|
|
- [Initialize and populate database](#initialize-and-populate-database)
|
|
|
|
- [Start hacking](#start-hacking)
|
|
|
|
- [Going Further](#going-further)
|
|
|
|
- [Useful docker / docker-compose commands](#useful-docker--docker-compose-commands)
|
2021-04-02 17:20:02 +00:00
|
|
|
- [Known issues](#known-issues)
|
2021-05-24 10:08:15 +00:00
|
|
|
- [Allocation failed - JavaScript heap out of memory](#allocation-failed---javascript-heap-out-of-memory)
|
|
|
|
- [Files created inside container are attributed to root locally (Linux)](#files-created-inside-container-are-attributed-to-root-locally-linux)
|
2020-06-05 13:54:40 +00:00
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
Castopod Host is a web app based on the `php` framework
|
2020-10-12 14:47:21 +00:00
|
|
|
[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
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
0. Install [docker](https://docs.docker.com/get-docker).
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
1. Clone Castopod Host project by running:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
git clone https://code.podlibre.org/podlibre/castopod-host.git
|
|
|
|
```
|
2020-06-05 13:54:40 +00:00
|
|
|
|
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
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```ini
|
|
|
|
CI_ENVIRONMENT="development"
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +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-23 17:07:01 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
app.baseURL="http://localhost:8080/"
|
|
|
|
app.mediaBaseURL="http://localhost:8080/"
|
2021-04-09 13:43:37 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
app.adminGateway="cp-admin"
|
|
|
|
app.authGateway="cp-auth"
|
2021-04-09 13:43:37 +00:00
|
|
|
|
2021-05-06 14:00:48 +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
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
cache.handler="redis"
|
|
|
|
cache.redis.host = "redis"
|
2021-04-09 13:43:37 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# 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
|
|
|
|
2021-05-06 14:00:48 +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
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
3. (for docker desktop) Add the repository you've cloned to docker desktop's
|
|
|
|
`Settings` > `Resources` > `File Sharing`
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-24 10:08:15 +00:00
|
|
|
## (recommended) Develop inside the app Container with VSCode
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
If you're working in VSCode, you can take advantage of the `.devcontainer/`
|
|
|
|
folder. It defines a development environment (dev container) with preinstalled
|
|
|
|
requirements and VSCode extensions so you don't have to worry about them. All
|
|
|
|
required services will be loaded automagically!
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
1. Install the VSCode extension
|
|
|
|
[Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
|
|
|
|
2. `Ctrl/Cmd + Shift + P` > `Open in container`
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
> The VSCode window will reload inside the dev container. It may take a long
|
|
|
|
> time on first load as it is building all necessary services.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
3. You're all set! 🎉
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
You're now **inside the dev container**, you may use the VSCode console
|
|
|
|
(`Terminal` > `New Terminal`) to run any command:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
# PHP is installed
|
|
|
|
php -v
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# Composer is installed
|
|
|
|
composer -V
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# npm is installed
|
|
|
|
npm -v
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# git is installed
|
|
|
|
git version
|
|
|
|
```
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
For more info, see
|
|
|
|
[VSCode Remote Containers](https://code.visualstudio.com/docs/remote/containers)
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-24 10:08:15 +00:00
|
|
|
## (not-recommended) Develop outside the app container
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
You do not wish to use the VSCode devcontainer? No problem!
|
2021-04-09 13:43:37 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
1. Start docker containers manually:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
Go to project's root folder and run:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
# starts all services declared in docker-compose.yml file
|
|
|
|
# -d option starts the containers in the background
|
|
|
|
docker-compose up -d
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# See all running processes (you should see 3 processes running)
|
|
|
|
docker-compose ps
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# Alternatively, you can check all docker processes
|
|
|
|
docker ps -a
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```
|
2020-10-06 15:39:27 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
> The `docker-compose up -d` command will boot 4 containers in the
|
|
|
|
> background:
|
|
|
|
>
|
2021-05-24 10:08:15 +00:00
|
|
|
> - `castopod-host_app`: a php based container with CodeIgniter4 requirements
|
2021-05-06 14:00:48 +00:00
|
|
|
> installed
|
2021-05-24 10:08:15 +00:00
|
|
|
> - `castopod-host_redis`: a [redis](https://redis.io/) database to handle
|
2021-05-06 14:00:48 +00:00
|
|
|
> queries and pages caching
|
2021-05-24 10:08:15 +00:00
|
|
|
> - `castopod-host_mariadb`: a [mariadb](https://mariadb.org/) server for
|
2021-05-06 14:00:48 +00:00
|
|
|
> persistent data
|
2021-05-24 10:08:15 +00:00
|
|
|
> - `castopod-host_phpmyadmin`: a phpmyadmin server to visualize the mariadb
|
2021-05-06 14:00:48 +00:00
|
|
|
> database.
|
2020-10-06 15:39:27 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
2. Run any command by prefixing them with `docker-compose run --rm app`:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
# use PHP
|
|
|
|
docker-compose run --rm app php -v
|
2020-08-21 08:41:09 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# use Composer
|
|
|
|
docker-compose run --rm app composer -V
|
2020-08-21 08:41:09 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# use npm
|
|
|
|
docker-compose run --rm app npm -v
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# use git
|
|
|
|
docker-compose run --rm app git version
|
|
|
|
```
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
## Install Castopod Host's dependencies
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
1. Install php dependencies with [Composer](https://getcomposer.org/)
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
composer install
|
|
|
|
```
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
> **Note:**
|
|
|
|
>
|
|
|
|
> The php dependencies aren't included in the repository. Composer will check
|
|
|
|
> the `composer.json` and `composer.lock` files to download the packages with
|
|
|
|
> the right versions. The dependencies will live under the `vendor/` folder.
|
|
|
|
> For more info, check out the
|
|
|
|
> [Composer documentation](https://getcomposer.org/doc/).
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
2. Install javascript dependencies with [npm](https://www.npmjs.com/)
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
npm install
|
|
|
|
```
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
> **Note:**
|
|
|
|
>
|
|
|
|
> The javascript dependencies aren't included in the repository. Npm will
|
|
|
|
> check the `package.json` and `package.lock` files to download the packages
|
|
|
|
> with the right versions. The dependencies will live under the `node_module`
|
|
|
|
> folder. For more info, check out the
|
|
|
|
> [NPM documentation](https://docs.npmjs.com/).
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
3. Generate static assets:
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
```bash
|
|
|
|
# build all assets at once
|
|
|
|
npm run build:dev
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
# generate/copy specific assets
|
|
|
|
npm run build:js
|
|
|
|
npm run build:css
|
|
|
|
npm run build:icons
|
|
|
|
npm run build:svg
|
|
|
|
npm run copy:images
|
|
|
|
npm run copy:fonts
|
|
|
|
```
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
> **Note:**
|
|
|
|
>
|
|
|
|
> The static assets generated live under the `public/assets` folder, it
|
|
|
|
> includes javascript, styles, images, fonts, icons and svg files.
|
2020-06-05 13:54:40 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
## Initialize and populate database
|
|
|
|
|
|
|
|
1. Build the database with the migrate command:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# loads the database schema during first migration
|
|
|
|
php spark migrate -all
|
|
|
|
```
|
|
|
|
|
|
|
|
You may need to undo the migration (rollback):
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# rolls back database schema (deletes all tables and their content)
|
|
|
|
php spark migrate:rollback
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Populate the database with the required data:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Populates all required data
|
|
|
|
php spark db:seed AppSeeder
|
|
|
|
```
|
|
|
|
|
|
|
|
You may choose to add data separately:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Populates all categories
|
|
|
|
php spark db:seed CategorySeeder
|
|
|
|
|
|
|
|
# Populates all Languages
|
|
|
|
php spark db:seed LanguageSeeder
|
|
|
|
|
|
|
|
# Populates all podcasts platforms
|
|
|
|
php spark db:seed PlatformSeeder
|
|
|
|
|
|
|
|
# Populates all Authentication data (roles definition…)
|
|
|
|
php spark db:seed AuthSeeder
|
|
|
|
```
|
|
|
|
|
|
|
|
3. (optionnal) Populate the database with test data:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Populates test data (login: admin / password: AGUehL3P)
|
|
|
|
php spark db:seed TestSeeder
|
|
|
|
|
|
|
|
# Populates with fake podcast analytics
|
|
|
|
php spark db:seed FakePodcastsAnalyticsSeeder
|
|
|
|
|
|
|
|
# Populates with fake website analytics
|
|
|
|
php spark db:seed FakeWebsiteAnalyticsSeeder
|
|
|
|
```
|
|
|
|
|
|
|
|
TestSeeder will add an active superadmin user with the following credentials:
|
|
|
|
|
|
|
|
- username: **admin**
|
|
|
|
- password: **AGUehL3P**
|
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:
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
- [localhost:8080](http://localhost:8080/) for the Castopod Host app
|
2020-06-05 13:54:40 +00:00
|
|
|
- [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
|
2021-05-24 10:08:15 +00:00
|
|
|
docker exec -it castopod-host_redis redis-cli
|
2021-04-09 13:43:37 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
## Known issues
|
|
|
|
|
2021-05-24 10:08:15 +00:00
|
|
|
### Allocation failed - JavaScript heap out of memory
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-24 10:08:15 +00:00
|
|
|
This happens when running `npm install`.
|
|
|
|
|
|
|
|
👉 By default, docker might not have access to enough RAM. Allocate more memory
|
|
|
|
and run `npm install` again.
|
|
|
|
|
|
|
|
### Files created inside container are attributed to root locally (Linux)
|
|
|
|
|
|
|
|
You may use Linux user namespaces to fix this:
|
|
|
|
|
|
|
|
> **Note:**
|
|
|
|
>
|
|
|
|
> Replace "username" with your local username
|
|
|
|
|
|
|
|
1. Go to `/etc/docker/daemon.json` and add:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"userns-remap": "username"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Configure the subordinate uid/guid:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
username:1000:1
|
|
|
|
username:100000:65536
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
username:1000:1
|
|
|
|
username:100000:65536
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Restart docker:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo systemctl restart docker
|
|
|
|
```
|
|
|
|
|
|
|
|
4. That's it! Now, the root user in the container will be mapped to the user on
|
|
|
|
your local machine, no more permission problems! 🎉
|
|
|
|
|
|
|
|
You can check
|
|
|
|
[this great article](https://www.jujens.eu/posts/en/2017/Jul/02/docker-userns-remap/)
|
|
|
|
to know more about how it works.
|