This repository holds the code for the Goteo v4 API.
NOTE: Review the trusted certificates by OpenSSL. See: #43
This application requires Docker and the Docker Compose plugin. Additionally, if you want to use the OAuth capabilities, you need to have Node.js and npm installed in your machine.
git clone https://github.com/goteo/org.goteo.api
cd org.goteo.apidocker compose up -d --buildNOTE: The following steps are optional, unless you need to specify ports or configure the default Docker build in some way you can skip to step 2.2. Post build setup.
To avoid ownership issues for files generated inside the PHP container the default Compose config will try to export your user's and group's ID, or 1000 if it can't find them, to the user inside the container. If that is not your ID you can pass your actual IDs using the env vars UID and GID.
In a similar fashion you can override the nginx container binding to the ports :8090 (for http) and :8091 (for https) on your host with the env vars APP_HTTP_PORT and APP_HTTPS_PORT.
- Option A. Using a custom
.env.localfile.
# .env.local
UID=1001
GID=1001
APP_HTTP_PORT=8080
APP_HTTPS_PORT=8443Then feed your custom env vars to Compose:
docker compose --env-file .env.local up -d --build- Option B. Passing the variables through the shell.
export APP_HTTP_PORT=8080 && export APP_HTTPS_PORT=8443
# Dynamic user and group id
export UID=$(id -u) && export GID=$(id -g)
# Custom user and group id
export UID=1001 && export GID=1001
docker compose up -d --buildAfter the Docker containers are first built, you'll need to finish the PHP setup.
# Install composer.json dependencies
docker compose exec php composer install
# Create the database
# May throw an error if it already exists, no further action required if so
docker compose exec php bin/console doctrine:database:create
# Update the database schema
docker compose exec php bin/console doctrine:migrations:migrate
# Generate keys to sign the JWTs for OAuth
docker compose exec php bin/console league:oauth2-server:generate-keypair
# Install and generate JavaScript assets
npm install
npm run buildThe app should be live at http://localhost:8090 (or your specified ports). Keep in mind that the API address is /v4.
You can access a real-time build of the OpenAPI spec file for the API at /v4/docs.json, to be used, for example, with API development suites such as Postman. This file will be up to date with most of your latest changes.
The API also builds a small ReDoc frontend to act as documentation at /v4/docs. A Swagger UI version of the docs is also available at /v4/docs?ui=swagger_ui.
For quick Docker access you can use the bin/docker shortcut to quickly exec anything into one of the containers. It expects the name of the Docker Compose service as first parameter, then you can pass whatever it is that you wish to exec into that container, e.g:
- Login to mysql CLI:
bin/docker mariadb mysql -u goteo -pgoteo goteo - Debug the symfony services:
bin/docker php bin/console debug:container - List app custom commands:
bin/docker php bin/console list app
This app uses PHPUnit.
bin/docker php bin/phpunitBeware you might experience the following error:
RuntimeException: Error running "doctrine:database:create": Could not create database `goteo_test` for connection named default
An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'goteo'@'%' to database 'goteo_test'
in /app/vendor/zenstruck/foundry/src/Test/AbstractSchemaResetter.php:33
To fix it:
- Login into the MariaDB instance as root.
bin/docker mariadb mysql -u root -pgoteo goteo- Grant goteo all privileges.
GRANT ALL PRIVILEGES ON *.* TO 'goteo'@'%';Xdebug is built for you in the PHP container of the Docker setup. A configuration file for VSCode is also shipped in the repo.
Common issues you might find while developing the application are:
When you first build the application after long times or having introduced breaking-changes you might cause a cold start which can induce out-of-memory issues. To fix it, simply warm-up the cache layer.
# Remove the old cache
docker compose exec php bin/console cache:clear
# Warm-up a new cache
docker compose exec php bin/console cache:warmupThis should usually fix your out-of-memory issues. If it does not then you have likely introduced memory leaks that shall be fixed. Refer to the Xdebug documentation on profiling for help.
Sometimes, when updating your local repository with remote changes, you might find that the application does not work anymore. When this happens the application will complain loudly and clearly about the issue, give it a read to the error messages. Most of the time it will be one of two issues that can be solved by running one command.
# Application dependencies have changed
docker compose exec php composer install
# Database schema has changed
docker compose exec php bin/console doctrine:migrations:migrate