This is the main repository for the CnCNet Ladder API.
- Set up docker on your computer (either docker desktop or docker engine with docker-compose)
- Copy .env-exampleto.envand configure docker related env.
- Copy cncnet-api/.env-exampleto.envand configure laravel related env.
If you are setting up your developpement environment, you can skip this chapter and go to the Development section.
Configurations are made using .env files :
- .app.env: file for the laravel containers (app, queue, scheduler)
- .backup.env: file for the backup container (- tiredofit/db-backup)
- .env: file for the configurations used in the- docker-compose.ymlfile
These files were split to avoid exposing vars to services that don't need them and for a better separation of concern.
.app.env example
APP_ENV="production"
APP_DEBUG=false
APP_KEY="..."
APP_URL=https://ladder.cncnet.org
# Laravel mysql config
DB_CONNECTION="mariadb"
DB_HOST="mysql"
DB_DATABASE="cncnet_api"
DB_USERNAME="cncnet"
DB_PASSWORD="cncnet"
CACHE_DRIVER="file"
SESSION_DRIVER="cookie"
QUEUE_DRIVER="redis"
LOG_LEVEL="info"
LOG_CHANNEL="stack"
MAIL_DRIVER="smtp"
MAIL_HOST="mailtrap.io"
MAIL_PORT="2525"
MAIL_USERNAME=null
MAIL_PASSWORD=null
JWT_SECRET=
REDIS_CLIENT=phpredis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
OCTANE_SERVER=frankenphp
.backup.env example
# Backups
DB_TYPE="mariadb"
DB_HOST="mysql"
DB_NAME="cncnet_api"
DB_USER="cncnet"
DB_PASS="cncnet"
DB_DUMP_FREQ="1440"
DB_DUMP_BEGIN="0000"
DB_CLEANUP_TIME="8640"
CHECKSUM="SHA1"
COMPRESSION="GZ"
SPLIT_DB="FALSE"
CONTAINER_ENABLE_MONITORING="false"
MYSQL_SINGLE_TRANSACTION="true"
USER_DBBACKUP=1001
GROUP_DBBACKUP=1001
.env example
# Docker related env
# Important for permissions, host machine user should match container as we have a volume sharing
HOST_USER=cncnet
HOST_UID=1001
HOST_GID=1001
ENV_SUFFIX=_prod
APP_TAG=latest
APP_PORT=3000
# Mysql config
MYSQL_DATABASE="cncnet_api"
MYSQL_USER="cncnet"
MYSQL_PASSWORD="cncnet"
MYSQL_ALLOW_EMPTY_PASSWORD="false"
MYSQL_ROOT_PASSWORD="yourRandomRootPass"
The docker-compose.yml will mount a few volumes :
- ./storageon- /app/storagein- appcontainer to store laravel storage.
- Two directory used by caddy under the hood : ./caddy/dataand./caddy/configinappcontainer
- The named volume cncnet-ladder-dbon/var/lib/mysqlinmysqlcontainer for the database.
- ./backupson- /storagein- db-backupscontainer to store database backups.
- ./docker/elogen/crontabin- /etc/cron.d/elogen-cronin- elogencontainer to configure the cron for the elogen.
- ./storage/app/ratingin- /datain- elogencontainer to store the generated files for the elo ranking.
Elogen can be configured using the crontab file /docker/elogen/crontab.
Deployment to production are automated using GitHub Actions. Everytime a commit is made on the main branch the workflow "build-and-deploy" run. This workflow consists of two jobs.
It will build all containers by using the Dockerfile at docker/frankenphp.
There is a container for the app, one for the queues and one for the scheduler (cron). Once all these 3 containers are built, they are
published to the GitHub Container Registry (ghcr) and tagged with latest.
Containers
- cncnet-ladder-app:latest
- cncnet-ladder-queue:latest
- cncnet-ladder-scheduler:latest
Once containers are ready, the next job will run.
This job will simply :
- Uplaod the docker-compose file docker-compose.ymlto the server in the target directory using scp.
- Connect in ssh and stop the current service, pull the new images and start again the service.
- It will also run php artisan config:cachein the containers.