deploy: staging single-container via host caddy-docker-proxy
- drop caddy/SSL in container (staging only): api service gets caddy labels,
host caddy terminates TLS and routes ${BRANCH}.it-smi.jt4d.ru.net -> :5000
- simplify Dockerfile to single-stage, healthcheck -> /, .dockerignore
- pin packageManager yarn@4.18.0 and use corepack: project is Yarn 4 (berry
lockfile), base image and CI runner ship Yarn 1 and failed on install
- rewrite ci.yaml/cleanup.yaml for flat project (single api image, no Nx)
This commit is contained in:
1 parent
7d8a583f11
commit
25de4ad823
6 files changed
+246
No files matched your search
@@ -0,0 +1,117 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Сборка
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Login to Gitea Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.jt4d.ru
|
||||
username: ${{ vars.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Setup Yarn 4
|
||||
run: npm install -g corepack && corepack enable
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --immutable
|
||||
|
||||
- name: Build
|
||||
run: yarn build
|
||||
|
||||
- name: Build api docker image
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: true
|
||||
tags: git.jt4d.ru/${{ github.repository }}/api:${{ github.head_ref || github.ref_name }}
|
||||
cache-from: git.jt4d.ru/${{ github.repository }}/api:latest
|
||||
labels: |
|
||||
org.opencontainers.image.ref.name=${{ github.head_ref || github.ref_name }}
|
||||
|
||||
deploy-staging:
|
||||
name: Деплой на стейджинг
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
env:
|
||||
DEPLOY_URL: https://${{ github.head_ref || github.ref_name }}.it-smi.jt4d.ru.net
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Deploy via SSH
|
||||
uses: jt4d-lab/ssh-action@v1
|
||||
env:
|
||||
BRANCH: ${{ github.head_ref || github.ref_name }}
|
||||
with:
|
||||
host: ${{ vars.STAGING_HOST }}
|
||||
username: ${{ vars.STAGING_USER }}
|
||||
key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }}
|
||||
port: ${{ vars.STAGING_PORT }}
|
||||
workdir: /home/${{ vars.STAGING_USER }}/${{ github.event.repository.name }}_${{ github.head_ref || github.ref_name }}
|
||||
files: docker-compose.staging.yml
|
||||
script_stop: true
|
||||
envs: BRANCH
|
||||
script: |
|
||||
mv -f docker-compose.staging.yml docker-compose.yml
|
||||
# \${BRANCH} — литеральный плейсхолдер в docker-compose.staging.yml,
|
||||
# $BRANCH — имя ветки из окружения.
|
||||
sed -i "s/\${BRANCH}/$BRANCH/g" docker-compose.yml
|
||||
docker compose pull --quiet
|
||||
staging-db-postgres create "${{ github.repository }}" "$BRANCH"
|
||||
docker compose down
|
||||
docker compose up -d
|
||||
|
||||
docker system prune -f
|
||||
|
||||
- name: Set deployment status
|
||||
env:
|
||||
BRANCH: ${{ github.head_ref || github.ref_name }}
|
||||
run: |
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"state": "success",
|
||||
"context": "Стенд",
|
||||
"description": "'"$BRANCH"'",
|
||||
"target_url": "'"$DEPLOY_URL"'"
|
||||
}' \
|
||||
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}"
|
||||
|
||||
- name: Write stand URL to summary
|
||||
run: echo "**Стенд:** $DEPLOY_URL" >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
check:
|
||||
name: Проверка кода
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Yarn 4
|
||||
run: npm install -g corepack && corepack enable
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --immutable
|
||||
|
||||
- name: Lint
|
||||
run: yarn lint
|
||||
Reference in new issue
Block a user