diff --git a/ansible/roles/act_runner/defaults/main.yml b/ansible/roles/act_runner/defaults/main.yml index 2d3a378..cb85188 100644 --- a/ansible/roles/act_runner/defaults/main.yml +++ b/ansible/roles/act_runner/defaults/main.yml @@ -3,6 +3,6 @@ act_runner_version: "0.2.12" act_runner_arch: "linux-amd64" act_runner_gitea_url: "https://git.tarla.io" act_runner_name: "iklim-test-app" -act_runner_labels: "ubuntu-latest,ubuntu-22.04,ubuntu-20.04" +act_runner_labels: "ubuntu-latest,ubuntu-22.04,ubuntu-20.04,test-runner:docker://ubuntu:22.04" # Gitea'dan alınan tek seferlik registration token; kayıt olmadıysa boş bırakılır. act_runner_registration_token: "{{ vault_gitea_runner_token | default('') }}" diff --git a/ansible/roles/act_runner/tasks/main.yml b/ansible/roles/act_runner/tasks/main.yml index cdf8299..b4d8a3c 100644 --- a/ansible/roles/act_runner/tasks/main.yml +++ b/ansible/roles/act_runner/tasks/main.yml @@ -33,19 +33,14 @@ group: gitea-runner mode: "0750" -# Kayıt öncesinde varsayılan config.yaml üretilir; dosya varsa tekrar yazılmaz. -- name: Generate default config.yaml - ansible.builtin.shell: - cmd: /usr/local/bin/act_runner generate-config > /etc/gitea-act-runner/config.yaml - creates: /etc/gitea-act-runner/config.yaml - become_user: gitea-runner - -- name: Fix config.yaml ownership - ansible.builtin.file: - path: /etc/gitea-act-runner/config.yaml +- name: Deploy act_runner config + ansible.builtin.template: + src: config.yaml.j2 + dest: /etc/gitea-act-runner/config.yaml owner: gitea-runner group: gitea-runner mode: "0640" + notify: restart act_runner # .runner dosyası varsa runner zaten kayıtlıdır; creates ile idempotent hale gelir. - name: Register runner with Gitea diff --git a/ansible/roles/act_runner/templates/config.yaml.j2 b/ansible/roles/act_runner/templates/config.yaml.j2 new file mode 100644 index 0000000..bd96204 --- /dev/null +++ b/ansible/roles/act_runner/templates/config.yaml.j2 @@ -0,0 +1,39 @@ +log: + level: info + +runner: + file: .runner + capacity: 1 + timeout: 3h + insecure: false + fetch_timeout: 5s + fetch_interval: 2s + labels: +{% for label in act_runner_labels.split(',') %} + - "{{ label }}" +{% endfor %} + +cache: + enabled: true + dir: "" + host: "" + port: 0 + external_server: "" + +container: + # Job container'ları iklimco-net overlay network'üne katılır; + # böylece iklim-db_postgresql ve iklim-db_mongodb servislerine direkt erişebilir. + network: "iklimco-net" + enable_ipv6: false + privileged: false + # Docker socket mount: docker build/push/stack komutlarının çalışması için gerekli. + options: "-v /var/run/docker.sock:/var/run/docker.sock" + workdir_parent: "" + valid_volumes: + - "/var/run/docker.sock" + docker_host: "" + force_pull: false + force_rebuild: false + +host: + workdir_parent: "" diff --git a/roadmap/test-env/07-deploy-pipeline-update.md b/roadmap/test-env/07-deploy-pipeline-update.md index 81e2f86..c1fd602 100644 --- a/roadmap/test-env/07-deploy-pipeline-update.md +++ b/roadmap/test-env/07-deploy-pipeline-update.md @@ -134,7 +134,8 @@ Final step order in the pipeline: 14. **Prepare SWAG Directories** ← NEW 15. Deploy Swarm Stack 16. **Bootstrap SWAG Certificate** ← NEW -17. Review Environment +17. **Run Database Init Scripts** ← NEW (önceki oturumda eklendi) +18. Review Environment > Steps 8 (Provision Vault) runs before SWAG because it creates Docker secrets and > AppRole IDs — Vault must be reachable for this. On re-deploys, Vault is already diff --git a/setup-vs-roadmap-map.md b/setup-vs-roadmap-map.md index 2884ef5..1aa26ce 100644 --- a/setup-vs-roadmap-map.md +++ b/setup-vs-roadmap-map.md @@ -18,8 +18,14 @@ Terraform/Ansible setup aşamalarından hangisinde ele alındığını gösterir | `/opt/iklimco/...` dizinleri | **Ansible `03-test-ansible-bootstrap.md`** — `node_dirs` role | | StorageBox DAVFS mount (`u469968-sub4`) | **Ansible `03-test-ansible-bootstrap.md`** — `storagebox` role | | DB stack deploy (PostgreSQL + MongoDB on `iklim-db-01`) | **Manuel `04-test-db-docker-kurulum.md`** | -| `act_runner` systemd kurulumu | **Ansible `05-test-runner-ve-deploy-onkosullari.md`** — `gitea_runner` role | +| `act_runner` systemd kurulumu | **Ansible `05-test-runner-ve-deploy-onkosullari.md`** — `act_runner` role (`test-app-post-stack.yml`) | | GoDaddy credentials storagebox'a yükleme | **Manuel kalır** — secret yönetimi, Terraform/Ansible dışı | +| `docker-stack-infra.yml` port kaldırma + SWAG/cert-reloader ekleme | **Pipeline `deploy-test.yml`** + **repo değişikliği** — `roadmap/test-env/03` | +| SWAG nginx proxy conf'ları (`swag/proxy-confs/*.conf.tpl`) | **Repo içinde teslim edildi** — `roadmap/test-env/04` | +| APISIX SSL cert yükleme bloğu kaldırma (`init/apisix-core/init.sh`) | **Repo değişikliği** — `roadmap/test-env/05` | +| cert-reloader sidecar servisi | **`docker-stack-infra.yml`'e eklendi** — `roadmap/test-env/06` | +| Pipeline güncelleme: Prepare SWAG Dirs + Bootstrap SWAG Cert + Run DB Init | **`deploy-test.yml`** — `roadmap/test-env/07` | +| Deployment sonrası doğrulama kontrol listesi | **Manuel `roadmap/test-env/08-verify.md`** | ## PROD ortamı @@ -40,7 +46,7 @@ Terraform/Ansible setup aşamalarından hangisinde ele alındığını gösterir | etcd cluster deploy (Patroni için) | **Manuel `08-prod-db-cluster-kurulum.md`** — Bölüm 5.2 | | MongoDB replica set deploy | **Manuel `08-prod-db-cluster-kurulum.md`** — Bölüm 4 | | Patroni + PostgreSQL HA deploy | **Manuel `08-prod-db-cluster-kurulum.md`** — Bölüm 5.4 | -| 3× `act_runner` systemd (HA runner) | **Ansible `09-prod-runner-ha-ve-swarm.md`** — `gitea_runner` role | +| 3× `act_runner` systemd (HA runner) | **Ansible `09-prod-runner-ha-ve-swarm.md`** — `act_runner` role | | GoDaddy credentials storagebox'a yükleme | **Manuel kalır** — secret yönetimi, Terraform/Ansible dışı | ## Klasör yapısı diff --git a/setup/00-genel-yol-haritasi.md b/setup/00-genel-yol-haritasi.md index 81f7aa1..8d9cc39 100644 --- a/setup/00-genel-yol-haritasi.md +++ b/setup/00-genel-yol-haritasi.md @@ -68,7 +68,7 @@ Public internete acik portlar sadece: `8200/tcp` Vault public internete acilmayacak. Vault sadece private network veya Docker overlay icinden erisilebilir olmalidir. -Mevcut uygulama stack dosyalarinda bazi servisler host port publish ediyor olabilir. Hetzner Cloud firewall public ingress'i engelleyecegi icin bu portlar public'ten erisilemez olmalidir. Ancak uzun vadede stack manifestleri de bu politikaya uyacak sekilde sadeleştirilmelidir. +`docker-stack-infra.yml` bu politikaya uygun hale getirilmiştir: yalnızca SWAG servisi 80/443 portlarını yayınlar; Vault, APISIX, RabbitMQ, Prometheus, Grafana gibi tüm diğer servisler yalnızca `iklimco-net` overlay üzerinden erişilebilir. ## Private Network Politikasi diff --git a/setup/01-private-network-port-matrisi.md b/setup/01-private-network-port-matrisi.md index b35edc7..d222ae9 100644 --- a/setup/01-private-network-port-matrisi.md +++ b/setup/01-private-network-port-matrisi.md @@ -79,7 +79,7 @@ Bu portlar public acilmayacak. Sadece private network veya Docker overlay icinde | `9090` | TCP | Prometheus UI/API | Admin CIDR veya private ops | Prometheus service/node | Public kapali | | `3000` | TCP | Grafana UI | Admin CIDR veya private ops | Grafana service/node | Public kapali | -Mevcut `docker-stack-infra.yml` bazi servisleri host mode ile publish ediyor olabilir. Hetzner firewall public ingress'i kapatsa bile private ingress kararini bu tablo belirler. +`docker-stack-infra.yml` güncellenmiş olup yalnızca SWAG servisi 80/443 portlarını host mode ile yayınlar. Diğer tüm servisler published port içermez; erişim yalnızca `iklimco-net` overlay üzerinden sağlanır. Private ingress kararları için bu tablo kaynak olmaya devam eder. ## DB Node Portlari diff --git a/setup/05-test-runner-ve-deploy-onkosullari.md b/setup/05-test-runner-ve-deploy-onkosullari.md index 091042d..16574ae 100644 --- a/setup/05-test-runner-ve-deploy-onkosullari.md +++ b/setup/05-test-runner-ve-deploy-onkosullari.md @@ -6,9 +6,9 @@ Bu aşamanın amacı test ortamında Gitea Actions runner'ı (`act_runner`) syst Test ortamında maliyet ve basitlik için tek runner kullanılır: -| Host | Servis Adı | Label | +| Host | Servis Adı | Etiketler | | --- | --- | --- | -| `iklim-app-01` | `gitea-act-runner` | `test-runner`, `iklim-app-01`, `docker` | +| `iklim-app-01` | `gitea-act-runner` | `ubuntu-latest`, `ubuntu-22.04`, `ubuntu-20.04`, `test-runner` | ## 1. Runner Kullanıcısı ve Yetkiler @@ -23,50 +23,53 @@ sudo usermod -aG docker gitea-runner ## 2. act_runner Kurulumu -### Binary İndirme +### 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.10/act_runner-0.2.10-linux-amd64 +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) bir **Registration Token** alın. -```bash -# Config dosyasını oluştur -act_runner generate-config > config.yaml +Gitea arayüzünden (Organization → Settings → Actions → Runners) **Registration Token** alın, vault'a ekleyin: -# Kayıt işlemini gerçekleştir -act_runner register --instance https://git.tarla.io --token --no-interactive -``` -*Not: Kayıt sırasında label olarak `test-runner,iklim-app-01,docker` girildiğinden emin olun.* - -## 3. Systemd Servisi - -`/etc/systemd/system/gitea-act-runner.service` dosyasını oluşturun: - -```ini -[Unit] -Description=Gitea Actions runner -After=network.target docker.service - -[Service] -ExecStart=/usr/local/bin/act_runner daemon --config /etc/gitea-act-runner/config.yaml -WorkingDirectory=/var/lib/gitea-runner -User=gitea-runner -Group=gitea-runner -Restart=always -RestartSec=5 - -[Install] -WantedBy=multi-user.target +```yaml +# group_vars/all/vault.yml +vault_gitea_runner_token: "" ``` -Servisi başlatın: ```bash -sudo systemctl daemon-reload -sudo systemctl enable --now gitea-act-runner +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ı @@ -83,13 +86,15 @@ Pipeline'ların çalışması için Gitea Organization seviyesinde şu secret'la | Secret | Açıklama | | --- | --- | -| `STORAGEBOX_SSH_PRIV` | StorageBox'a erişim için private key | -| `HARBOR_USERNAME` | Container registry kullanıcı adı | -| `HARBOR_PASSWORD` | Container registry şifresi | +| `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) | ## Kabul Kriterleri -1. Gitea Runners sayfasında `iklim-app-01` statusü **Idle** (yeşil) görünür. -2. Bir test workflow'u (`runs-on: test-runner`) başarıyla tetiklenir. -3. Runner, host üzerindeki Docker daemon'a erişip konteyner oluşturabilir. +1. Gitea Runners sayfasında `iklim-test-app` 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.