Skip to content

--- tags: - Gogscategories: - Containerdate:created: 2020-08-26# updated: 2024-01-19---

Build Git Server Using Gogs with Docker and Employ Frp with Caddy Reverse Proxy## Goals- Run Gogs on Raspberry Pi and deploy using Docker- Since the Raspberry Pi is on the internal network, Frp needs to be used for internal network penetration.- Use Caddy+CDN proxy to speed up access to Gogs

Requirements- Raspberry 3B+- Domain- Cloudflare Account- VPS with Public IPv4 Address

1. Install Docker on RaspberryPi 3B+#### (1). Use docker’s official one-click installation script:```

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

#### (2). Add the current user to the`docker`group:```
sudo groupadd docker
sudo usermod -aG docker $USER

(3). Set up image acceleration for docker:`sudo vim /etc/docker/daemon.json````

{ "registry-mirrors": [ "https://1nj0zren.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "http://f1361db2.m.daocloud.io", "https://registry.docker-cn.com" ] }

`sudo systemctl daemon-reload``sudo systemctl restart docker`
## 2. Install Gogs with Docker#### (1). Download the image file`docker pull gogs/gogs-rpi`#### (2). Run the image```
docker run  \
--name=gogs-rpi -d \
--restart=always \
-p 10022:22 -p 13000:3000 \
-v /data/gogs:/data gogs/gogs-rpi
- 10022:22->Map the local port 10022 to 22 in docker- 13000:3000->Map the local port 13000 to 3000 in docker- /data/gogs is the location where data is stored on this machine

3. Install Gogs with docker-compose Orchestration using MySQL (optional)#### (1). Install docker-compose```

sudo apt-get install docker-compose

#### (2). Arrange docker-compose.yaml content```
version: "3"
services:
    db:
        image: mysql:5.7
        container_name: MySQL5.7
        restart: always
        ports:
            - "13306:3306"
        volumes:
            - ${pwd_DB}/gogs_DB:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: AdminMySQL
            MYSQL_DATABASE: gogs
            MYSQL_USER: gogs
            MYSQL_PASSWORD: passwordgogs
            TZ: Asia/Shanghai
    docker-gogs:
        depends_on:
            - db
        image: gogs/gogs
        container_name: docker-gogs
        restart: always
        ports:
            - "10022:22"
            - "13000:3000"
        volumes:
            - ${pwd_gogs}/data:/data

(3). Run docker containerEnter the path wheredocker-compose.yamlis located and run:```

docker-compose up -d

> #### When using MySQL as the data storage, on the settings page of gogs, you need to set the database address to`db:3306`
## 4. Configuration of Domain#### (1). First change the nameservers of the domain name to cloudflare, refer to[Change nameservers to cloudflare](https://support.cloudflare.com/hc/en-us/articles/205195708-Step-3-Change-your-domain-name-servers-to-Cloudflare)#### (2). Resolve the domain name to the IP address of the VPS in Cloudflare, and turn off PrivateDNS, orange cloud -> gray#### (3). After gogs configuration is completed, open PrivateDNS
## 5.Configuration of FRP### Server Config```
[common]
bind_port = [your port1]
token =  [your token]
vhost_http_port = [your port2]
bing_udp_port = [your port3]
vhost_https_port = [your port4]

Client Config```

[common] server_addr = [your ip] server_port = [your port] token = [your token]

[Gogs] type = tcp local_ip = 127.0.0.1 local_port = 13000 remote_port = 8888

> - It should be noted here that the`13000`port is the port mapped by the gogs container on the Raspberry Pi, which should correspond to the port running on docker before.
## 6. Configuration of Caddy On VPS#### (1). Install Caddy, refer to[Use RaspberryPi to build Aria2+Caddy2 download station](https://www.wannaexpresso.com/2020/04/21/aria-pi/)#### (2). Configure Caddyfile:`sudo vim /etc/caddy/Caddyfile`
gogs.yourdomain: { tls address@mail.com proxy / 127.0.0.1:8888 proxy /captcha 127.0.0.1:8888 } ``` - proxy / 127.0.0.1:8888 means forwarding traffic accessing gogs.yourdomain:443 to port 8888 of this machine- address@mail.com represents the user's email address

(3). Restart Caddy:sudo systemctl restart caddy

7. Configuration of Gogs#### (1). AccessIPv4:13000of Raspberry Pi in the browser to set up#### (2). Enteryourdomainin Domain#### (3).EXTERNAL_URLis set tohttps://gogs.yourdomain:443/#### (4). After completing the installation, jump back to Section 3.3 and turn on Cloudflare’s PrivateDNS.

limitation- Gogs installed in this way can only perform git operations through https or http protocol.- SSH operations can be achieved by performing FRP penetration on the SSH port, but PrivateDNS cannot support SSH, so PrivateDNS needs to be turned off.

REF[1]. https://blog.ximcloud.cn/1199/%E6%A0%91%E8%8E%93%E6%B4%BE4b-ubuntu19-10-%E5%AE%89%E8%A3%85docker-gogs.html

[2]. https://li-aaron.github.io/2019/07/nas-frp-caddy-cloudfare/

[3]. https://asdasd.page/2019/04/14/Local-Service-Tunneling-with-FRP-and-Caddy/

[4]. https://github.com/fatedier/frp

[5]. Install-FRP [6]. gogs-configuration details [7]. Reverse-Proxy-with-Caddy-on-RHEL