# 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 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/*' --exclude='.gitlab-ci.yml' . ../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') script: - 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 rules: - if: $CI_COMMIT_BRANCH exists: - .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