.gitlab-ci.yml 5.88 KiB
Newer Older
# .gitlab-ci.yml
#
# pipelines can be triggered manually in the web
# setting POLKADOT_BRANCH to v0.2 will result in a poc2 build
# setting DEPLOY_TAG will only deploy the tagged image


gabriel klawitter's avatar
gabriel klawitter committed
stages:
gabriel klawitter's avatar
gabriel klawitter committed
  - test
  - build

# default release in rust:nightly image is stable
gabriel klawitter's avatar
gabriel klawitter committed
image:                             parity/rust:nightly

variables:
  CI_SERVER_NAME:                  "GitLab CI"
  CARGO_HOME:                      "${CI_PROJECT_DIR}/.cargo"
  SUBSTRATE_REPO:                  "https://github.com/paritytech/substrate.git"

gabriel klawitter's avatar
gabriel klawitter committed

.collect_artifacts:                &collect_artifacts
  artifacts:
    name:                          "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    when:                          on_success
    expire_in:                     7 days
    paths:
.kubernetes_build:                 &kubernetes_build
  tags:
    - kubernetes-parity-build
  environment:
    name: gke-build




# disabled as there are bugs
# before_script:
#   - ./scripts/build.sh
#### stage:                        merge-test

check:merge:conflict:
  stage:                           merge-test
  image:                           parity/tools:latest
  cache:                           {}
  <<:                              *kubernetes_build
  only:
    - /^[0-9]+$/
  variables:
    GITHUB_API:                    "https://api.github.com"
    GITLAB_API:                    "https://gitlab.parity.io/api/v4"
    GITHUB_API_PROJECT:            "parity%2Finfrastructure%2Fgithub-api"
  script:
    - ./scripts/gitlab/check_merge_conflict.sh



# test will be run for ci on the current repo
# for version v0.2 branch tests are located in substrate repository and 
# therefore not generically testable
test:rust:release:
gabriel klawitter's avatar
gabriel klawitter committed
  stage:                           test
  cache:
    key:                           "${CI_JOB_NAME}-test"
    paths:
      - ${CARGO_HOME}
      - ./target
gabriel klawitter's avatar
gabriel klawitter committed
  only:
    - triggers
    - tags
    - master
    - schedules
    - web
    - /^[0-9]+$/
  except:
    variables:
      - $POLKADOT_BRANCH == "v0.2"
      - $DEPLOY_TAG
gabriel klawitter's avatar
gabriel klawitter committed
  tags:
    - rust
  script:
    - time cargo test --all --release --verbose
gabriel klawitter's avatar
gabriel klawitter committed
  stage:                           build
  cache:
    key:                           "${CI_JOB_NAME}-build"
    paths:
      - ${CARGO_HOME}
      - ./target
  <<:                              *collect_artifacts
  only:
    - master
    - tags
    - web
  except:
    variables:
      - $DEPLOY_TAG
  tags:
    - rust
gabriel klawitter's avatar
gabriel klawitter committed
  script:
    - >
      set -x;
      if [ "${POLKADOT_BRANCH}" = "v0.2" ]; then
        if [ -z "${TAG}" ]; then
          time cargo install --verbose --root ./target/release/ --git "${SUBSTRATE_REPO}" --branch "${POLKADOT_BRANCH}" polkadot;
        else
          time cargo install --verbose --root ./target/release/ --git "${SUBSTRATE_REPO}" --tag "${TAG}" polkadot;
        fi;
        mv ./target/release/bin/polkadot ./target/release/polkadot;
        rm -d ./target/release/bin;
      else
        time cargo build --release --verbose;
      fi;
      set +x
    - ./target/release/polkadot --version



dockerize:release:
  stage:                           publish
  dependencies:
    - build:rust:linux:release
  cache: {}
  only:
    - master
    - tags
    - web
  except:
    variables:
      - $DEPLOY_TAG
  tags:
    - shell
  variables:
    DOCKERFILE: scripts/docker/Dockerfile
    CONTAINER_IMAGE: parity/polkadot
  before_script:
    - test "$Docker_Hub_User_Parity" -a "$Docker_Hub_Pass_Parity"
        || ( echo "no docker credentials provided"; exit 1 )
    - docker login -u "$Docker_Hub_User_Parity" -p "$Docker_Hub_Pass_Parity"
    - docker info
    - VERSION="$(./target/release/polkadot --version | sed -n -r 's/^polkadot ([0-9.]+-[0-9a-f]+)-.*$/\1/p')"
    - export VERSION
    - echo "Polkadot version = ${VERSION}"
  script:
    - test -z "${VERSION}" && exit 1
    - docker build --tag $CONTAINER_IMAGE:$VERSION --tag $CONTAINER_IMAGE:latest -f $DOCKERFILE ./target/release/
    - docker push $CONTAINER_IMAGE:$VERSION
    - docker push $CONTAINER_IMAGE:latest
    - rm -f ./target/release/polkadot
    - echo "${VERSION}" > ./target/release/VERSION
  after_script:
    - docker logout
  # use artifacts here to transport the version to the next stage
gabriel klawitter's avatar
gabriel klawitter committed
  <<:                              *collect_artifacts
  image:                           dtzar/helm-kubectl:$HELM_VERSION
gabriel klawitter's avatar
gabriel klawitter committed
  only:
    - master
    - tags
gabriel klawitter's avatar
gabriel klawitter committed
  tags:
    # this is the runner that is used to deploy it
    - kubernetes-parity-build
  before_script:
    - test -z "${DEPLOY_TAG}" && 
      test -f ./target/release/VERSION && 
      DEPLOY_TAG="$(cat ./target/release/VERSION)"
    - test "${DEPLOY_TAG}" || ( echo "Neither DEPLOY_TAG nor VERSION information available"; exit 1 )
  script:
    - echo "Polkadot version = ${DEPLOY_TAG}"
    # or use helm to render the template
    - helm template 
      --values ./scripts/kubernetes/values.yaml 
      --set image.tag=${DEPLOY_TAG}
      ./scripts/kubernetes | kubectl apply -f - --dry-run=true
    - echo "# polkadot namespace"
    - kubectl -n polkadot get all
    - echo "# polkadot's nodes' external ip addresses:"
    - kubectl get nodes -l node=polkadot
      -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{range @.status.addresses[?(@.type=="ExternalIP")]}{.address}{"\n"}{end}'
    - echo "# polkadots' nodes"
    - kubectl -n polkadot get pods 
      -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}'



# have environment:url eventually point to the logs

deploy:ew3:
  <<:                              *deploy
  environment:
    name: parity-prod-ew3
    name: parity-prod-ue1