git server setup

1: Story background:

In project development, code management usually includes SVN and git, which have their own advantages. Here we explain the construction and use of GIT

2: Precautions:

Because the source code construction is too cumbersome, here we introduce the whole environment with docker. It is unclear what docker is used. Please follow the steps strictly

Environment introduction:

root@server:~/git# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.10
Release:        20.10
Codename:       groovy

3: docker environment construction

3.1 installation of docker

3.1.1 preparation for docker installation

If you have installed docker in the past, delete it first:

sudo apt-get remove docker docker-engine docker.io

Install dependencies first:

sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

According to your distribution, the following contents are different. The distribution you use, I'm Ubuntu

Trust Docker's GPG public key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

For computers with amd64 architecture, add a software warehouse:

sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

3.1.2 start installation

sudo apt-get update
sudo apt-get install docker-ce

3.2 installation of docker compose

sudo apt-get install docker-compose

3.3 change docker to domestic source

Due to the moving speed of downloading image in China, it is modified as domestic accelerated image source here. Please ignore this step if you can access the Internet scientifically

Modify dockers configuration file
Execute the command sudo VIM / etc / docker / daemon The JSON configuration is modified as follows

{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn"
  ]
}

3.4 restart docker application configuration

sudo systemctl daemon-reload
sudo systemctl restart docker

4: git environment construction

Official document description link.

4.1 preparation

Create a folder for storing data

mkdir git
cd git

Configure docker compose YML file
Execute the command sudo VIM docker compose The YML configuration is modified as follows

version: "3"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.13.2
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - DB_TYPE=mysql
      - DB_HOST=db:3306
      - DB_NAME=gitea
      - DB_USER=gitea
      - DB_PASSWD=gitea
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
       - "3000:3000"
       - "222:22"
    depends_on:
       - db

  db:
    image: mysql:5.7
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=gitea
      - MYSQL_USER=gitea
      - MYSQL_PASSWORD=gitea
      - MYSQL_DATABASE=gitea
    networks:
      - gitea
    volumes:
      - ./mysql:/var/lib/mysql

4.2 downloading image files

Note that downloading in advance here is to prevent the failure of downloading the image when starting the project. My network environment is not good, so download in advance to prevent error reporting during operation

docker pull mysql:5.7
docker pull gitea/gitea:1.13.2

4.3 operation items

Execute the command sudo docker compose up - D server

root@server:~/git# docker-compose up -d server
Creating git_db_1 ... done
Creating gitea    ... done

View run results
Execute the command sudo docker compose PS

root@server:~/git# docker-compose ps
  Name                Command               State                      Ports
-----------------------------------------------------------------------------------------------
git_db_1   docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp
gitea      /usr/bin/entrypoint /bin/s ...   Up      0.0.0.0:222->22/tcp, 0.0.0.0:3000->3000/tcp

You can see that both containers are Up

5: Basic configuration of git environment

Browser input server IP:3000 to access Git warehouse


As shown in the figure, you can see that Git has run successfully
Click login in the upper right corner of the page
Get this configuration page


These items need to be changed in the previous configuration

Finally, click Install now
This is what it looks like after a successful installation



Click Manage background to perform a series of operations

6: git created our first project and tested it

Tags: Docker Ubuntu git server

Posted by joshmaker on Sat, 16 Apr 2022 03:25:42 +0930