文章目录
1.GitLab pipeline部署
服务器使用Gitlab的服务器
GitLab Runner安装
- 下载
# For Debian/Ubuntu/Mint
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
# For RHEL/CentOS/Fedora
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
- 安装
# MacOS
sudo brew install gitlab-ci-multi-runner
# For Debian/Ubuntu/Mint
sudo apt-get install gitlab-ci-multi-runner
# For RHEL/CentOS/Fedora
sudo yum install gitlab-ci-multi-runner
- 查看是否运行正常
sudo gitlab-ci-multi-runner status
gitlab-runner 注册
项目主页 -> Sttings -> CI/CD -> Runners Expand
sudo gitlab-runner register
输入gitlab的服务URL,这个使用的是https://gitlab.com/
输入gitlab-ci的Toekn,获取方式参考上图
关于集成服务中对于这个runner的描述
给这个gitlab-runner输入一个标记,这个tag非常重要,在后续的使用过程中需要使用这个tag来指定gitlab-runner
是否运行在没有tag的build上面。在配置gitlab-ci的时候,会有很多job,每个job可以通过tags属性来选择runner。这里为true表示如果job没有配置tags,也执行
是否锁定runner到当前项目
选择执行器,gitlab-runner实现了很多执行器,可用在不同场景中运行构建,详情可见GitLab Runner Executors,这里选用Shell模式
gitlab-ci
自己写的 gitlab-ci.yml demo
stages:
- test
- confirm-deploy
- prod
test:
stage: test
script:
- echo "this is test"
tags:
- my-tag
confirm-1:
stage: confirm-deploy
script:
- echo "master confirmation of test"
allow_failure: false
only:
- master
tags:
- my-tag
confirm-2:
stage: confirm-deploy
script:
- echo "release confirmation of production"
allow_failure: false
only:
- release
tags:
- my-tag
prod:
stage: prod
script:
- docker-compose up -d
only:
- release
tags:
- my-tag
一般在test 时回会启动该项目
每一次 docker build 时会在 docker registry 仓库中上传
matser 或者 release branch时回从仓库中拉取镜像 并部署在k8s集群
2.单机使用Docker 部署go语言项目
Dockerfile
FROM golang:1.15.6
ENV TZ=Asia/Shanghai
WORKDIR /src
# 复制构建应用程序所需的代码
COPY . .
# 构建应用程序
RUN CGO_ENABLED=0 go build -mod=vendor main.go
EXPOSE 8080
CMD ["./main"]
start.sh
git pull
docker build -t project:latest .
docker rm -f project-pro
docker run -it -p 8080:8080 -d -e BAOGOENV=pro --name project-pro --restart=always project:latest
3.单机使用nohup 部署go语言项目
gox -osarch="linux/amd64"
scp -r project_linux_amd64 root@ip:/home/project
lsof -i:3001
kill -9 pid
nohup ./project_linux_amd64 > /nohup/nohup.`date +%Y%m%d%H%M%S`.log 2>&1 &
https://github.com/mitchellh/gox
4. 阿里云Codeup云效使用flow+k8s部署
https://blog.csdn.net/weixin_43746433/article/details/109585695
5.阿里云容器镜像服务+gitlab部署至k8s
1.建立gitlab 触发器
http://cr-callback.console.aliyun.com/sourceRepo/doGitLabCallBack.json?site=china
secret_toekn 为自己的token