Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

end2end localdb tests #6839

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
178 changes: 170 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,170 @@
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.4.1
steps:
- checkout
- run: echo "A first hello"
defaults: &defaults
docker:
- image: circleci/node:8.12.0-browsers

version: 2
jobs:
pull_frontend_codebase:
<<: *defaults
working_directory: /tmp/repos/cbioportal
steps:
- checkout
- run:
name: Pull frontend code
command: |
export FRONTEND_VERSION=$(grep 'frontend\.version' pom.xml | sed 's/<frontend\.version>//g' | sed 's|</frontend\.version>||' | tr -d '[:blank:]') && \
cd .. && \
git clone https://github.com/$CIRCLE_PROJECT_USERNAME/cbioportal-frontend.git && \
cd cbioportal-frontend && \
git fetch --tags && \
git checkout ${FRONTEND_VERSION}
- persist_to_workspace:
root: /tmp/repos
paths:
- cbioportal-frontend

install_yarn:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the e2e tests are using the backend of this PR the install_yarn job prolly won't be necessary anymore because the frontend artifacts are already in the war. No need to recompile them

Copy link
Contributor Author

@n1zea144 n1zea144 Nov 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @inodb Unless I'm misunderstanding something, it is already using the backend.

I checkout the frontend code so I can run the end-2-end test scripts. By setting the BACKEND var, I thought the end2end tests build the proper backend (using the user/HASH of the PR).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - so it looks like it's pretty much working then 🎉. My point was mostly regarding some minor optimization. I think currently the localdb test tries to mount the frontend inside the war. That's why you need these steps of yarn run build etc. On the frontend e2e tests that makes sense cause you need to test against that frontend code in the PR. On the backend it's redundant b/c the war already contains the compiled frontend.

Another minor thing is that in the localdb tests the backend code gets pulled from GitHub again and the docker image is made. An optimization would be to create the image before running these tests and using it subsequently in the localdb tests ( to avoid the extra pull). You can then extend it with things like: only rebuild the image when the code has changed.

But yeah we can skip these optimizations for now I think, better to have something working in master branch.

Maybe just double check the backend of the PR is actually being used e.g. by introducing an error or something. And check it is properly creating the new backend image when you add a new commit in the pr to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true that the only use of the backend checkout right now is to get the version of the frontend to checkout. I explored the idea of creating an image from the checkout step done by the pull_frontend_codebase job. In one scenario, it may just involve the modification of build_portal_image.sh, maybe with some additional args passed to setup_docker_containers.sh (called by the circle-ci config). @pvannierop any thoughts on this?

I did see from the circle-ci page that my hash was being used during the Setup docker images and containers step. I went ahead and introduced an error as you suggested to confirm the error and fix on revert. This looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inodb I have a further thought on this - maybe I could add a check to see what files have changed after checkout and then short circuit the rest of the script when code files haven't changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inodb based on what I've discovered and communicated to you during our conversation this morning, I'm going to drop the effort to optimize the current configuration. I'll merge this PR once you give the approval. cc @pvannierop

<<: *defaults
working_directory: /tmp/repos/cbioportal-frontend
steps:
- attach_workspace:
at: /tmp/repos
- run:
name: "Install yarn at specific version"
command:
sudo npm install --global yarn@1.13.0
- run:
name: "Show yarn and node versions"
command: |
node --version
yarn --version
# cache build artifacts. Use concatenation of all source files as cache
# key. If there are no changes to src/ and yarn.lock, no need to rebuild
- run:
name: "Concatenate all source files to use as hash key for caching dist folder"
command: "cat yarn.lock $(find src/ -type f | sort) webpack.config.js vendor-bundles.webpack.config.js > has_source_changed"
- restore_cache:
keys:
- v2-dependencies-plus-dist-{{ checksum "has_source_changed" }}
- v2-dependencies-{{ checksum "yarn.lock" }}
# Download and cache dependencies
- run: yarn
- run:
name: "Make sure lock file is still the same"
command: 'git diff --exit-code yarn.lock > /dev/null || (echo -e "New package lock file at $(cat yarn.lock | curl -F c=@- https://ptpb.pw | grep url) (include this file in your PR to fix this test)"; git diff --exit-code yarn.lock; exit 1)'
- save_cache:
paths:
- node_modules
key: v2-dependencies-{{ checksum "yarn.lock" }}
- run:
name: "Run build if no dist folder"
command: 'ls dist || yarn run build'
environment:
DISABLE_SOURCEMAP: true
NO_PARALLEL: true
- save_cache:
paths:
- node_modules
- dist
- common-dist
key: v2-dependencies-plus-dist-{{ checksum "has_source_changed" }}
- persist_to_workspace:
root: /tmp/repos
paths:
- cbioportal-frontend

end_to_end_tests_localdb:
working_directory: /tmp/repos/cbioportal-frontend
machine:
enabled: true
image: ubuntu-1604:201903-01
steps:
- attach_workspace:
at: /tmp/repos
- run:
# needed to get python3 on the path (https://discuss.circleci.com/t/pyenv-pyvenv-command-not-found/4087/2)
name: Add python3 to path [corrects bug in circle ci image and may be removed in the future]
command: pyenv local 3.5.2 && virtualenv venv
- run:
name: Setup python libraries
command: |
pip3 install requests pyyaml
- run:
name: Setup e2e-environment
command: |
echo -e "\nexport BACKEND=$CIRCLE_PR_USERNAME:$CIRCLE_SHA1" >> $PORTAL_SOURCE_DIR/env/custom.sh && \
source $PORTAL_SOURCE_DIR/env/custom.sh || true && \
cd $TEST_HOME/local/runtime-config && \
./setup_environment.sh && ./setup_environment.sh >> $BASH_ENV
- run:
name: Generate checksum of data that populates the test database
command: |
$TEST_HOME/local/runtime-config/db_content_fingerprint.sh > /tmp/db_data_md5key
- restore_cache:
keys:
- v4-e2e-database-files-{{ checksum "/tmp/db_data_md5key" }}
- run:
name: Create MySQL data directory when no cache found
command: |
mkdir -p $DB_DATA_DIR
- run:
name: Setup docker images and containers
command: |
docker network create $DOCKER_NETWORK_NAME && \
cd $TEST_HOME/local/docker && \
if (ls $DB_DATA_DIR/* 2> /dev/null > /dev/null); then \
./setup_docker_containers.sh -p -e; \
else \
./setup_docker_containers.sh -p -e -d; \
fi
- run:
name: Change owner of MySQL database files (needed by cache)
command: |
sudo chmod -R 777 $DB_DATA_DIR && \
sudo chown -R circleci:circleci $DB_DATA_DIR
- save_cache:
paths:
- /tmp/mysql
key: v4-e2e-database-files-{{ checksum "/tmp/db_data_md5key" }}
- run:
name: Run end-2-end tests with studies in local database
command: |
cd $PORTAL_SOURCE_DIR && $TEST_HOME/local/runtime-config/run_container_screenshot_test.sh
- run:
name: "Make sure all screenshots are tracked (otherwise the test will always be successful)"
command: 'for f in $TEST_HOME/local/screenshots/reference/*.png; do git ls-files --error-unmatch $f > /dev/null 2> /dev/null || (echo -e "\033[0;31m $f not tracked \033[0m" && touch screenshots_not_tracked); done; ls screenshots_not_tracked > /dev/null 2> /dev/null && exit 1 || exit 0'
- store_artifacts:
path: /tmp/repos/cbioportal-frontend/end-to-end-test/local/screenshots
destination: /screenshots
- store_artifacts:
path: /tmp/repos/cbioportal-frontend/end-to-end-test/shared/image-compare
destination: /image-compare
- store_artifacts:
path: /tmp/repos/cbioportal-frontend/end-to-end-test/local/errorShots
destination: /errorShots
- store_test_results:
path: /tmp/repos/cbioportal-frontend/end-to-end-test/local/junit
- store_artifacts:
path: /tmp/repos/cbioportal-frontend/end-to-end-test/local/junit
- store_artifacts:
path: /tmp/repos/cbioportal-frontend/end-to-end-test/shared/imageCompare.html
destination: /imageCompare.html
environment:
PORTAL_SOURCE_DIR: /tmp/repos/cbioportal-frontend
TEST_HOME: /tmp/repos/cbioportal-frontend/end-to-end-test
FRONTEND_TEST_USE_LOCAL_DIST: true
NO_PARALLEL: true


workflows:
version: 2
end_to_end_tests:
jobs:
- pull_frontend_codebase
- install_yarn:
requires:
- pull_frontend_codebase
- end_to_end_tests_localdb:
requires:
- pull_frontend_codebase
- install_yarn