From c59be5f7461d431638adf61eefb25774a3310857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jev=20Bj=C3=B6rsell?= Date: Thu, 13 Feb 2020 23:10:02 +0000 Subject: [PATCH] * Switch to in-line CI for webide over GitLab's child-pipeline feature. There was too many bugs/weirdness with the child-pipeline. Maybe we use it when it matures. * Flatten the build_and_deploy_docker and build_and_deploy_website into one step. They don't appear to be dependent, and if the upstream "test" jobs ran okay, then we can run these jobs in parallel. * Run the webide unit tests in the `test` stage only if there are changes to the tools/webide directory. * Switch to using the new `rules` ([docs](https://docs.gitlab.com/ee/ci/yaml/#rules))property instead of `only` / `except`. `rules` is now the preferred way of setting job policies. `only`/`except` are [candidates for deprecation](https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic). * Build/push docker images only when CI is running on the canonical `ligolang/ligo` repo. Makes hacking on CI in forked repos easier. * Don't push a `latest` tag for the webide. --- .gitlab-ci.yml | 92 +++++++++++++++++++++++++++++++------- tools/webide/webide-ci.yml | 70 ----------------------------- 2 files changed, 76 insertions(+), 86 deletions(-) delete mode 100644 tools/webide/webide-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d7beb8dc1..b5b1229ad 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,14 +4,16 @@ variables: build_binary_script: "./scripts/distribution/generic/build.sh" package_binary_script: "./scripts/distribution/generic/package.sh" LIGO_REGISTRY_IMAGE_BASE_NAME: "${CI_PROJECT_PATH}/${CI_PROJECT_NAME}" + WEBIDE_IMAGE_NAME: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide" stages: - test - - ide - build_and_package_binaries - build_docker - - build_and_deploy_docker - - build_and_deploy_website + - build_and_deploy + - ide-build + - ide-e2e-test + - ide-deploy # TODO provide sensible CI for master dont-merge-to-master: @@ -32,7 +34,7 @@ dont-merge-to-master: - dist/package/**/* .website_build: &website_build - stage: build_and_deploy_website + stage: build_and_deploy image: node:8 dependencies: - build-and-package-debian-9 @@ -126,17 +128,19 @@ build-current-docker-image: # When a MR/PR is merged to dev # take the previous build and publish it to Docker Hub build-and-publish-latest-docker-image: - stage: build_and_deploy_docker + stage: build_and_deploy <<: *docker dependencies: - build-and-package-debian-10 script: - sh scripts/build_docker_image.sh - sh scripts/test_cli.sh - - docker login -u $LIGO_REGISTRY_USER -p $LIGO_REGISTRY_PASSWORD + - echo ${LIGO_REGISTRY_PASSWORD} | docker login -u ${LIGO_REGISTRY_USER} --password-stdin - docker push ${LIGO_REGISTRY_IMAGE_BUILD:-ligolang/ligo}:next - only: - - dev + rules: + # Only deploy docker when from the dev branch AND on the canonical ligolang/ligo repository + - if: '$CI_COMMIT_REF_NAME == "dev" && $CI_PROJECT_PATH == "ligolang/ligo"' + when: always # It'd be a good idea to generate those jobs dynamically, # based on desired targets @@ -192,16 +196,72 @@ build-and-package-ubuntu-19-04: only: - dev - -trigger-webide: - stage: ide - trigger: - include: tools/webide/webide-ci.yml - - # Pages are deployed from dev, be careful not to override 'next' # in case something gets merged into 'dev' while releasing. pages: <<: *website_build + rules: + - if: '$CI_COMMIT_REF_NAME == "dev" && $CI_PROJECT_PATH == "ligolang/ligo"' + when: always + +# WEBIDE jobs + +run-webide-unit-tests: + stage: test + image: node:12-alpine + script: + - cd tools/webide/packages/server + - npm ci + - npm run test only: - - dev + changes: + - tools/webide/** + +build-publish-ide-image: + stage: build_and_deploy + <<: *docker + script: + - ls -F + - find dist/ + - find dist/package/ -name '*ligo_*deb' + - mv $(realpath dist/package/debian-10/*.deb) tools/webide/ligo_deb10.deb + - cd tools/webide + - echo "${CI_BUILD_TOKEN}" | docker login -u gitlab-ci-token --password-stdin registry.gitlab.com + - > + docker build + -t "${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" + --build-arg GIT_TAG="${CI_COMMIT_SHA}" + --build-arg GIT_COMMIT="${CI_COMMIT_SHORT_SHA}" + . + - docker push "${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: always + - if: '$CI_COMMIT_REF_NAME == "dev"' + when: always + +run-webide-e2e-tests: + stage: ide-e2e-test + <<: *docker + image: tmaier/docker-compose + script: + - cd tools/webide/packages/e2e + - export WEBIDE_IMAGE="${WEBIDE_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" + - docker-compose run e2e + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: always + - if: '$CI_COMMIT_REF_NAME == "dev"' + when: always + +deploy-handoff: + # Handoff deployment duties to private repo + stage: ide-deploy + variables: + IDE_DOCKER_IMAGE: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide" + LIGO_COMMIT_REF_NAME: "${CI_COMMIT_SHORT_SHA}" + trigger: ligolang/ligo-webide-deploy + rules: + - if: '$CI_COMMIT_REF_NAME == "dev"' + when: always + diff --git a/tools/webide/webide-ci.yml b/tools/webide/webide-ci.yml deleted file mode 100644 index 3f7d68731..000000000 --- a/tools/webide/webide-ci.yml +++ /dev/null @@ -1,70 +0,0 @@ -# This Gitlab CI config is triggerd by the main ligo gitlab config file -image: docker -services: - - docker:dind - -variables: - CONTAINER_NAME: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide" - -stages: - - unit-test - - build - - e2e-test - - deploy - -run-webide-unit-tests: - stage: unit-test - image: node:12-alpine - script: - - cd tools/webide/packages/server - - npm ci - - npm run test - -build-docker-image: - stage: build - script: - - cd tools/webide - - apk add curl unzip - # Fetch the builid artifact from the upstream debian10 build job, extract the deb - # package file and name it so that the Dockerfile can pick it up during the - # build process. - - > - curl - --fail - --location - --output artifacts.zip - "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/jobs/artifacts/${CI_COMMIT_REF_NAME}/download?job=build-and-package-debian-10" - - mv $(unzip -j artifacts.zip| sed -n 's/.*\('ligo_'.*\.deb\).*/\1/p') ligo_deb10.deb - - echo "${CI_BUILD_TOKEN}" | docker login -u gitlab-ci-token --password-stdin registry.gitlab.com - # Pull the last build to use as a cache image to shorten build times when - # possible - - docker pull "${CONTAINER_NAME}:latest" || true - - > - docker build - --cache-from "${CONTAINER_NAME}:latest" - -t "${CONTAINER_NAME}:${CI_COMMIT_REF_NAME}" - -t "${CONTAINER_NAME}:${CI_COMMIT_SHORT_SHA}" - -t "${CONTAINER_NAME}:latest" - --build-arg GIT_TAG="${CI_COMMIT_SHA}" - --build-arg GIT_COMMIT="${CI_COMMIT_REF_NAME}" - . - - docker push "${CONTAINER_NAME}:${CI_COMMIT_REF_NAME}" - - docker push "${CONTAINER_NAME}:${CI_COMMIT_SHORT_SHA}" - - docker push "${CONTAINER_NAME}:latest" - -run-webide-e2e-tests: - stage: e2e-test - image: tmaier/docker-compose - script: - - cd tools/webide/packages/e2e - - export WEBIDE_IMAGE="${CONTAINER_NAME}:${CI_COMMIT_SHORT_SHA}" - - docker-compose run e2e - -deploy-handoff: - # Handoff deployment duties to private repo - stage: deploy - variables: - IDE_DOCKER_IMAGE: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide" - LIGO_COMMIT_REF_NAME: "${CI_COMMIT_REF_NAME}" - trigger: ligolang/ligo-webide-deploy -