From 30d80247f24962aa776e079c231a9968a1ab341f Mon Sep 17 00:00:00 2001 From: sonny Date: Tue, 22 Oct 2024 22:07:41 +0200 Subject: [PATCH] Add forgejo runner setup --- playbook.yml | 64 ++++++++++++++++++++++++++++++++----- templates/docker-compose.j2 | 24 ++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/playbook.yml b/playbook.yml index 440aa09..e537f8d 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,17 +1,64 @@ - hosts: localhost tasks: + - name: create git user + become: true + user: + name: git + uid: 1001 + group: git + create_home: false + - name: create required directories become: true file: - path: '{{ item }}' - state: directory - mode: '0755' - owner: sonny - group: sonny + path: '{{ item.path }}' + state: '{{ item.state }}' + mode: '{{ item.mode }}' + owner: '{{ item.owner }}' + group: '{{ item.group }}' loop: - - '{{ app_dir }}' - - '{{ data_dir }}' - - '{{ postgres_dir }}' + - { + path: '{{ app_dir }}', + owner: sonny, + group: sonny, + state: directory, + mode: 755 + } + - { + path: '{{ data_dir }}', + owner: sonny, + group: sonny, + state: directory, + mode: 755 + } + - { + path: '{{ postgres_dir }}', + owner: sonny, + group: sonny, + state: directory, + mode: 755 + } + - { + path: '{{ runner_dir }}', + owner: git, + group: git, + state: directory, + mode: 755 + } + - { + path: '{{ runner_dir }}/.cache', + owner: git, + group: git, + state: directory, + mode: 2775 + } + - { + path: '{{ runner_dir }}/.runner', + owner: git, + group: git, + state: touch, + mode: 2775 + } - name: copy docker-compose file template: @@ -39,6 +86,7 @@ app_dir: '/srv/docker/forgejo' data_dir: '/home/sonny/vm/forgejo/data' postgres_dir: '/home/sonny/vm/forgejo/postgres' + runner_dir: '/home/sonny/vm/forgejo/runner' image_tag: 'codeberg.org/forgejo/forgejo:9' diff --git a/templates/docker-compose.j2 b/templates/docker-compose.j2 index 423fab4..49dd00a 100644 --- a/templates/docker-compose.j2 +++ b/templates/docker-compose.j2 @@ -43,3 +43,27 @@ services: - forgejo volumes: - {{ postgres_dir }}:/var/lib/postgresql/data + + docker-in-docker: + image: docker:dind + privileged: true + container_name: 'docker_dind' + command: ['dockerd', '--host', 'tcp://0.0.0.0:2375', '--tls=false'] + restart: 'unless-stopped' + + # see https://forgejo.org/docs/latest/admin/runner-installation/#oci-image-installation + runner: + image: 'code.forgejo.org/forgejo/runner:3.4.1' + user: 1001:1001 # User without root privileges, but with access to {{ runner_dir }} + command: '/bin/sh -c "sleep 5; forgejo-runner daemon"' + environment: + DOCKER_HOST: tcp://docker-in-docker:2375 + links: + - docker-in-docker + depends_on: + docker-in-docker: + condition: service_started + + volumes: + - {{ runner_dir }}:/data + restart: 'unless-stopped'