ci: move deploy pipeline to registry images

This commit is contained in:
a.tolmachev
2026-03-31 09:22:54 +03:00
parent cb23f1eb96
commit 2db056817d
8 changed files with 124 additions and 29 deletions
+84 -11
View File
@@ -12,8 +12,77 @@ concurrency:
group: deploy-${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
env:
IMAGE_TAG: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
ADMIN_API_IMAGE: ghcr.io/${{ github.repository_owner }}/crank-admin-api
MCP_SERVER_IMAGE: ghcr.io/${{ github.repository_owner }}/crank-mcp-server
UI_IMAGE: ghcr.io/${{ github.repository_owner }}/crank-ui
jobs:
build-images:
if: >
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: admin-api
dockerfile: apps/admin-api/Dockerfile
- name: mcp-server
dockerfile: apps/mcp-server/Dockerfile
- name: ui
dockerfile: apps/ui/Dockerfile
steps:
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
- name: Resolve image name
id: image
run: |
case "${{ matrix.name }}" in
admin-api) echo "name=${ADMIN_API_IMAGE}" >> "$GITHUB_OUTPUT" ;;
mcp-server) echo "name=${MCP_SERVER_IMAGE}" >> "$GITHUB_OUTPUT" ;;
ui) echo "name=${UI_IMAGE}" >> "$GITHUB_OUTPUT" ;;
*) exit 1 ;;
esac
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ${{ matrix.name }}
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: |
${{ steps.image.outputs.name }}:${{ env.IMAGE_TAG }}
${{ steps.image.outputs.name }}:main
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
deploy:
needs: build-images
if: >
github.event_name == 'workflow_dispatch' ||
(
@@ -41,28 +110,32 @@ jobs:
printf '%s\n' "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Sync project to server
- name: Sync deployment files to server
run: |
rsync -az --delete \
--exclude ".git" \
--exclude "target" \
--exclude "notes" \
--exclude "node_modules" \
./ "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/"
ssh "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"mkdir -p '${{ secrets.DEPLOY_PATH }}'"
rsync -az docker-compose.yml \
"${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/docker-compose.yml"
- name: Write environment file
run: |
ssh "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"mkdir -p '${{ secrets.DEPLOY_PATH }}' && cat > '${{ secrets.DEPLOY_PATH }}/.env'" \
<<< "${{ secrets.DEPLOY_ENV_FILE }}"
{
printf '%s\n' "${{ secrets.DEPLOY_ENV_FILE }}"
printf 'CRANK_ADMIN_API_IMAGE=%s:%s\n' "${{ env.ADMIN_API_IMAGE }}" "${{ env.IMAGE_TAG }}"
printf 'CRANK_MCP_SERVER_IMAGE=%s:%s\n' "${{ env.MCP_SERVER_IMAGE }}" "${{ env.IMAGE_TAG }}"
printf 'CRANK_UI_IMAGE=%s:%s\n' "${{ env.UI_IMAGE }}" "${{ env.IMAGE_TAG }}"
} | ssh "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"mkdir -p '${{ secrets.DEPLOY_PATH }}' && cat > '${{ secrets.DEPLOY_PATH }}/.env'"
- name: Deploy with Docker Compose
run: |
ssh "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "
set -e
cd '${{ secrets.DEPLOY_PATH }}'
echo '${{ secrets.DEPLOY_REGISTRY_TOKEN }}' | docker login ghcr.io -u '${{ secrets.DEPLOY_REGISTRY_USER }}' --password-stdin
docker compose config -q
docker compose up -d --build --remove-orphans
docker compose pull admin-api mcp-server ui
docker compose up -d --remove-orphans
"
- name: Verify health endpoints