docker-composer安装gitlab,gitlab-runner设置CICD,及重置root密码

docker-composer安装gitlab及重置root密码

1、部署

mkdir /data/gitlab
export GITLAB_HOME=/data/gitlab
cd /data/gitlab
touch docker-composer.yaml

docker-composer.yaml

version: '3.6'
services:
  web:
    image: 'gitlab/gitlab-ee:latest'
    #或者使用极狐
    #image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
    container_name: gitlab
    restart: always
    hostname: '域名或ip'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://域名或ip'
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
    ports:
      - '80:80'
      - '18443:443'
      - '2222:22'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    shm_size: '256m'

启动

export GITLAB_HOME=/data/gitlab && docker-composer up -d

重启

export GITLAB_HOME=/data/gitlab && docker-composer down
export GITLAB_HOME=/data/gitlab && docker-composer up -d

查看root密码

docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

2、配置邮箱

grep -vE "^#|^$" gitlab.rb

gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.mxhichina.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "passW0rd"
gitlab_rails['smtp_domain'] = "mxhichina.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false

3、重置root密码

  • docker启动的错误命令
docker exec -it gitlab bash
gitlab-rails console production
  • 报错

  • 正确做法
docker exec -it gitlab bash
gitlab-rails console

  • 进入ruby控制台(密码要至少8位)
irb(main):007:0> u=User.where(id:1).first
=> #

#通过u.password='root@123456'设置密码
irb(main):002:0> u.password='root@123456'
=> "root@12345"

# 通过u.password_confirmation='root@123456' 再次确认密码
irb(main):003:0> u.password_confirmation='root@123456'
=> "root@123456"

#通过 u.save!进行保存(切记切记 后面的 !)
irb(main):004:0> u.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: 00ea0b5a-e0d1-4410-8c39-e35a295ac972) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#>]}
=> true

4、浏览器登录验证

http://域名或ip:1880

root / root@123456

4、gitlab-runner

下载并安装二进制文件

#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

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

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

#Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
#注册runner的命令
sudo gitlab-runner register --url http://10.10.0.12/ --registration-token 1UguT4Qo7CEexgq6SBeu
Runtime platform                                    arch=amd64 os=linux pid=8504 revision=133d7e76 version=15.6.1
WARNING: The 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with a 'deploy' command. For more information, see https://gitlab.com/gitlab-org/gitlab/-/issues/380872
Running in system-mode.

Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://10.10.0.12/]: #默认,回车
Enter the registration token:
[1UguT4Qo7CEexgq6SBeu]: #默认,回车
Enter a description for the runner: #默认,回车
[KD111111000062.ppp-bb.dion.ne.jp]: 12-gitlab-runner #自定义,回车
Enter tags for the runner (comma-separated):
12-gitlab-runner #自定义,回车
Enter optional maintenance note for the runner:
# 回车
Registering runner... succeeded                     runner=1UguT4Qo
Enter an executor: docker, docker-ssh, shell, docker+machine, custom, ssh, virtualbox, docker-ssh+machine, instance, kubernetes, parallels:
shell #自定义
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"

启动

sudo gitlab-runner start 

5、gitlab-runner配置CICD

gitlab在项目的根目录下面创建.gitlab-ci.yml

stages:
- build
- deploy


.build_script: &build_script
  - export RELEASE_NUM="$(date +%Y%m%d)-$(echo $CI_COMMIT_SHA | cut -c1-8)"
  - export NEW_RELEASE_DIR="/tmp/${RELEASE_NUM}"
  - cp -rf "${CI_PROJECT_DIR}" "${NEW_RELEASE_DIR}"


.deploy_script: &deploy_script
  - ls /tmp

production_build:
  stage: build
  script: *build_script
  only:
    - main
  tags:
    - 12-gitlab-runner

production_deploy:
  stage: deploy
  script: *deploy_script
  when: manual #手动触发发布
  only:
    - main
  tags:
    - 12-gitlab-runner

你可能感兴趣的:(docker,composer,gitlab,gitlab-runner)