How to run PlanetScale alongside with an MySQL enabled app that does not have any other internet access (like in the InformatiCup CI setup)
- Sign up for a free forever MySQL compatible database with up to three branches
- Create a database and fill it with some sample data
- Create a service token and grant it permissions to connect to your database
- Set the following environmental variables
- PLANETSCALE_DB: name of your database
- PLANETSCALE_BRANCH: name of your branch (probably main at the beginning)
- PLANETSCALE_ORG: the default org is named after your PlanetScale account
- PLANETSCALE_SERVICE_TOKEN: the token you created in step 3
- PLANETSCALE_SERVICE_TOKEN_NAME the name of the token you create in step 3
You can either set those environmental variables in your shell (export PLANETSCALE_DB=infocup
) or put them into a file .env
alongside with the docker-compose.yml
file.
For format illustration purposes, an .env file (with outdated credentials) is included in this gist. If you make your .env file executale or export the variables manually in your shell, you can now test db connectivity:
. .env && docker run -e PLANETSCALE_SERVICE_TOKEN=$PLANETSCALE_SERVICE_TOKEN -e PLANETSCALE_SERVICE_TOKEN_NAME -e PLANETSCALE_BRANCH -e PLANETSCALE_ORG -e PLANETSCALE_DB --rm -it -p 3306:3306/tcp --entrypoint '/bin/sh' planetscale/pscale:latest -c 'pscale connect --host `hostname -i | awk "{print $1}"` $PLANETSCALE_DB $PLANETSCALE_BRANCH --org $PLANETSCALE_ORG'
docker-compose run app
After the run, you can shut down the database service by running
docker-compose down
- See example from docker-compose file, this would be the way to connect to the DB while running in the CI server:
mysql -h planetscale
-
For other ways to test against the database locally (i.e. when not running in CI), check out this documentation
-
Add your own app / service with the "no-internet" network to get a feeling how your app will behave
-
use
docker-compose down
when you change docker-compose.yml, before you rundocker-compose up
again