|
|
@@ -4,37 +4,79 @@
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Jobs
|
|
|
|
|
|
stages:
|
|
|
- - build
|
|
|
+ - github-sync
|
|
|
+ - gitlab-build
|
|
|
+ - gitlab-deploy
|
|
|
+
|
|
|
+services:
|
|
|
+ - name: docker:dind
|
|
|
+ #command: ["--registry-mirror=https://dhcr-cf.oni.li"]
|
|
|
|
|
|
variables:
|
|
|
- PUB_DOCKER_USER: "niliaerith"
|
|
|
- PUB_DOCKER_IMAGE_NAME: $PUB_DOCKER_USER/$CI_PROJECT_NAME
|
|
|
+ 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
|
|
|
|
|
|
-构建Docker镜像:
|
|
|
- stage: build
|
|
|
- # Use the official docker image.
|
|
|
+同步至 GitHub:
|
|
|
+ stage: github-sync
|
|
|
tags:
|
|
|
- - gxy
|
|
|
- image: docker:dind
|
|
|
- #image: docker:latest
|
|
|
- #image: docker:cli
|
|
|
- #services:
|
|
|
- # - name: docker:dind
|
|
|
- # command: ["--registry-mirror=https://dhcr-cf.niliovo.top"]
|
|
|
+ - oracle
|
|
|
+ image: alpine
|
|
|
+ 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:$GITHUB_ACCESS_TOKEN@github.com/$GIT_USER_NAME/$CI_PROJECT_NAME.git ../tmp
|
|
|
+ script:
|
|
|
+ #- rm -rf .git
|
|
|
+ - 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 "Gitlab CI Auto Update $TIME"
|
|
|
+ - git push
|
|
|
+ rules:
|
|
|
+ - if: $CI_COMMIT_BRANCH
|
|
|
+ exists:
|
|
|
+ - .gitignore
|
|
|
+
|
|
|
+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')
|
|
|
- # All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug)
|
|
|
- # Default branch is also tagged with `latest`
|
|
|
+ #- 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" --tag "$PRI_DOCKER_IMAGE_NAME:$TIME" --platform linux/amd64,linux/arm64 --push .
|
|
|
+ - docker buildx build --file Dockerfile --progress=plain --tag "$PUB_DOCKER_IMAGE_NAME:latest" --platform linux/amd64,linux/arm64 --push .
|
|
|
+ #- docker buildx build --file Dockerfile --progress=plain --tag "$PUB_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
|
|
|
- # Run this job in a branch where a Dockerfile exists
|
|
|
rules:
|
|
|
- if: $CI_COMMIT_BRANCH
|
|
|
exists:
|
|
|
- - Dockerfile
|
|
|
+ - .dockerignore
|
|
|
+
|
|
|
+Gitlab Runner 部署 Docker 镜像:
|
|
|
+ stage: gitlab-deploy
|
|
|
+ tags:
|
|
|
+ - oracle
|
|
|
+ #image: docker:dind
|
|
|
+ #before_script:
|
|
|
+ # - sleep 60
|
|
|
+ script:
|
|
|
+ - echo "$SSH_KEY" > key
|
|
|
+ - chmod 600 key
|
|
|
+ - ssh-keygen -p -f key -N '' -P "$SSH_KEY_PASSWD"
|
|
|
+ - rm key
|
|
|
+ rules:
|
|
|
+ - if: $CI_PIPELINE_SOURCE == "push"
|
|
|
+ exists:
|
|
|
+ - .dockerignore
|