Встроенная CI/CD система Gitea Actions, миграция с GitHub Actions, интеграция с Jenkins и GitLab CI, пайплайны.
Встроенная CI/CD система Gitea Actions, миграция с GitHub Actions, интеграция с Jenkins и GitLab CI, пайплайны
CI/CD — это кровеносная система современной разработки. Автоматическая сборка, тестирование и развёртывание кода экономят часы ручной работы и предотвращают человеческие ошибки.
Gitea предлагает два подхода:
Эта тема научит вас настраивать оба подхода.
┌─────────────────────────────────────────────────────────────────┐
│ Gitea Server │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ Workflow Engine │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │ │
│ │ │ Runner │ │ Runner │ │ Runner │ │ │
│ │ │ (Docker) │ │ (Kubernetes)│ │ (External) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────────┘ │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
↑ ↑ ↑
.gitea/workflows/ Кастомные runner'ы Внешние runner'ы
app.ini:
[actions]
ENABLED = true
; URL для runner'ов
URL = http://git.company.ru:3000
; Хранилище артефактов
STORAGE_TYPE = local
ARTIFACT_STORAGE_PATH = /data/gitea-actions/artifactsФайл: .gitea/workflows/ci.yml
name: CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test -- --coverage
- name: Build application
run: npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/Вариант 1: Docker runner (рекомендуется для начала)
docker-compose.runner.yml:
version: '3.8'
services:
gitea-runner:
image: gitea/act_runner:latest
container_name: gitea-runner
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./runner-data:/data
environment:
- GITEA_INSTANCE_URL=http://git.company.ru:3000
- GITEA_RUNNER_REGISTRATION_TOKEN=your_registration_token
- GITEA_RUNNER_NAME=docker-runner-1
- GITEA_RUNNER_LABELS=ubuntu-latest:docker://node:20-bullseye
networks:
- gitea-net
networks:
gitea-net:
external: trueПолучение токена регистрации:
Вариант 2: Бинарный runner (для bare-metal)
# Скачивание
wget https://github.com/gitea/act_runner/releases/latest/download/act_runner-linux-amd64
# Сделать исполняемым
chmod +x act_runner-linux-amd64
# Регистрация
./act_runner-linux-amd64 register --instance http://git.company.ru:3000 --token YOUR_TOKEN
# Запуск
./act_runner-linux-amd64 daemonGitea Actions совместим с GitHub Actions на уровне:
GitHub workflow:
name: GitHub CI
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install deps
run: pip install -r requirements.txt
- name: Run tests
run: pytestGitea workflow (практически без изменений):
name: Gitea CI
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install deps
run: pip install -r requirements.txt
- name: Run tests
run: pytest| GitHub Action | Gitea альтернатива |
|---|---|
actions/github-script | gitea/gitea-script-action |
actions/upload-release-asset | gitea/upload-release-action |
| GitHub Container Registry | Gitea Container Registry |
GitHub:
# Через CLI
gh secret set DEPLOY_KEY --repo org/repoGitea:
DEPLOY_KEY, Value: ...Или через API:
curl -X POST http://git.company.ru/api/v1/repos/{owner}/{repo}/actions/secrets/{secret_name} \
-H "Authorization: token $TOKEN" \
-d '{"data": "encrypted_value"}'name: Matrix Build
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22]
os: [ubuntu-latest, windows-latest]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Test on ${{ matrix.os }}
run: npm testname: CI with Cache
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Cache build output
uses: actions/cache@v4
with:
path: dist/
key: ${{ runner.os }}-build-${{ github.sha }}
- run: npm ci
- run: npm run buildname: Docker Build
on:
push:
tags: ['v*']
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Gitea Registry
uses: docker/login-action@v3
with:
registry: git.company.ru:5000
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
git.company.ru:5000/org/app:${{ github.ref_name }}
git.company.ru:5000/org/app:latest
cache-from: type=registry,ref=git.company.ru:5000/org/app:buildcache
cache-to: type=registry,ref=git.company.ru:5000/org/app:buildcache,mode=maxname: Conditional Deploy
on:
push:
branches: [main, develop, 'release/*']
jobs:
deploy:
runs-on: ubuntu-latest
# Запуск только для main или release/*
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')
steps:
- uses: actions/checkout@v4
- name: Deploy to production
if: github.ref == 'refs/heads/main'
run: ./deploy.sh production
- name: Deploy to staging
if: startsWith(github.ref, 'refs/heads/release/')
run: ./deploy.sh staginghttp://jenkins.company.ru/gitea-webhook/your-webhook-secretJenkinsfile:
pipeline {
agent any
triggers {
pollSCM('') // Пустой pollSCM для webhook-триггера
}
environment {
GITEA_URL = 'http://git.company.ru'
GITEA_CREDENTIALS = 'gitea-credentials'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'npm ci'
sh 'npm run build'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh './deploy.sh'
}
}
}
post {
always {
junit 'reports/*.xml'
}
failure {
mail to: 'team@company.ru',
subject: "Build Failed: ${currentBuild.fullDisplayName}",
body: "Check ${BUILD_URL}"
}
}
}Установка плагина:
# Через Jenkins UI: Manage Jenkins → Plugins
# Или через CLI
java -jar jenkins-cli.jar install-plugin giteaНастройка в Jenkins:
http://git.company.ruЕсли вы мигрируете с GitLab, можно временно использовать GitLab Runner:
# Установка GitLab Runner
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt-get install gitlab-runner
# Регистрация (через generic webhook)
sudo gitlab-runner register \
--non-interactive \
--url "http://git.company.ru" \
--registration-token "YOUR_TOKEN" \
--executor "docker" \
--docker-image docker:latest \
--description "Gitea Runner" \
--tag-list "gitea,docker" \
--run-untagged="true" \
--locked="false".gitlab-ci.yml (адаптированный):
stages:
- build
- test
- deploy
build:
stage: build
image: node:20
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 week
test:
stage: test
image: node:20
script:
- npm ci
- npm test
coverage: '/Lines\s*:\s*(\d+.\d+)\%/'
deploy:
stage: deploy
image: alpine:latest
script:
- apk add --no-cache curl
- curl -X POST $DEPLOY_URL
only:
- main
environment:
name: production
url: https://app.company.ruSlack webhook:
name: Slack Notify
on:
push:
pull_request:
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send Slack notification
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"text": "New push to ${{ github.repository }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*New Push*: ${{ github.repository }}\nBranch: ${{ github.ref_name }}\nAuthor: ${{ github.actor }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}Telegram webhook:
name: Telegram Notify
on: [push]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send Telegram message
run: |
curl -X POST "https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendMessage" \
-d "chat_id=${{ secrets.TG_CHAT_ID }}" \
-d "text=🔨 New push to ${{ github.repository }}%0ABranch: ${{ github.ref_name }}%0ACommit: ${{ github.sha }}"name: Jira Transition
on:
pull_request:
types: [opened, closed]
jobs:
transition:
runs-on: ubuntu-latest
steps:
- name: Transition Jira issue
uses: atlassian/gajira-transition@v3
with:
issue: PROJ-${{ github.event.pull_request.number }}
transition: In Review# .gitea/workflows/ci.yml - для PR и develop
name: CI
on:
push:
branches: [develop]
pull_request:
jobs:
test:
# Только тесты# .gitea/workflows/cd.yml - для production
name: CD
on:
push:
branches: [main]
jobs:
deploy:
# Развёртывание с approval# .gitea/workflows/templates/test.yml
name: Reusable Test
on:
workflow_call:
inputs:
node-version:
required: true
type: string
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- run: npm testИспользование:
name: Main CI
on: [push]
jobs:
test-18:
uses: ./.gitea/workflows/templates/test.yml
with:
node-version: '18'
test-20:
uses: ./.gitea/workflows/templates/test.yml
with:
node-version: '20'# Никогда не логируйте secrets
- name: Deploy
run: |
# Плохо: секрет может попасть в логи
echo "Deploying with key: $DEPLOY_KEY"
# Хорошо: используйте secret в команде
echo "$DEPLOY_KEY" | ssh-add -
ssh deploy@app.company.ru "./deploy.sh"
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}jobs:
flaky-test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Run tests with retry
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: npm testСледующий шаг: Мониторинг и логирование
Вопросы ещё не добавлены
Вопросы для этой подтемы ещё не добавлены.