forked from netptop/siteproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
88 lines (82 loc) · 3.01 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# https://docs.gitlab.com/ee/ci/yaml/
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
# https://docs.gitlab.com/ee/ci/migration/github_actions.html
# https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Jobs
stages:
- github-sync
- gitlab-build
- gitlab-deploy
services:
- name: docker:dind
#command: ["--registry-mirror=https://dhcr-cf.oni.li"]
variables:
DOCKER_IMAGE_NAME: $DOCKER_USER/$CI_PROJECT_NAME
PUB_DOCKER_IMAGE_NAME: $PUB_DOCKER_URL/$CI_PROJECT_NAME
PRI_DOCKER_USER: "nili"
PRI_DOCKER_IMAGE_NAME: $PRI_DOCKER_URL/$CI_PROJECT_NAME
同步至 GitHub:
stage: github-sync
tags:
- oracle
image: alpine
allow_failure: true
before_script:
#- sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
#- TIME=$(TZ='UTC-8' date +'%Y%m%d-%H-%M-%S')
- apk add git rsync
- git config --global user.email $GIT_USER_EMAIL
- git config --global user.name $GIT_USER_NAME
- git clone https://$GIT_USER_NAME:[email protected]/$GIT_USER_NAME/$CI_PROJECT_NAME.git ../tmp
script:
- cd ../tmp
- find . -mindepth 1 -path './.git' -prune -o -exec rm -rf {} +
- cd ../$CI_PROJECT_NAME
- rsync -av --include='.*' --exclude='.git/*' . ../tmp
- cd ../tmp
- git add -A
- git commit -sm "$CI_COMMIT_MESSAGE"
#- git commit -sm "Gitlab CI Auto Update $TIME"
- git push
rules:
- if: $CI_COMMIT_BRANCH
Gitlab Runner 构建 Docker 镜像:
stage: gitlab-build
tags:
- oracle
#image: docker:dind
before_script:
- docker run --privileged --rm tonistiigi/binfmt --install all
- docker buildx create --use --name mybuilder
#- docker login -u "$PRI_DOCKER_USER" -p "$DOCKER_PASSWORD" $PRI_DOCKER_URL
#- TIME=$(TZ='UTC-8' date +'%Y%m%d-%H-%M-%S')
script:
- docker buildx build --file Dockerfile --progress=plain --tag "$PRI_DOCKER_IMAGE_NAME:latest" --platform linux/amd64,linux/arm64 --push .
#- docker buildx build --file Dockerfile --progress=plain --tag "$PRI_DOCKER_IMAGE_NAME:latest" --tag "$PRI_DOCKER_IMAGE_NAME:$TIME" --platform linux/amd64,linux/arm64 --push .
#linux/amd64,linux/arm64,linux/386,linux/arm/v7
rules:
- if: $CI_COMMIT_BRANCH
exists:
- .gitigno
Gitlab Runner 推送部署:
stage: gitlab-deploy
tags:
- oracle
image: alpine
before_script:
- apk add rsync openssh-client
- echo "$SSH_KEY" > key
- chmod 600 key
- ssh-keygen -p -f key -N '' -P "$SSH_KEY_PASSWD"
script:
#- export FILE=nginx/conf.d/stream/stream.conf
#- export TARGETDIR=/root/docker/public/openresty/nginx/conf.d/stream/
- export COMMAND="./sh/dc.sh"
#- chmod +x $FILE
- ssh -o StrictHostKeyChecking=no -p 2200 -i key -4 [email protected] $COMMAND
- ssh -o StrictHostKeyChecking=no -p 2200 -i key -4 [email protected] $COMMAND
- ssh -o StrictHostKeyChecking=no -p 2200 -i key -4 [email protected] $COMMAND
- rm key
rules:
- if: $CI_COMMIT_BRANCH
exists:
- .gitigno