GHCR migration + env defaults + memory updates
This commit is contained in:
parent
384d4d5489
commit
b49cebb577
3 changed files with 68 additions and 29 deletions
40
.github/workflows/deploy.yml
vendored
40
.github/workflows/deploy.yml
vendored
|
|
@ -9,9 +9,16 @@ concurrency:
|
||||||
group: deploy-prod
|
group: deploy-prod
|
||||||
cancel-in-progress: false
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_BACKEND: ghcr.io/lekss361/gendesign-backend
|
||||||
|
IMAGE_FRONTEND: ghcr.io/lekss361/gendesign-frontend
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
|
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
@ -20,10 +27,12 @@ jobs:
|
||||||
id: meta
|
id: meta
|
||||||
run: echo "tag=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
run: echo "tag=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Login to Yandex Container Registry
|
- name: Login to GHCR
|
||||||
uses: yc-actions/yc-cr-login@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
@ -36,8 +45,8 @@ jobs:
|
||||||
cache-from: type=gha,scope=backend
|
cache-from: type=gha,scope=backend
|
||||||
cache-to: type=gha,mode=max,scope=backend
|
cache-to: type=gha,mode=max,scope=backend
|
||||||
tags: |
|
tags: |
|
||||||
cr.yandex/${{ secrets.YC_REGISTRY_ID }}/backend:latest
|
${{ env.IMAGE_BACKEND }}:latest
|
||||||
cr.yandex/${{ secrets.YC_REGISTRY_ID }}/backend:${{ steps.meta.outputs.tag }}
|
${{ env.IMAGE_BACKEND }}:${{ steps.meta.outputs.tag }}
|
||||||
|
|
||||||
- name: Build & push frontend
|
- name: Build & push frontend
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
|
|
@ -47,30 +56,25 @@ jobs:
|
||||||
cache-from: type=gha,scope=frontend
|
cache-from: type=gha,scope=frontend
|
||||||
cache-to: type=gha,mode=max,scope=frontend
|
cache-to: type=gha,mode=max,scope=frontend
|
||||||
tags: |
|
tags: |
|
||||||
cr.yandex/${{ secrets.YC_REGISTRY_ID }}/frontend:latest
|
${{ env.IMAGE_FRONTEND }}:latest
|
||||||
cr.yandex/${{ secrets.YC_REGISTRY_ID }}/frontend:${{ steps.meta.outputs.tag }}
|
${{ env.IMAGE_FRONTEND }}:${{ steps.meta.outputs.tag }}
|
||||||
|
|
||||||
- name: Deploy to VM via SSH
|
- name: Deploy to VM via SSH
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
env:
|
||||||
|
IMAGE_TAG: ${{ steps.meta.outputs.tag }}
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.DEPLOY_HOST }}
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
username: ${{ secrets.DEPLOY_USER }}
|
username: ${{ secrets.DEPLOY_USER }}
|
||||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||||
port: ${{ secrets.DEPLOY_PORT || 22 }}
|
port: ${{ secrets.DEPLOY_PORT || 22 }}
|
||||||
|
envs: IMAGE_TAG
|
||||||
script: |
|
script: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cd /opt/gendesign
|
cd /opt/gendesign
|
||||||
|
export IMAGE_TAG="$IMAGE_TAG"
|
||||||
# Login to YCR on the host (uses key passed via env or pre-configured docker config)
|
|
||||||
echo "${{ secrets.YC_SA_JSON_CREDENTIALS }}" | docker login \
|
|
||||||
--username json_key \
|
|
||||||
--password-stdin cr.yandex
|
|
||||||
|
|
||||||
export IMAGE_TAG=${{ steps.meta.outputs.tag }}
|
|
||||||
docker compose -f docker-compose.prod.yml pull
|
docker compose -f docker-compose.prod.yml pull
|
||||||
docker compose -f docker-compose.prod.yml up -d
|
docker compose -f docker-compose.prod.yml up -d
|
||||||
docker image prune -f
|
docker image prune -f
|
||||||
|
sleep 8
|
||||||
# Wait for health
|
curl -fsS http://localhost:8000/health | head -c 200 || true
|
||||||
sleep 5
|
|
||||||
curl -fsS http://localhost:8000/health | head -c 200
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,46 @@
|
||||||
# Production compose for Yandex Cloud VM (or Selectel cloud server).
|
# Production compose. Pulls pre-built images from GHCR
|
||||||
# Pull pre-built images from Yandex Container Registry pushed by GitHub Actions.
|
# (built and pushed by .github/workflows/deploy.yml).
|
||||||
#
|
#
|
||||||
# Place this file at /opt/gendesign/docker-compose.prod.yml on the VM.
|
# Place at /opt/gendesign/docker-compose.prod.yml on the VM.
|
||||||
# Required env vars provided via /opt/gendesign/.env:
|
# Required env in /opt/gendesign/.env:
|
||||||
# YC_REGISTRY_ID, IMAGE_TAG, DATABASE_URL, REDIS_URL, SENTRY_DSN,
|
# POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD
|
||||||
# NEXT_PUBLIC_API_BASE_URL
|
# IMAGE_TAG (defaults to "latest")
|
||||||
|
# NEXT_PUBLIC_API_BASE_URL (e.g. https://your-domain or empty for same-origin)
|
||||||
|
#
|
||||||
|
# Postgres + Redis run alongside the app on the same VM (Discovery mode).
|
||||||
|
# Volumes are shared with docker-compose.yml so switching between files preserves data.
|
||||||
|
|
||||||
services:
|
services:
|
||||||
backend:
|
postgres:
|
||||||
image: cr.yandex/${YC_REGISTRY_ID}/backend:${IMAGE_TAG:-latest}
|
image: postgis/postgis:16-3.4
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
environment:
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
|
||||||
|
backend:
|
||||||
|
image: ghcr.io/lekss361/gendesign-backend:${IMAGE_TAG:-latest}
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file: ./backend/.env
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_started
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8000:8000"
|
- "127.0.0.1:8000:8000"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|
@ -20,10 +50,10 @@ services:
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
image: cr.yandex/${YC_REGISTRY_ID}/frontend:${IMAGE_TAG:-latest}
|
image: ghcr.io/lekss361/gendesign-frontend:${IMAGE_TAG:-latest}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
|
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL:-}
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:3000:3000"
|
- "127.0.0.1:3000:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
@ -44,5 +74,7 @@ services:
|
||||||
- frontend
|
- frontend
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
redis_data:
|
||||||
caddy_data:
|
caddy_data:
|
||||||
caddy_config:
|
caddy_config:
|
||||||
|
|
|
||||||
|
|
@ -43,3 +43,6 @@ The key's randomart image is:
|
||||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPYYAH7vPN/b0npfH1IrhADdE+SwJsmo8gJm84VauM4m gendesign-server-deploy-key
|
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPYYAH7vPN/b0npfH1IrhADdE+SwJsmo8gJm84VauM4m gendesign-server-deploy-key
|
||||||
|
|
||||||
pg pass 2J2SBPMKuS998fiwhtQqDhMI
|
pg pass 2J2SBPMKuS998fiwhtQqDhMI
|
||||||
|
|
||||||
|
ssh -i $HOME\.ssh\gendesign_deploy gendesign@46.173.16.127
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue