As discussed on the Discord server #support channel here :
https://discord.com/channels/1309279407743172608/1345758358141141113
The steps below explain how to use a self-hosted libSQL instance running on a local working environment using Docker for StudioCMS projects. This setup can be used for Astro.js projects that utilize AstroDB and/or libSQL as well.
Note that this guide targets the development environment, and using this setup in production is not recommended since doing so has its own risks.
In addition, this issue is created to support the StudioCMS documentation.
Note : You'll need Docker and openssl installed on your system. pnpm is used in this guide.
- In your project root folder, create a new folder (here we're naming it as
keys) :
- Run the following command to create a new PKCS#8-encoded Ed25519 key-pair :
openssl pkey -in ./keys/libsql.pem -pubout -out ./keys/libsql.pub
jwtgen is a node CLI utility used to generate JWT tokens. run pnpm jwtgen -h for more options.
- Run the following command to get the contents of your private key file in single line format :
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g' ./keys/libsql.pem
- Copy the output and use it in the
jwtgen command below
pnpm jwtgen -a HS256 -s "paste your private key output here" -c "iss=admin" -e 31556926
The output is the JWT auth token encrypted with your private key, which will be used for libSQL authentication. Keep in mind that the token will be valid for 1 year!
- Run the following command to encode the JWT auth token in base64URL format :
echo -n "paste the JWT auth token output here" | base64 | tr '/+' '_-' | tr -d '='
- Now update your Studio CMS
.env file :
ASTRO_DB_REMOTE_URL=http://localhost:8080
ASTRO_DB_APP_TOKEN=paste your base64URL encoded JWT auth token here
services:
libsql:
image: ghcr.io/tursodatabase/libsql-server:latest
platform: linux/amd64
ports:
- "8080:8080"
- "5001:5001"
environment:
- SQLD_NODE=primary
- SQLD_AUTH_JWT_KEY_FILE=/home/.ssh/libsql.pub
volumes:
- ./data/libsql:/var/lib/sqld
- ./keys/libsql.pub:/home/.ssh/libsql.pub
services:
libsql:
image: ghcr.io/tursodatabase/libsql-server:latest
platform: linux/amd64
ports:
- "8080:8080"
- "5001:5001"
environment:
- SQLD_NODE=primary
- SQLD_AUTH_JWT_KEY=paste your base64URL encoded JWT auth token here
volumes:
- ./data/libsql:/var/lib/sqld
If you'd like to use a different libSQL instance per project, you'll need to use different ports for each libSQL instance. You can find more details on how to configure it here :
https://github.com/tursodatabase/libsql/blob/main/docs/DOCKER.md
- Start the libSQL instance :
- Prepare your project's database :
pnpm astro db push --remote
- Run your StudioCMS application :
As discussed on the Discord server #support channel here :
https://discord.com/channels/1309279407743172608/1345758358141141113
The steps below explain how to use a self-hosted libSQL instance running on a local working environment using Docker for StudioCMS projects. This setup can be used for Astro.js projects that utilize AstroDB and/or libSQL as well.
Note that this guide targets the development environment, and using this setup in production is not recommended since doing so has its own risks.
In addition, this issue is created to support the StudioCMS documentation.
Note : You'll need
Dockerandopensslinstalled on your system.pnpmis used in this guide.keys) :jwtgen:jwtgenis a node CLI utility used to generate JWT tokens. runpnpm jwtgen -hfor more options.jwtgencommand belowThe output is the JWT auth token encrypted with your private key, which will be used for libSQL authentication. Keep in mind that the token will be valid for 1 year!
.envfile :Create a new
docker-compose.ymlfile for the libSQL instance. At this point you have two options to configure libSQL authentication :ASTRO_DB_APP_TOKENvalue you used in your.envfile)If you'd like to use a different libSQL instance per project, you'll need to use different ports for each libSQL instance. You can find more details on how to configure it here :
https://github.com/tursodatabase/libsql/blob/main/docs/DOCKER.md