Files
RolemasterDB/docs/vserver_docker_deploy.md

99 lines
2.7 KiB
Markdown

# 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:
```bash
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.sh`
- `deploy/vserver.Dockerfile`
- `deploy/vserver.env.example`
## Remote Prerequisites
On the vserver:
1. Install Docker.
2. Make sure the SSH user can run `docker`, or set `REMOTE_USE_SUDO=1` in the deploy config.
3. 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:
```bash
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 example `myvserver`
- `REMOTE_APP_DIR`: base directory on the server, for example `/opt/rolemasterdb`
- `REMOTE_DATA_DIR`: persistent directory for the SQLite database
- `HOST_PORT`: public port on the vserver
- `REMOTE_USE_SUDO`: set to `1` if remote Docker commands need `sudo`
- `REMOTE_ENV_FILE`: optional existing env file on the server to pass through to `docker run`
## Deploy
Run:
```bash
./scripts/deploy-vserver.sh
```
Or point at a different config file:
```bash
./scripts/deploy-vserver.sh /path/to/custom.env
```
## What The Script Does
1. Publishes `src/RolemasterDb.App/RolemasterDb.App.csproj` in `Release`.
2. Precreates `publish/wwwroot/components/layout` and `publish/wwwroot/components/shared` before publish.
This is required because the current project otherwise fails to publish two JavaScript static assets.
3. Bundles the publish output, `src/RolemasterDb.App/rolemaster.db`, and the runtime Dockerfile into `artifacts/deploy/<release-id>/`.
4. Uploads the bundle to the vserver.
5. Extracts the bundle on the vserver.
6. Seeds `REMOTE_DATA_DIR/rolemaster.db` on first deploy only.
7. Builds the Docker image on the vserver.
8. Recreates the container with:
```text
--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:
```bash
ssh myvserver docker ps
```
Follow logs:
```bash
ssh myvserver docker logs -f rolemasterdb
```