feat: Enhance Docker build versioning with a build argument, fetch git tags during deployment, and add comprehensive deployment documentation.
This commit is contained in:
84
DEPLOYMENT.md
Normal file
84
DEPLOYMENT.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# Deployment Guide
|
||||||
|
|
||||||
|
## Automated Deployment
|
||||||
|
|
||||||
|
Use the deployment script for zero-downtime deployments:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./scripts/deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This script will:
|
||||||
|
1. Create a database backup
|
||||||
|
2. Pull latest changes from git
|
||||||
|
3. Fetch all git tags (for version display)
|
||||||
|
4. Build the new Docker image
|
||||||
|
5. Restart the container with minimal downtime
|
||||||
|
6. Clean up old images
|
||||||
|
|
||||||
|
## Manual Deployment
|
||||||
|
|
||||||
|
If you need to deploy manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Pull latest changes
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# Fetch tags (important for version display!)
|
||||||
|
git fetch --tags
|
||||||
|
|
||||||
|
# Build and restart
|
||||||
|
docker compose build
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version Display
|
||||||
|
|
||||||
|
The app displays the current version in the footer. The version is determined as follows:
|
||||||
|
|
||||||
|
1. **During Docker build**: The version is extracted from git tags using `git describe --tags --always`
|
||||||
|
2. **At runtime**: The version is read from `/app/version.txt` and exposed via the `/api/version` endpoint
|
||||||
|
3. **Local development**: The version is extracted directly from git on each request
|
||||||
|
|
||||||
|
### Building with a specific version
|
||||||
|
|
||||||
|
You can override the version during build:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose build --build-arg APP_VERSION=v1.2.3
|
||||||
|
```
|
||||||
|
|
||||||
|
### Troubleshooting
|
||||||
|
|
||||||
|
If the version shows as "dev" or "unknown":
|
||||||
|
|
||||||
|
1. Make sure git tags are pushed to the remote repository:
|
||||||
|
```bash
|
||||||
|
git push --tags
|
||||||
|
```
|
||||||
|
|
||||||
|
2. On the deployment server, fetch the tags:
|
||||||
|
```bash
|
||||||
|
git fetch --tags
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Verify tags are available:
|
||||||
|
```bash
|
||||||
|
git describe --tags --always
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Rebuild the Docker image:
|
||||||
|
```bash
|
||||||
|
docker compose build --no-cache
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## Health Check
|
||||||
|
|
||||||
|
The container includes a health check that monitors the `/api/daily` endpoint. Check the health status:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker ps
|
||||||
|
```
|
||||||
|
|
||||||
|
Look for the "healthy" status in the STATUS column.
|
||||||
12
Dockerfile
12
Dockerfile
@@ -14,14 +14,22 @@ RUN npm ci
|
|||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Accept version as build argument (optional)
|
||||||
|
ARG APP_VERSION=""
|
||||||
|
|
||||||
# Install git to extract version information
|
# Install git to extract version information
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Extract version from git
|
# Extract version: use build arg if provided, otherwise get from git
|
||||||
RUN git describe --tags --always 2>/dev/null > /tmp/version.txt || echo "unknown" > /tmp/version.txt
|
RUN if [ -n "$APP_VERSION" ]; then \
|
||||||
|
echo "$APP_VERSION" > /tmp/version.txt; \
|
||||||
|
else \
|
||||||
|
git describe --tags --always 2>/dev/null > /tmp/version.txt || echo "unknown" > /tmp/version.txt; \
|
||||||
|
fi && \
|
||||||
|
echo "Building version: $(cat /tmp/version.txt)"
|
||||||
|
|
||||||
# Next.js collects completely anonymous telemetry data about general usage.
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
# Learn more here: https://nextjs.org/telemetry
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ fi
|
|||||||
echo "📥 Pulling latest changes from git..."
|
echo "📥 Pulling latest changes from git..."
|
||||||
git pull
|
git pull
|
||||||
|
|
||||||
|
# Fetch all tags
|
||||||
|
echo "🏷️ Fetching git tags..."
|
||||||
|
git fetch --tags
|
||||||
|
|
||||||
# Build new image in background (doesn't stop running container)
|
# Build new image in background (doesn't stop running container)
|
||||||
echo "🔨 Building new Docker image (this runs while app is still online)..."
|
echo "🔨 Building new Docker image (this runs while app is still online)..."
|
||||||
docker compose build
|
docker compose build
|
||||||
|
|||||||
Reference in New Issue
Block a user