Castopod is a web app based on the php
framework
CodeIgniter 4.
We use Docker to quickly setup a dev environment. A
docker-compose.yml
and Dockerfile
are included in the project's root folder
to help you kickstart your contribution.
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!
-
Install Docker.
-
Clone the Castopod repository by running:
git clone https://code.castopod.org/adaures/castopod.git
-
Create a
.env
file with the minimum required config to connect the app to the database and use redis as a cache handler:CI_ENVIRONMENT="development" # If set to development, you must run `pnpm run dev` to start the static assets server vite.environment="development" # 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 app.baseURL="http://localhost:8080/" admin.gateway="cp-admin" auth.gateway="cp-auth" database.default.hostname="mariadb" database.default.database="castopod" database.default.username="castopod" database.default.password="castopod" database.default.DBPrefix="dev_" analytics.salt="DEV_ANALYTICS_SALT" 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" ###################################### # Media config ###################################### media.baseURL="http://localhost:8080/" # S3 # Uncomment to store s3 objects using adobe/s3mock service # ----------------------- #media.fileManager="s3" #media.s3.bucket="castopod" #media.s3.endpoint="http://172.31.0.6:9090/" #media.s3.pathStyleEndpoint=true
[!NOTE]
You can tweak your environment by setting more environment variables in your custom.env
file. See theenv
for examples or the CodeIgniter4 User Guide for more info. -
(for Docker desktop) Add the repository you've cloned to Docker desktop's
Settings
>Resources
>File Sharing
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! 🪄
-
Install the VSCode extension Remote - Containers
-
Ctrl/Cmd + Shift + P
>Open in container
The VSCode window will reload inside the dev container. Expect several minutes during first load as it is building all necessary services.
Note: The dev container will start by running Castopod's PHP server. During development, you will have to start Vite's dev server for compiling the typescript code and styles:
# run Vite dev server pnpm run dev --host
If there is any issue with the PHP server not running, you can restart them using the following commands:
# run Castopod server php spark serve - 0.0.0.0
-
You're all set! 🎉
You're now inside the dev container, you may use the VSCode console (
Terminal
>New Terminal
) to run any command:# PHP is installed php -v # Composer is installed composer -V # pnpm is installed pnpm -v # git is installed git version
For more info, see Developing inside a Container
You're all set! Start working your magic by updating the project's files! Help yourself to the CodeIgniter4 User Guide for more insights.
To see your changes, go to:
-
http://localhost:8080/
for the Castopod website -
http://localhost:8080/cp-admin
for the Castopod admin:- email: [email protected]
- password: castopod
-
http://localhost:8888/
for the phpmyadmin interface:- username: castopod
- password: castopod
You do not wish to use the VSCode devcontainer? No problem!
-
Start the Docker containers manually:
Go to the project's root folder and run:
# 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) docker-compose ps # Alternatively, you can check all docker processes docker ps -a
The
docker-compose up -d
command will boot 5 containers in the background:castopod_app
: a php based container with Castopod requirements installedcastopod_redis
: a redis database to handle queries and pages cachingcastopod_mariadb
: a mariadb server for persistent datacastopod_phpmyadmin
: a phpmyadmin server to visualize the mariadb database.castopod_s3
: a mock s3 server to work on the s3 fileManager
-
Run any command inside the containers by prefixing them with
docker-compose run --rm app
:# use PHP docker-compose run --rm app php -v # use Composer docker-compose run --rm app composer -V # use pnpm docker-compose run --rm app pnpm -v # use git docker-compose run --rm app git version
-
Install php dependencies with Composer
composer install
[!NOTE]
The php dependencies aren't included in the repository. Composer will check thecomposer.json
andcomposer.lock
files to download the packages with the right versions. The dependencies will live under thevendor/
folder. For more info, check out the Composer documentation. -
Install JavaScript dependencies with pnpm
pnpm install
[!NOTE]
The JavaScript dependencies aren't included in the repository. Pnpm will check thepackage.json
andpnpm-lock.yaml
files to download the packages with the right versions. The dependencies will live under thenode_module
folder. For more info, check out the PNPM documentation. -
Generate static assets:
# build all static assets at once pnpm run build:static # build specific assets pnpm run build:icons pnpm run build:svg
[!NOTE]
The static assets generated live under thepublic/assets
folder, it includes JavaScript, styles, images, fonts, icons and svg files.
Tip
You may skip this section if you go through the install wizard (go to
/cp-install
).
-
Build the database with the migrate command:
# loads the database schema during first migration php spark migrate -all
You may need to undo the migration (rollback):
# rolls back database schema (deletes all tables and their content) php spark migrate:rollback
-
Populate the database with the required data:
# Populates all required data php spark db:seed DevSeeder
You may choose to add data separately:
# Populates all categories php spark db:seed CategorySeeder # Populates all Languages php spark db:seed LanguageSeeder # Adds a superadmin with [[email protected] / castopod] credentials php spark db:seed DevSuperadminSeeder
-
(optional) Populate the database with test data:
- Populate with fake podcast analytics:
php spark db:seed FakePodcastsAnalyticsSeeder
- Populate with fake website analytics:
php spark db:seed FakeWebsiteAnalyticsSeeder
- Monitor the app container:
docker-compose logs --tail 50 --follow --timestamps app
- Interact with the 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
- Monitor the mariadb container:
docker-compose logs --tail 50 --follow --timestamps mariadb
- Monitor the phpmyadmin container:
docker-compose logs --tail 50 --follow --timestamps phpmyadmin
- Restart docker containers:
docker-compose restart
- Destroy all containers, opposite of
up
command:
docker-compose down
- Rebuild app container:
docker-compose build app
Check Docker and docker-compose documentations for more insights.
This happens when running pnpm install
.
👉 By default, docker might not have access to enough RAM. Allocate more memory
and run pnpm install
again.
You may use Linux user namespaces to fix this on your machine:
Note
Replace "username" with your local username
-
Go to
/etc/docker/daemon.json
and add:{ "userns-remap": "username" }
-
Configure the subordinate uid/guid:
# in /etc/subuid username:1000:1 username:100000:65536
# in /etc/subgid username:1000:1 username:100000:65536
-
Restart Docker:
sudo systemctl restart docker
-
That's it! Now, the root user in the container will be mapped to the user on your local machine, no more permission issues! 🎉
You can check this great article to know more about how it works.