2.7 KiB
2.7 KiB
Docker Deployment To A Linux VServer
This repo now includes a deployment script for shipping RolemasterDb.App to a remote Linux server that you reach with:
ssh myvserver
The script publishes the app locally, uploads a release bundle over scp, builds the Docker image on the server, and replaces the running container.
Files
scripts/deploy-vserver.shdeploy/vserver.Dockerfiledeploy/vserver.env.example
Remote Prerequisites
On the vserver:
- Install Docker.
- Make sure the SSH user can run
docker, or setREMOTE_USE_SUDO=1in the deploy config. - Open the host port you want to expose, for example
8080.
The deploy script stores releases under REMOTE_APP_DIR/releases/<timestamp> and keeps the SQLite database in REMOTE_DATA_DIR/rolemaster.db.
Local Setup
Create a local deploy config from the example:
cp deploy/vserver.env.example deploy/vserver.env
Adjust the values in deploy/vserver.env as needed:
REMOTE_HOST: your SSH host or alias, for examplemyvserverREMOTE_APP_DIR: base directory on the server, for example/opt/rolemasterdbREMOTE_DATA_DIR: persistent directory for the SQLite databaseHOST_PORT: public port on the vserverREMOTE_USE_SUDO: set to1if remote Docker commands needsudoREMOTE_ENV_FILE: optional existing env file on the server to pass through todocker run
Deploy
Run:
./scripts/deploy-vserver.sh
Or point at a different config file:
./scripts/deploy-vserver.sh /path/to/custom.env
What The Script Does
- Publishes
src/RolemasterDb.App/RolemasterDb.App.csprojinRelease. - Precreates
publish/wwwroot/components/layoutandpublish/wwwroot/components/sharedbefore publish. This is required because the current project otherwise fails to publish two JavaScript static assets. - Bundles the publish output,
src/RolemasterDb.App/rolemaster.db, and the runtime Dockerfile intoartifacts/deploy/<release-id>/. - Uploads the bundle to the vserver.
- Extracts the bundle on the vserver.
- Seeds
REMOTE_DATA_DIR/rolemaster.dbon first deploy only. - Builds the Docker image on the vserver.
- Recreates the container with:
--restart unless-stopped
-p HOST_PORT:CONTAINER_PORT
-v REMOTE_DATA_DIR:/app/data
ConnectionStrings__RolemasterDb=Data Source=/app/data/rolemaster.db
Updating The App Later
Running the same deploy command again will:
- publish a fresh release bundle
- upload a new timestamped release
- keep the existing database in
REMOTE_DATA_DIR - rebuild the image and restart the container
Useful Remote Commands
Check the running container:
ssh myvserver docker ps
Follow logs:
ssh myvserver docker logs -f rolemasterdb