Setting up a Gitea server

From bibbleWiki
Revision as of 00:01, 12 April 2025 by Iwiseman (talk | contribs) (Using the Action)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Set up a MYSQL Database

Make sure you are listening on 0.0.0.0 and not localhost.

CREATE DATABASE gitea_db;
CREATE USER 'gitea_admin'@'you network IP' IDENTIFIED BY 'not saying';
GRANT ALL PRIVILEGES ON gitea_db.* TO 'gitea_admin'@'you network IP' WITH GRANT OPTION;

Gitea Setup

# Get Software
 wget -O gitea https://dl.gitea.com/gitea/1.23.7/gitea-1.23.7-linux-amd64

# Add Git User
sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git

# Link to RAID
sudo ln -s  /var/lib/gitea /mnt/RAID/gitea

#Make Directory structure
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/

sudo mkdir /etc/gitea
sudo chown  root:git /etc/gitea
sudo chmod  770 /etc/gitea

Gitea Service

Create a service to run in /etc/systemd/system/gitea.service

[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target

Gitea initial setup

I needed this because 3000 is in use. You put this file in /etc/gitea/app.ini. Make sure it is writable or the install will fail.

[server]
PROTOCOL     = http
DOMAIN       = localhost
ROOT_URL     = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
HTTP_ADDR    = 0.0.0.0
HTTP_PORT    = 1701
DISABLE_SSH  = false

Nginx Setup

Need to add a reverse proxy

server{
   server_name git.example.local;

   listen       443 ssl;

   access_log /var/log/nginx/git.example.local.log;
   error_log  /var/log/nginx/git.example.local.log error;

   disable_symlinks off;

   ssl_certificate     /etc/ssl/certs/server.crt;
   ssl_certificate_key /etc/ssl/private/server.key;

   client_max_body_size 20m;

   location ~ / {
        client_max_body_size 512M;
        proxy_pass http://localhost:1701;
        proxy_set_header Connection $http_connection;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

 }

Github Actions

So we are now able to run actions with gitea. Better write some stuff up on how we do this with github. Seems there is nothing new and very similar to Azure pipelines

Installing on Gitea

You need to install docker to run you pipleline. I used the page [digitalOcean] for this and downloaded act_runner for gitea from [here]. The only part that was hard was understanding the instructions for getting a token as it directs you to http://192.168.8.8:3000/admin/actions/runners but that is not what you do. You go to -/admin/actions/runners note the hyphen. Once there you create a runner

Workflow

A work flow consists of the following.

  • Events
  • Jobs
  • Runners
  • Steps
  • Actions

Events

This is when to run the workflow. E.g. on push

Jobs

This is the list of jobs to do in a workflow

Runners

This is the environment we will run are steps on. e.g. a docker container

Steps

This is a list of actions to run

Actions

This might be checkout code. Run linter

Example

We need to name our file .github/workflows/my_great_workflow.yaml

name: Super-Linter

on: push

jobs:
  super-lint:
    name: Lint code base
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Run Super-Linter
        uses: github/super-linter@v4
        env:
          DEFAULT_BRANCH: main
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Building an Action

Setup

To build the example action which can be found [here], I needed to install go on the docker image.

FROM ubuntu:latest

ARG GO_VERSION
ENV GO_VERSION=${GO_VERSION}

RUN apt-get update
RUN apt-get install -y wget git gcc

RUN wget -P /tmp "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"

RUN tar -C /usr/local -xzf "/tmp/go${GO_VERSION}.linux-amd64.tar.gz"
RUN rm "/tmp/go${GO_VERSION}.linux-amd64.tar.gz"

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

WORKDIR $GOPATH

You can then build the image with

docker build --build-arg GO_VERSION=<version> -t ubuntu-go .

And you can copy save and restore image to copy it so a different machine with

docker save -o ubuntu-go.tar ubuntu-go
docker load -i ubuntu-go.tar

Now you can make another runner but make sure you add the ubuntu-go tag as when you go to build the action it will be required.

Preparing the Code

You need to either use the existing repository for the example or check it in to your one repository as a public project. It you don't make it public you will need to figure out authentication

Using the Action

Now you can use this and should be enough to get you started. The long thing is the commit sha

name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]

jobs:
  install:
    name: install packages
    runs-on: google-go

    steps:
      - name: Use Go Action  
        uses: https://git.example.com/bibble235/simple-go-action@165dd3709f4e772140a2f3bbc51a4d44c2a3e9ec
        with:
          username: foo
...