gitlab搭建

发布于:2024-09-18 ⋅ 阅读:(122) ⋅ 点赞:(0)

1、gitlab服务器基础环境搭建

1) ubuntu和cmake安装
       Ubuntu:18.04
       Tensorflow:1.14.0
       Cmake 3.16
说明:cmake要求3.16版本以上,此处以cmake-3.17安装为例
cmake –version(查看当前cmake版本)
sudo apt-get remove cmake              (删除旧的cmake版本)
wget  https://cmake.org/files/v3.17/cmake-3.17.1.tar.gz(下载cmake-3.17压缩包)
tar -xzvf cmake-3.17.1.tar.gz(解压cmake-3.17压缩包)
cd cmake-3.17.1
sudo apt-get install build-essential(安装cmake-3.17)
./bootstrap
若运行./bootstrap报错,请按照 错误1 的方法解决。然后再继续下面的安装步骤。
make
sudo make install
若make和make install错误,请按照 错误2 的方法解决。

cmake –version确认是否安装成功

2)    protobuf安装问题
https://blog.csdn.net/FK2016/article/details/83375048?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.essearch_pc_relevant&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.essearch_pc_relevant
版本3.7.1
sudo apt-get remove libprotobuf-dev
which protoc
rm /usr/bin/protoc
sudo apt-get install autoconf automake libtool curl make g++ unzip
git clone –b v3.7.1 https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
cd protobuf
./autogen.sh
./configure
make -j4
make check | sudo make install
sudo ldconfig
protoc --version

3)gtest安装
git clone https://github.com/google/googletest.git
cd gtest
mkdir build
cmake ..
make –j4
sudo make install

4)    jsoncpp安装问题
 版本1.9.3
mkdir build; cd build; cmake .. ;make -j4; sudo make install

5)依赖项

   sudo apt install clang
   sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev             build-essential libedit-dev libxml2-dev python3-pip
    sudo apt install graphviz
    pip3 install --user numpy decorator attrs
    pip3 install --user tornado psutil xgboost
    sudo apt install protobuf-compiler
    sudo apt install libprotobuf-dev
    sudo apt-get install libboost-all-dev
    pip3 install typed_ast scipy tensorflow
    pip3 install onnx==1.9.0 
    pip3 install pytorch==1.10.0
    pip3 install pytest==6.2.5 
    pip3 install pytest-forked==1.4.0
    pip3 install pytest-parallel==0.1.1
    pip3 install pytest-xdist==2.5.0  
    pip3 install onnxoptimize==x.x.x ( if use onnxoptimize )

6)环境变量设置

        source ~/.bashrc

2、gitlab服务器部署、更新和备份恢复:

1)首先安装 docker:https://docs.docker.com/install/
2)再安装 docker-compose:https://docs.docker.com/compose/install/
3)建立一个目录,方便存放数据、配置等文件,例如在 home 目录下建立 gitlab 目录。
之后在 gitlab 目录中创建文件 docker-compose.yml ,简单的配置如下:
web :
image : 'gitlab/gitlab-ee:latest'
restart : always
hostname : 'gitlab.example.com'
environment :
GITLAB_OMNIBUS_CONFIG : |
external_url 'http://192.168.4.16' 
#由于在内网环境下不需要使用 https ,注意将 external_url 改为 http 协议,否则无法通过 http
访问
# Add any other gitlab.rb configuration here, each on its own line
ports :
- '80:80'
- '8090:443'
- '22:22
# 冒号表示宿主机和创建的虚拟机的映射关系,冒号前为宿主机,如果要使用宿主机的 22 号端口,需要事先更改服务器 ssh 服务的端口号。
volumes :
- '/home/xxx/gitlab/config:/etc/gitlab'
- '/home/xxx/gitlab/logs:/var/log/gitlab'
- '/home/xxx/gitlab/data:/var/opt/gitlab'
之后运行 docker-compose up -d 即可下载镜像运行并部署 gitlab 服务器。
注意 :创建之后使用 root 账户登录,初始密码位于 config/initial_root_password ,需要 sudo
限查看。
4)更新
docker-compose pull
docker-compose up -d
5)备份
docker exec -t <container name> gitlab-backup create新产生的备份会位于 data/backups 目录内,命名例如 1629806217_2021_08_24_14.2.1-
ee_gitlab_backup.tar 。注意可能需要 sudo 权限才能进入。
5)恢复
首先创建一个新的容器并如上部署完毕。注意部署之前目标目录需要是空的。
之后将之前的备份文件赋予权限:
sudo chmod 777 ***.tar
并将其复制到新容器的 data/backups 目录内。
# 进入GITLAB
docker exec -it <container name> /bin/bash
# 停止数据服务
gitlab-ctl stop puma
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 检查状态
gitlab-ctl status
# 数据恢复,注意不需要最后的 gitlab_backup 后缀
gitlab-backup restore BACKUP=1629806217_2021_08_24_14.2.1-ee
# 重启并验证
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true
邮箱功能
参考 https://www.cxyzjd.com/article/gnail_oug/96701397 即可。
由于是在 docker 已经配置好的情况下进行操作,在 docker - compose.yml 中添加项似乎不起作用(不
过合理推测在新创建实例前加上是可以生效的)。最终更改了 config 目录中的 gitlab.rb 配置成功。

3、gitlab配置gitlab-runner,实现CI/CD流程:

1)下载gitlab-runner

Download and install binary
# Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

2)安装gitlab-runner

# Give it permissions to execute
sudo chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab CI user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

# Install and run as service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start

3)注册runner sudo gitlab-runner register --url http://192.168.10.99/ --registration-token avMBwSLHcaYAQzBHpMcj

然后一直回车,直到提示Registering runner... succeeded,后输入shell。

4)在代码工程目录下添加.gitlab-ci.yml,例子:

stages: # List of stages for jobs, and their order of execution

  - build

  - test

  - deploy

build-job: # This job runs in the build stage, which runs first.

  stage: build

  script:

    - echo "Compiling the code..."

    - echo "Compile complete."

    - ./build.sh #工程编译脚本

    - ./run.sh #工程执行脚本

unit-test-job: # This job runs in the test stage.

  stage: test # It only starts when the job in the build stage completes successfully.

  script:

    - echo "Running unit tests... This will take about 60 seconds."

    - sleep 1

    - echo "Code coverage is 90%"

lint-test-job: # This job also runs in the test stage.

  stage: test # It can run at the same time as unit-test-job (in parallel).

  script:

    - echo "Linting code... This will take about 10 seconds."

    - sleep 1

    - echo "No lint issues found."

deploy-job: # This job runs in the deploy stage.

  stage: deploy # It only runs when *both* jobs in the test stage complete successfully.

  script:

    - rm -rf dump_sv

    - echo "Deploying application..."

    - echo "Application successfully deployed."

5)如果提示

按照下面流程将gitlab-runner修改为可以执行没有标签的作用。


网站公告

今日签到

点亮在社区的每一天
去签到