By Jon Friesen
Senior Software Engineer II
I would like to use PlanetScale with my App Platform app, how can I configure it to use the proxy that is required?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Please, do NOT follow the answer from Jon Friesen anymore. It was probably written before PlanetScale implement its connection strings feature.
Instead:
MYSQL_ATTR_SSL_CA
env variable also with the value /etc/ssl/certs/ca-certificates.crt
You can also find more details here
👋
Great question! Since PlanetScale has a neat client that creates a proxy to the database instance, we will have to install and authenticate that tool so that it can inject a DATABASE_URL
environment variable into the app.
export PSCALE_VERSION="$(curl https://github.com/planetscale/cli/releases/latest -s -L -I -o /dev/null -w '%{url_effective}' | awk '{n=split($1,A,"/v"); print A[n]}')" && \
curl -sL https://github.com/planetscale/cli/releases/download/v$PSCALE_VERSION/pscale_${PSCALE_VERSION}_linux_amd64.tar.gz | tar -xz -C ./ && \
chmod +x ./pscale
./pscale connect app-platform-test main --execute "node app.js"
Don’t forget to set the required PlanetScale environment variables from the tutorial!
PLANETSCALE_ORG=your-org-name
PLANETSCALE_SERVICE_TOKEN_NAME=your-token-name
PLANETSCALE_SERVICE_TOKEN=your-token-value
And that’s it! PlanetScale connections in App Platform! If you want to support PlanetScale with an a dockerfile based app add the install command above prefixed with RUN
to your dockerfile, for example:
export PSCALE_VERSION="$(curl https://github.com/planetscale/cli/releases/latest -s -L -I -o /dev/null -w '%{url_effective}' | awk '{n=split($1,A,"/v"); print A[n]}')" && \
curl -sL https://github.com/planetscale/cli/releases/download/v$PSCALE_VERSION/pscale_${PSCALE_VERSION}_linux_amd64.tar.gz | tar -xz -C ./ && \
chmod +x ./pscale
Don’t forget to ensure your run command is wrapped in the pscale connect...
command :)
Here’s an example app spec:
name: pscale-express-example
region: nyc
services:
- build_command: |-
export PSCALE_VERSION="$(curl https://github.com/planetscale/cli/releases/latest -s -L -I -o /dev/null -w '%{url_effective}' | awk '{n=split($1,A,"/v"); print A[n]}')" && \
curl -sL https://github.com/planetscale/cli/releases/download/v$PSCALE_VERSION/pscale_${PSCALE_VERSION}_linux_amd64.tar.gz | tar -xz -C ./ && \
chmod +x ./pscale
environment_slug: node-js
envs:
- key: PLANETSCALE_ORG
scope: RUN_AND_BUILD_TIME
value: <org>
- key: PLANETSCALE_SERVICE_TOKEN_NAME
scope: RUN_AND_BUILD_TIME
value: <service_token_name>
- key: PLANETSCALE_SERVICE_TOKEN
scope: RUN_AND_BUILD_TIME
value: <service_token>
github:
branch: main
deploy_on_push: true
repo: planetscale/express-example
http_port: 8080
instance_count: 1
instance_size_slug: basic-xs
name: pscale-express-example
routes:
- path: /
run_command: ./pscale connect <database_name> main --execute "node app.js"
source_dir: /
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.