Post

Gitea

Self-hosted Git service with Docker.

Gitea

Introduction

Gitea is a lightweight, self-hosted Git service written in Go. This guide will walk you through setting up Gitea with Docker using docker-compose.

Setting Up Gitea with Docker

Create a Directory

1
mkdir gitea && cd gitea

Create docker-compose.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
version: '3'

services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    restart: unless-stopped
    environment:
      - USER_UID=1000
      - USER_GID=1000
    volumes:
      - ./gitea-data:/data
    ports:
      - "3000:3000"
      - "222:22" # If you expose SSH
    networks:
      - gitea

  gitea-act-runner:
    image: gitea/act_runner:latest
    container_name: gitea-act-runner
    restart: unless-stopped
    depends_on:
      - gitea
    environment:
      - CONFIG_FILE=/config.yaml
      - GITEA_INSTANCE_URL=http://gitea:3000
      - GITEA_RUNNER_REGISTRATION_TOKEN=REGISTRATION_TOKEN
      - GITEA_RUNNER_NAME=runner-1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./gitea-runner-data:/data
      - ./gitea-runner-data/config.yaml:/config.yaml
    networks:
      - gitea
networks:
  gitea:

Start Gitea

1
docker-compose up -d

Installation

After starting the Docker setup, open your browser and visit http://server-ip:3000 to complete the installation via the web UI.

Customization

Customization files should be placed in the gitea/data directory as described in the official documentation.

Modify app.ini:

1
nano ./gitea/data/conf/app.ini

Example:

1
2
[server]
DISABLE_REGISTRATION = true # Disables registration so only admins can create accounts.

Restart Gitea for changes to take effect:

1
docker restart gitea

Setting Up a Runner (Optional)

To enable CI/CD workflows using Gitea Actions, set up a runner:

1
docker run --entrypoint="" --rm -it docker.io/gitea/act_runner:latest act_runner generate-config > gitea-runner-data/config.yaml

Edit config.yaml

1
2
container:
  network: "gitea_gitea"

example of workflow .gitea/workflows/demo.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
name: Deploy Container

on:
  push:
    branches:
      - master

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Build Docker image
      run: |
        docker build -t my-app .

    - name: Deploy Container
      run: |
        docker stop my-app || true
        docker rm my-app || true
        docker run -d --name my-app -p 8080:8080 my-app

Conclusion

You now have a self-hosted Git service running with Gitea, and optional CI/CD support. Happy coding!

This post is licensed under CC BY 4.0 by the author.