Environment_Infrastructure/setup/05-test-runner-ve-deploy-onkosullari.md
Murat ÖZDEMİR 3bf0a513f9 docs(setup): sync 01-05 documentation with actual terraform/ansible/workflow
- 01: Add WireGuard 51820/udp to public ingress table; add 9000/tcp
  (APISIX Dashboard) to admin CIDR row in test private rules
- 02: Fix admin_ssh_public_key_path (id_rsa.pub, not id_ed25519.pub);
  add WireGuard 51820/udp to DB firewall table; clarify 9000/9180 port
  descriptions (app subnet access + SWAG proxy)
- 03: Update file structure with new roles (db_stack, wireguard,
  act_runner) and playbooks (test-app/db-post-stack.yml); add floating
  IP systemd service to base role description; clarify node labels
- 04: Clarify two-phase deployment (Ansible prepares dirs/config,
  Gitea CI/CD deploys stack); add WireGuard setup info
- 05: Add system user column to runner table; fix runner name in
  acceptance criteria (iklim-test-app → test-runner)
2026-05-14 16:13:25 +03:00

120 lines
4.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 05 - Test Runner ve Deploy Ön Koşulları
Bu aşamanın amacı test ortamında Gitea Actions runner'ı (`act_runner`) systemd servisi olarak kurmak ve CI/CD pipeline'larının çalışabileceği ortamı hazırlamaktır.
## Runner Yerleşimi
Test ortamında maliyet ve basitlik için tek runner kullanılır:
| Host | Servis Adı | Sistem Kullanıcısı | Etiketler |
| --- | --- | --- | --- |
| `iklim-app-01` | `gitea-act-runner` | `gitea-runner` | `ubuntu-latest`, `ubuntu-22.04`, `ubuntu-20.04`, `test-runner` |
## 1. Runner Kullanıcısı ve Yetkiler
Runner, host üzerinde Docker komutlarını çalıştırabilmelidir.
```bash
# Kullanıcıyı oluştur
sudo useradd -m -s /bin/bash gitea-runner
# Docker grubuna ekle
sudo usermod -aG docker gitea-runner
```
## 2. act_runner Kurulumu
### Kurulum
Kurulum ve kayıt Ansible ile otomatik yapılır (`test-app-post-stack.yml`). Manuel kurulum gerekirse:
```bash
wget -O act_runner https://dl.gitea.com/act_runner/0.2.12/act_runner-0.2.12-linux-amd64
sudo mv act_runner /usr/local/bin/
sudo chmod +x /usr/local/bin/act_runner
```
### Kayıt (Registration)
Gitea arayüzünden (Organization → Settings → Actions → Runners) **Registration Token** alın, vault'a ekleyin:
```yaml
# group_vars/all/vault.yml
vault_gitea_runner_token: "<TOKEN>"
```
```bash
cd Environment_Infrastructure/ansible/test
ansible-playbook test-app-post-stack.yml --vault-password-file=.vault_pass
```
## 3. Systemd Servisi ve Konfigürasyon
Ansible tarafından yönetilir. Servis dosyası `/etc/systemd/system/gitea-act-runner.service`, konfigürasyon `/etc/gitea-act-runner/config.yaml` konumundadır.
Konfigürasyonun kritik bölümleri:
```yaml
runner:
labels:
- "ubuntu-latest:docker://ubuntu:latest"
- "ubuntu-22.04:docker://ubuntu:22.04"
- "ubuntu-20.04:docker://ubuntu:20.04"
- "test-runner:docker://ubuntu:22.04"
container:
network: "iklimco-net" # DB servislerine overlay üzerinden erişim
options: "-v /var/run/docker.sock:/var/run/docker.sock" # Docker komutları için
```
Durum kontrolü:
```bash
sudo systemctl status gitea-act-runner
sudo journalctl -u gitea-act-runner -f
```
## 4. Deploy Ön Koşulları
Pipeline'ın `iklim-app-01` üzerinde başarılı deploy yapabilmesi için şu araçların kurulu olması şarttır:
- `docker-ce` ve `docker-compose-plugin`
- `gettext` (`envsubst` komutu için)
- `jq`
- `git`
## 5. Gitea Organization Secrets
Pipeline'ların çalışması için Gitea Organization seviyesinde şu secret'lar tanımlanmalıdır:
| Secret | Açıklama |
| --- | --- |
| `STORAGEBOX_SSH_PRIV` | StorageBox SSH private key |
| `STORAGEBOX_SSH_PUB` | StorageBox SSH public key |
| `HARBOR_CI_TOKEN` | `robot-ci-push-iklimco` robot hesabı token'ı (build + push) |
| `HARBOR_PULL_TOKEN` | `robot-swarm-pull-iklimco` robot hesabı token'ı (Swarm deploy pull) |
| `REPO_ACCESS_TOKEN` | Gitea private repo erişimi (BE-Commons vb. checkout) |
## 6. Custom Image Build ve Harbor Push
`docker-stack-infra.yml` ve mikroservis stack'leri `registry.tarla.io/iklimco/` altındaki özel image'leri kullanır. Bu image'ler `ops/push-harbor-custom-images.sh` scripti ile build edilip registry'ye push edilir.
APISIX config dosyaları (`build/apisix-core/config.yaml`, `build/apisix-dashboard/conf.yaml`) `template/` altındaki şablonlardan `envsubst` ile üretilir. Bu üretimi `push-harbor-custom-images.sh` kendi içinde yapar; build bitince geçici dosyalar otomatik temizlenir.
**Tasarım notu:** APISIX admin key image'a bake edilmez. Template'de `${{APISIX_ADMIN_KEY}}` (çift süslü parantez) kullanılır; APISIX bunu container başlarken Docker service ortam değişkeninden okur. Böylece tek image hem test hem prod için kullanılabilir.
### Adımlar
```bash
# 1. Harbor'a login ol
docker login registry.tarla.io -u robot-ci-push-iklimco
# 2. Image'leri build edip push et (env'leri ve config dosyalarını script kendi üretir)
bash ops/push-harbor-custom-images.sh
```
## Kabul Kriterleri
1. Gitea Runners sayfasında `test-runner` etiketli runner **Idle** (yeşil) görünür.
2. `runs-on: test-runner` kullanan bir workflow başarıyla tetiklenir.
3. Job container'ı Docker daemon'a ve `iklimco-net` overlay network'üne erişebilir.
4. `8200/tcp` (Vault) portu public internete kapalıdır.
5. `registry.tarla.io/iklimco/custom-apisix`, `custom-apisix-dashboard`, `custom-prometheus` image'leri Harbor'da mevcut ve çekilebilir durumda.