Blog Home
Updated: 2024 Aug 03

how to migrate from gitlab to gitea

create docker-compose.yml file

version: '3.1'

services:
  postgres:
    image: postgres:latest
    container_name: db
    environment:
      POSTGRES_DB: gitea
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: gitea
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    restart: always
    networks:
      - giteanet

  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - DB_TYPE=postgres
      - DB_HOST=db:5432
      - DB_NAME=gitea
      - DB_USER=gitea
      - DB_PASSWD=gitea
    restart: always
    networks:
      - giteanet
    volumes:
      - ./gitea-data:/data
    depends_on:
      - postgres

  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - ./ssl:/etc/nginx/ssl
    networks:
      - giteanet
    depends_on:
      - gitea

networks:
  giteanet:

create nginx conf file

server {
    listen 80;
    server_name your-domain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name your-domain.com;

    ssl_certificate /etc/nginx/ssl/your_domain.crt;
    ssl_certificate_key /etc/nginx/ssl/your_domain.key;

    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;

    location / {
        proxy_pass http://gitea:3000;
        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;
    }
}

include the migration configuration in app.ini

[migrations]
SKIP_TLS_VERIFY     = true
ALLOW_LOCALNETWORKS = true
ALLOWED_DOMAINS     = your domain

adjust the timeout.

[git.timeout]
DEFAULT = 360000
MIGRATE = 600000
MIRROR = 3000000
CLONE = 3000000
PULL = 3000000
GC = 6000000

ssh container passthrough

[server]
...
SSH_PORT = 2222
...

gitlab to gitea

gitea backup

#!/bin/bash

# This script creates a .zip backup of gitea running inside docker and copies the backup file to the current working directory

echo "Creating gitea backup inside docker containter ..."
docker exec -u git -it -w /tmp $(docker ps -qf "name=gitea") bash -c '/app/gitea/gitea dump -c /data/gitea/conf/app.ini --file /tmp/gitea-dump.zip'

echo "Copying backup file from the container to the host machine ..."
docker cp $(docker ps -qf "name=gitea"):/tmp/gitea-dump.zip /tmp

echo "Removing backup file in container ..."
docker exec -u git -it -w /tmp $(docker ps -qf "name=gitea") bash -c 'rm /tmp/gitea-dump.zip'

echo "Renaming backup file ..."
BACKUPFILE=gitea-dump-$(date +"%Y%m%d%H%M").zip
mv /tmp/gitea-dump.zip $BACKUPFILE

echo "Backup file is available: "$BACKUPFILE

echo "Done."

gitea restore


other

docker exec -it gitea cat /data/gitea/conf/app.ini
docker exec -it gitea vi /data/gitea/conf/app.ini
docker exec -it gitea mv data/* /data/gitea
docker exec -it gitea mv repos/* /data/git/gitea-repositories/
docker exec -it gitea chown -R git:git /data
docker exec -it gitea /usr/local/bin/gitea -c '/data/gitea/conf/app.ini' admin regenerate hooks

Comments:

Email questions, comments, and corrections to hi@smartisan.dev.

Submissions may appear publicly on this website, unless requested otherwise in your email.