Commit e6ee2b61 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: added gitlab-cp based impl (disabled by default)

parent 1ea65875
Loading
Loading
Loading
Loading
Loading
+64 −2
Original line number Diff line number Diff line
@@ -7,12 +7,16 @@ include:
variables:
  BASH_SHELLCHECK_FILES: "*.sh"
  GITLAB_SYNC_IMAGE: "registry.hub.docker.com/library/alpine:latest"
  # variabilized gitlab-cp image
  GITLABCP_IMAGE: registry.gitlab.com/to-be-continuous/tools/gitlab-cp:latest
  # variabilized sync tool to use (either 'legacy' or 'gitlab-cp')
  SYNC_TOOL: legacy

stages:
  - build
  - test

sync-tbc:
sync-tbc-legacy:
  image:
    name: "${GITLAB_SYNC_IMAGE}"
    entrypoint: [""]
@@ -79,12 +83,15 @@ sync-tbc:
    # disable on gitlab.com
    - if: '$CI_SERVER_HOST == "gitlab.com"'
      when: never
    # disable if $SYNC_TOOL != 'legacy'
    - if: '$SYNC_TOOL != "legacy"'
      when: never
    # allow manual source
    - if: '$CI_PIPELINE_SOURCE == "web"'
    # allow scheduled source
    - if: '$CI_PIPELINE_SOURCE == "schedule"'

sync-tbc-dryrun:
sync-tbc-legacy-dryrun:
  extends: sync-tbc
  script:
    # unset dest GitLab (dryrun)
@@ -92,3 +99,58 @@ sync-tbc-dryrun:
  rules:
    # run only on gitlab.com (to test at least the script correctly crawls tbc projects)
    - if: '$CI_SERVER_HOST == "gitlab.com"'

sync-tbc:
  image:
    name: "$GITLABCP_IMAGE"
    entrypoint: [""]
  stage: build
  variables:
    SRC_GITLAB_API: https://gitlab.com/api/v4
    SRC_SYNC_PATH: to-be-continuous
    DEST_GITLAB_API: $CI_API_V4_URL
    EXCLUDE: samples,custom
  before_script:
    - |
      function install_ca_certs() {
        certs=$1
        if [[ -z "$certs" ]]
        then
          return
        fi
        if echo "$certs" >> /etc/ssl/certs/ca-certificates.crt
        then
          export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
          echo -e "CA certificates imported in \\e[33;1m/etc/ssl/certs/ca-certificates.crt\\e[0m"
        elif echo "$certs" >> /etc/ssl/cert.pem
        then
          export REQUESTS_CA_BUNDLE=/etc/ssl/cert.pem
          echo -e "CA certificates imported in \\e[33;1m/etc/ssl/cert.pem\\e[0m"
        fi
      }
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    # smart variables
    # GitLab source API url defaults to gitlab.com
    - export SRC_GITLAB_API=${SRC_GITLAB_API:-https://gitlab.com/api/v4}
    # GitLab destination API url defaults to $CI_API_V4_URL
    - export DEST_GITLAB_API=${DEST_GITLAB_API:-$CI_API_V4_URL}
    # GitLab destination token defaults to $GITLAB_TOKEN
    - export DEST_TOKEN=${DEST_TOKEN:-$GITLAB_TOKEN}
    # root group path to synchronize
    - export SRC_SYNC_PATH=${SRC_SYNC_PATH:-to-be-continuous}
    - export GUESSED_TBC_NAMESPACE=${CI_PROJECT_NAMESPACE%/*}
    - export DEST_SYNC_PATH=${DEST_SYNC_PATH:-${GUESSED_TBC_NAMESPACE:-to-be-continuous}}
    - export MAX_VISIBILITY=${MAX_VISIBILITY:-${CI_PROJECT_VISIBILITY:-public}}
  script:
    - gitlab-cp
  rules:
    # disable on gitlab.com
    - if: '$CI_SERVER_HOST == "gitlab.com"'
      when: never
    # disable if $SYNC_TOOL != 'gitlab-cp'
    - if: '$SYNC_TOOL != "gitlab-cp"'
      when: never
    # allow manual source
    - if: '$CI_PIPELINE_SOURCE == "web"'
    # allow scheduled source
    - if: '$CI_PIPELINE_SOURCE == "schedule"'