1
0

.gitlab-ci.yml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # https://docs.gitlab.com/ee/ci/yaml/
  2. # https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
  3. # https://docs.gitlab.com/ee/ci/migration/github_actions.html
  4. # https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Jobs
  5. stages:
  6. - github-sync
  7. - gitlab-build
  8. - gitlab-deploy
  9. services:
  10. - name: docker:dind
  11. #command: ["--registry-mirror=https://dhcr-cf.oni.li"]
  12. variables:
  13. DOCKER_IMAGE_NAME: $DOCKER_USER/$CI_PROJECT_NAME
  14. PUB_DOCKER_IMAGE_NAME: $PUB_DOCKER_URL/$CI_PROJECT_NAME
  15. PRI_DOCKER_USER: "nili"
  16. PRI_DOCKER_IMAGE_NAME: $PRI_DOCKER_URL/$CI_PROJECT_NAME
  17. 同步至 GitHub:
  18. stage: github-sync
  19. tags:
  20. - oracle
  21. image: alpine
  22. before_script:
  23. #- sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
  24. - TIME=$(TZ='UTC-8' date +'%Y%m%d-%H-%M-%S')
  25. - apk add git rsync
  26. - git config --global user.email $GIT_USER_EMAIL
  27. - git config --global user.name $GIT_USER_NAME
  28. - git clone https://$GIT_USER_NAME:$GITHUB_ACCESS_TOKEN@github.com/$GIT_USER_NAME/$CI_PROJECT_NAME.git ../tmp
  29. script:
  30. #- rm -rf .git
  31. - cd ../tmp
  32. - find . -mindepth 1 -path './.git' -prune -o -exec rm -rf {} +
  33. - cd ../$CI_PROJECT_NAME
  34. - rsync -av --include='.*' --exclude='.git/*' --exclude='.gitlab-ci.yml' . ../tmp
  35. - cd ../tmp
  36. - git add -A
  37. - git commit -sm "Gitlab CI Auto Update $TIME"
  38. - git push
  39. rules:
  40. - if: $CI_COMMIT_BRANCH
  41. exists:
  42. - .gitignore
  43. Gitlab Runner 构建 Docker 镜像:
  44. stage: gitlab-build
  45. tags:
  46. - oracle
  47. #image: docker:dind
  48. before_script:
  49. - docker run --privileged --rm tonistiigi/binfmt --install all
  50. - docker buildx create --use --name mybuilder
  51. #- docker login -u "$PRI_DOCKER_USER" -p "$DOCKER_PASSWORD" $PRI_DOCKER_URL
  52. #- TIME=$(TZ='UTC-8' date +'%Y%m%d-%H-%M-%S')
  53. script:
  54. - docker buildx build --file Dockerfile --progress=plain --tag "$PUB_DOCKER_IMAGE_NAME:latest" --platform linux/amd64,linux/arm64 --push .
  55. #- 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 .
  56. #linux/amd64,linux/arm64,linux/386,linux/arm/v7
  57. rules:
  58. - if: $CI_COMMIT_BRANCH
  59. exists:
  60. - .dockerignore
  61. Gitlab Runner 部署 Docker 镜像:
  62. stage: gitlab-deploy
  63. tags:
  64. - oracle
  65. #image: docker:dind
  66. #before_script:
  67. # - sleep 60
  68. script:
  69. - echo "$SSH_KEY" > key
  70. - chmod 600 key
  71. - ssh-keygen -p -f key -N '' -P "$SSH_KEY_PASSWD"
  72. - rm key
  73. rules:
  74. - if: $CI_PIPELINE_SOURCE == "push"
  75. exists:
  76. - .dockerignore
粤ICP备19079148号