This commit is contained in:
admin
2026-01-22 21:05:48 +09:00
parent 3d91356877
commit 536266d70b
11 changed files with 236 additions and 85 deletions

34
deploy/README.md Normal file
View File

@@ -0,0 +1,34 @@
# NAS Git Deploy (sample)
This folder contains a sample `post-receive` hook for deploying the app on a NAS via a bare git repository.
Quick setup (example):
1. On the NAS, create directories and a bare repo:
```bash
mkdir -p /srv/njts-accounting/repo.git
git init --bare /srv/njts-accounting/repo.git
mkdir -p /srv/njts-accounting/app
```
2. Copy the `post-receive` hook into the bare repo hooks and make it executable:
```bash
cp deploy/post-receive /srv/njts-accounting/repo.git/hooks/post-receive
chmod +x /srv/njts-accounting/repo.git/hooks/post-receive
```
3. On your local machine, add a remote and push:
```bash
git remote add nas ssh://user@nas:/srv/njts-accounting/repo.git
git push nas main
```
4. Ensure Docker and Docker Compose are installed on the NAS and `/srv/njts-accounting/docker-compose.yml` points to the code in `/srv/njts-accounting/app`.
Notes:
- Adjust paths and permissions according to your NAS environment.
- The sample hook runs `docker compose up -d --build` and may require the user to be in the `docker` group or run via sudo.

22
deploy/post-receive Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# Sample post-receive hook for bare repository deployment.
# Adjust paths and user permissions as needed.
set -e
REPO_DIR="/srv/njts-accounting/repo.git"
WORK_TREE="/srv/njts-accounting/app"
COMPOSE_FILE="/srv/njts-accounting/docker-compose.yml"
echo "Deploy hook triggered"
mkdir -p "$WORK_TREE"
# checkout latest to work tree
GIT_DIR="$REPO_DIR" git --work-tree="$WORK_TREE" checkout -f
cd "$WORK_TREE"
echo "Building and restarting containers..."
docker compose -f "$COMPOSE_FILE" pull --ignore-pull-failures || true
docker compose -f "$COMPOSE_FILE" up -d --build --remove-orphans
echo "Deployment finished"