aboutsummaryrefslogtreecommitdiff
path: root/content/post/2023-01-12-gitrepo.md
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-11-10 00:04:43 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-11-10 00:04:43 +0300
commit8e79098193fd0a8b65305dd8054cf7c424c60bc5 (patch)
treeaa894af1e2463e4919885a5bca700ab742012b4c /content/post/2023-01-12-gitrepo.md
parent59c7d4567380d1a9c80e96eb958fdbdd512ce006 (diff)
новая жизнь блога 2
Diffstat (limited to 'content/post/2023-01-12-gitrepo.md')
-rw-r--r--content/post/2023-01-12-gitrepo.md122
1 files changed, 114 insertions, 8 deletions
diff --git a/content/post/2023-01-12-gitrepo.md b/content/post/2023-01-12-gitrepo.md
index 8635d1d..18a06a2 100644
--- a/content/post/2023-01-12-gitrepo.md
+++ b/content/post/2023-01-12-gitrepo.md
@@ -3,12 +3,12 @@ author: NeonXP
categories:
- Мои проекты
date: "2023-01-12T20:22:00Z"
-guid: http://10
id: 55
tags:
- it
- моё
title: GitRepo.ru
+draft: false
---
# Сегодня серьезно переделал свой хостинг [репозиториев кода](https://gitrepo.ru/):
@@ -30,26 +30,132 @@ title: GitRepo.ru
У меня на руках `docker-compose.yml` который полностью описывает всю конфигурацию сервака, примерно так:
-<div class="highlight">```yml
-<span style="display:flex;"><span><span style="color:#f92672">version</span>: <span style="color:#e6db74">"3"</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#f92672">services</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">caddy</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">image</span>: <span style="color:#ae81ff">caddy:2.6.2-alpine</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">container_name</span>: <span style="color:#ae81ff">gateway</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">restart</span>: <span style="color:#ae81ff">unless-stopped</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">ports</span>:</span></span><span style="display:flex;"><span> - <span style="color:#e6db74">"80:80"</span></span></span><span style="display:flex;"><span> - <span style="color:#e6db74">"443:443"</span></span></span><span style="display:flex;"><span> - <span style="color:#e6db74">"443:443/udp"</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">./Caddyfile:/etc/caddy/Caddyfile</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">caddy_data:/data</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">caddy_config:/config</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">networks</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gateway</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#f92672">git</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">image</span>: <span style="color:#ae81ff">codeberg.org/forgejo/forgejo:1.18.0-1</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">container_name</span>: <span style="color:#ae81ff">git</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">environment</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">USER_UID=1000</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">USER_GID=1000</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">TZ=Europe/Moscow</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">USER=git</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">GITEA__database__DB_TYPE=postgres</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">GITEA__database__HOST=db:5432</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">GITEA__database__NAME=${PG_NAME}</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">GITEA__database__USER=${PG_USER}</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">GITEA__database__PASSWD=${PG_PASS}</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">restart</span>: <span style="color:#ae81ff">always</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">networks</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gitea</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gateway</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">/home/git/.ssh/:/data/git/.ssh</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">forgejo:/data</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">/etc/timezone:/etc/timezone:ro</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">/etc/localtime:/etc/localtime:ro</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">ports</span>:</span></span><span style="display:flex;"><span> - <span style="color:#e6db74">"127.0.0.1:2222:22"</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">depends_on</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">db</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">condition</span>: <span style="color:#ae81ff">service_healthy</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#f92672">db</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">image</span>: <span style="color:#ae81ff">postgres:13</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">restart</span>: <span style="color:#ae81ff">always</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">environment</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">POSTGRES_USER=${PG_USER}</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">POSTGRES_PASSWORD=${PG_PASS}</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">POSTGRES_DB=${PG_NAME}</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">healthcheck</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">test</span>: <span style="color:#ae81ff">/usr/bin/pg_isready</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">interval</span>: <span style="color:#ae81ff">5s</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">timeout</span>: <span style="color:#ae81ff">10s</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">retries</span>: <span style="color:#ae81ff">120</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">networks</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gitea</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">postgres:/var/lib/postgresql/data</span></span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span> <span style="color:#f92672">woodpecker-server</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">image</span>: <span style="color:#ae81ff">woodpeckerci/woodpecker-server:latest</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">woodpecker-server-data:/var/lib/woodpecker/</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">environment</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_OPEN=true</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_GITEA=true</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_GITEA_URL=https://gitrepo.ru</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_GITEA_CLIENT=${GITEA_CLIENT}</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_GITEA_SECRET=${GITEA_SECRET}</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_HOST=https://ci.gitrepo.ru</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_ADMIN=neonxp</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">networks</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gitea</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gateway</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">depends_on</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">git</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#f92672">woodpecker-agent</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">image</span>: <span style="color:#ae81ff">woodpeckerci/woodpecker-agent:latest</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">command</span>: <span style="color:#ae81ff">agent</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">restart</span>: <span style="color:#ae81ff">always</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">depends_on</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">woodpecker-server</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">/var/run/docker.sock:/var/run/docker.sock</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">environment</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_SERVER=woodpecker-server:9000</span></span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}</span></span></span><span style="display:flex;"><span> <span style="color:#f92672">networks</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">gitea</span></span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span><span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">woodpecker-server-data</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">caddy_data</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">caddy_config</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">forgejo</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">postgres</span>:</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#f92672">networks</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">gateway</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">gitea</span>:</span></span><span style="display:flex;"><span> <span style="color:#f92672">external</span>: <span style="color:#66d9ef">false</span></span></span>
+```yml
+version: "3"
+services:
+ caddy:
+ image: caddy:2.6.2-alpine
+ container_name: gateway
+ restart: unless-stopped
+ ports:
+ - "80:80"
+ - "443:443"
+ - "443:443/udp"
+ volumes:
+ - ./Caddyfile:/etc/caddy/Caddyfile
+ - caddy_data:/data
+ - caddy_config:/config
+ networks:
+ - gateway
+ git:
+ image: codeberg.org/forgejo/forgejo:1.18.0-1
+ container_name: git
+ environment:
+ - USER_UID=1000
+ - USER_GID=1000
+ - TZ=Europe/Moscow
+ - USER=git
+ - GITEA__database__DB_TYPE=postgres
+ - GITEA__database__HOST=db:5432
+ - GITEA__database__NAME=${PG_NAME}
+ - GITEA__database__USER=${PG_USER}
+ - GITEA__database__PASSWD=${PG_PASS}
+ restart: always
+ networks:
+ - gitea
+ - gateway
+ volumes:
+ - /home/git/.ssh/:/data/git/.ssh
+ - forgejo:/data
+ - /etc/timezone:/etc/timezone:ro
+ - /etc/localtime:/etc/localtime:ro
+ ports:
+ - "127.0.0.1:2222:22"
+ depends_on:
+ db:
+ condition: service_healthy
+ db:
+ image: postgres:13
+ restart: always
+ environment:
+ - POSTGRES_USER=${PG_USER}
+ - POSTGRES_PASSWORD=${PG_PASS}
+ - POSTGRES_DB=${PG_NAME}
+ healthcheck:
+ test: /usr/bin/pg_isready
+ interval: 5s
+ timeout: 10s
+ retries: 120
+ networks:
+ - gitea
+ volumes:
+ - postgres:/var/lib/postgresql/data
+ woodpecker-server:
+ image: woodpeckerci/woodpecker-server:latest
+ volumes:
+ - woodpecker-server-data:/var/lib/woodpecker/
+ environment:
+ - WOODPECKER_OPEN=true
+ - WOODPECKER_GITEA=true
+ - WOODPECKER_GITEA_URL=https://gitrepo.ru
+ - WOODPECKER_GITEA_CLIENT=${GITEA_CLIENT}
+ - WOODPECKER_GITEA_SECRET=${GITEA_SECRET}
+ - WOODPECKER_HOST=https://ci.gitrepo.ru
+ - WOODPECKER_ADMIN=neonxp
+ - WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
+ networks:
+ - gitea
+ - gateway
+ depends_on:
+ - git
+ woodpecker-agent:
+ image: woodpeckerci/woodpecker-agent:latest
+ command: agent
+ restart: always
+ depends_on:
+ - woodpecker-server
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
+ environment:
+ - WOODPECKER_SERVER=woodpecker-server:9000
+ - WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
+ networks:
+ - gitea
+volumes:
+ woodpecker-server-data:
+ caddy_data:
+ caddy_config:
+ forgejo:
+ postgres:
+networks:
+ gateway:
+ gitea:
+ external: false
+
```
-</div>а рядом лежит `.env` файлик с значениями переменных `${...}`.
+а рядом лежит `.env` файлик с значениями переменных `${...}`.
Запускаю деплой я с локального компьютера, предварительно добавив удаленный сервер в [контекст докера](https://docs.docker.com/engine/context/working-with-contexts/):
```
-docker context create gitrepo --docker "host=ssh://gitrepo.ru" # Создаю новый контекст для удаленного сервераdocker use gitrepo # Все последующие docker команды выполняются на удаленном сервереdocker use default # Возвращаюсь в локальный контекст
+# Создаю новый контекст для удаленного сервера
+docker context create gitrepo --docker "host=ssh://gitrepo.ru"
+# Все последующие docker команды выполняются на удаленном сервере
+docker use gitrepo
+# Возвращаюсь в локальный контекст
+docker use default
```
## Оставшиеся проблемы
Сейчас так получается, что Caddyfile должен лежать на удаленном сервере, т.к. часть конфига
-<div class="highlight">```yml
-<span style="display:flex;"><span><span style="color:#f92672">volumes</span>:</span></span><span style="display:flex;"><span> - <span style="color:#ae81ff">./Caddyfile:/etc/caddy/Caddyfile</span></span></span>
+```yml
+ volumes:
+ - ./Caddyfile:/etc/caddy/Caddyfile
```
-</div>выполняется в контексте именно удаленного сервера, а значит при его апдейте на локальном серваке приходится делать SCP этого файла на сервак. Такое себе.
+выполняется в контексте именно удаленного сервера, а значит при его апдейте на локальном серваке приходится делать SCP этого файла на сервак. Такое себе.
Как это решить — есть интересная идея, но это уже в другой раз. \ No newline at end of file