API code for Badapple2. Currently in beta.
The compose-production.yml
file will spin up the Badapple2 website (DB, API, and UI).
- Docker
- Docker Compose
- Copy
.env.example
to.env
(in the/app
folder) - Edit the
.env
credentials as needed - Run
docker-compose --env-file ./app/.env -f compose-development.yml up --build
- Note: Depending on your version of docker, you may instead want to use:
docker compose --env-file ./app/.env -f compose-development.yml up --build
- Note: Depending on your version of docker, you may instead want to use:
- The API should now be accessible from
localhost:8000
- A full set of Swagger documentation can be found at http://localhost:8000/apidocs
- Copy
production_env.example
to.env
- Fill in/edit the
.env
credentials as needed - Update apache2 config:
- Create a new file for apache2 config:
/etc/apache2/sites-available/badapple2api.conf
- Add the following line to
/etc/apache2/apache2.conf
:Include /etc/apache2/sites-available/badapple2api.conf
- Update the apache2 virtual config file:
/etc/apache2/sites-enabled/000-default.conf
- Run config check:
sudo apachectl configtest
- (If config check passed) reload apache:
sudo systemctl reload apache2
- Create a new file for apache2 config:
- (If server was previously up):
docker-compose -f compose-production.yml down
- Run
docker-compose -f compose-production.yml up --build -d
- If you are noticing some UI changes not showing up you may need to clear your browser cache
- You will likely need to clear the docker cache if you've made changes to the DB
- If you've pushed changes to the UI and docker is still using the cached github context, try changing UI build context to either a specific branch or commit. See https://docs.docker.com/reference/compose-file/build/#attributes for more info.
- In extreme cases you may need to go in and manually override the DB. I still do not know what the reason is for this, but there are times when even after updating the .pgdump file the DB state will not be changed (even after clearing cache etc). These steps are what I've found work:
- Connect to the DB container:
docker exec -it <container_id> sh
- (If necessary) re-download the .pgdump file. For example:
wget --no-cache -O /tmp/badapple_classic.pgdump https://unmtid-dbs.net/download/Badapple2/badapple_classic.pgdump
- Change to postgres user:
sudo -i -u postgres
- Run pg_restore on the DB with the .pgdump file:
pg_restore --clean -O -x -v -d ${DB_NAME} <PATH_TO_PGDUMP_FILE>
- Grant privileges back to DB_USER:
psql -p ${DB_PORT} -d ${DB_NAME} -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO ${DB_USER}"
psql -p ${DB_PORT} -d ${DB_NAME} -c "GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO ${DB_USER}"
psql -p ${DB_PORT} -d ${DB_NAME} -c "GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO ${DB_USER}"
- Exit DB container.