Setup running e2e tests in Docker image#70
Conversation
| """"Install all dependencies needed to run e2e tests for all examples and templates""" | ||
| def cmd_e2e_build_images(args): | ||
| """Build docker images for each component e2e tests""" | ||
| for project_dir in EXAMPLE_DIRECTORIES + TEMPLATE_DIRECTORIES: |
There was a problem hiding this comment.
Is it possible to aggregate all examples in one docker container? Setup docker takes some time and we probably only need separate dockers for template and template-reactless. Probably it can be done in later PR
There was a problem hiding this comment.
Yes, it's possible. Let's discuss it with Kamil tomorrow, but I like the idea :)
There was a problem hiding this comment.
Our goal is less than 15 minutes and we seem to be achieving this so there is no need to optimize. If I was optimizing something, I would put playwright in the docker image so that we don't have to install the browser multiple times, but that's not even needed now. Multiple images and multiple containers are not a problem for me as long as they are lightweight.
There was a problem hiding this comment.
Ok, fine for me for now. Do you agree @sfc-gh-pbelczyk ?
dev.py
Outdated
| ) | ||
| e2e_dir = next(project_dir.glob("**/e2e/"), None) | ||
| if e2e_dir: | ||
| mount_catalog = e2e_dir.parts[-2] |
There was a problem hiding this comment.
Not sure why, but also create CustomDataframe for me, even if there is no tests. I would leave it for now, as we will be testing this component in the future anyway, but it will be possible to check that we are not creating an unnecessary container once we have all the tests in place
There was a problem hiding this comment.
It is possible that you had an empty catalog "e2e" in this component
There was a problem hiding this comment.
Actually I don't have, but probably it's waste of time to debug it, since we want to have this tests in the future
There was a problem hiding this comment.
I added another check for the catalog e2e if it is not empty
Dockerfile
Outdated
| ARG STREAMLIT_VERSION="latest" | ||
| ENV E2E_STREAMLIT_VERSION=${STREAMLIT_VERSION} | ||
|
|
||
| # hadolint ignore=DL3013 |
There was a problem hiding this comment.
Do we have hadolint setup for this repo?
There was a problem hiding this comment.
Copy-pasted :P I am removing that comment unless you think that we need hadolint. As for me, I think we can live without it
There was a problem hiding this comment.
Can you create an issue in EPIC: https://snowflakecomputing.atlassian.net/browse/STREAMLIT-3913 ?
| run_verbose([ | ||
| "docker", | ||
| "run", | ||
| "--tty", |
There was a problem hiding this comment.
| "--tty", | |
| "--tty", | |
| "--rm", |
Running containers with --rm flag is good for those containers that you use for very short while just to accomplish something, e.g., compile your application inside a container, or just testing something that it works, and then you are know it's a short lived container and you tell your Docker daemon that once it's done running, erase everything related to it and save the disk space.
https://stackoverflow.com/questions/49726272/what-is-the-rm-flag-doing
dev.py
Outdated
| "--volume", f"{e2e_dir.parent}/:/component/{mount_catalog}", | ||
| image_tag, | ||
| "/bin/sh", "-c", # Run a shell command inside the container | ||
| f"cd /component/{mount_catalog} && " |
There was a problem hiding this comment.
| "--volume", f"{e2e_dir.parent}/:/component/{mount_catalog}", | |
| image_tag, | |
| "/bin/sh", "-c", # Run a shell command inside the container | |
| f"cd /component/{mount_catalog} && " | |
| "--volume", f"{e2e_dir.parent}/:/component/", | |
| image_tag, | |
| "/bin/sh", "-c", # Run a shell command inside the container | |
| f"cd /component/ && " |
I don't think we need to create a separate directory here, and this could potentially cause a shell injection threat. In this case, there is no real threat, because the input is under our control, but it is still worth being careful.
dev.py
Outdated
| f"pip install dist/*.whl && " # Install whl package | ||
| f"pip install -e .[devel] && " # Install dependencies |
There was a problem hiding this comment.
| f"pip install dist/*.whl && " # Install whl package | |
| f"pip install -e .[devel] && " # Install dependencies | |
| f"pip install dist/*.whl[devel] && " # Install whl package and dev dependencies |
We don't want to use local source code to run tests.
There was a problem hiding this comment.
Your solution doesn't work. But I managed to change it to this:
f"pip install /component/dist/*.whl && " # Install whl package
f"pip install /component/[devel] && " # Install dev dependencies
There was a problem hiding this comment.
What do you think about?
find /dist/ -name '*.whl' | xargs -I {} echo '{}[devel]' | xargs pip install
There was a problem hiding this comment.
Works. Thanks
.github/workflows/ci.yaml
Outdated
| - name: Install python dependencies | ||
| run: ./dev.py install-python-deps | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 |
There was a problem hiding this comment.
Please pin individual actions to a full-length commit SHA to make the action immutable. For details, see: https://snowflakecomputing.atlassian.net/wiki/spaces/CITS/pages/2420933452/Github+Actions+and+Runners+Security+Baseline+Requirements#Req-#10-Using-Third-Party-Actions
https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
dev.py
Outdated
|
|
||
| ARGUMENTS = { | ||
| "e2e-build-images": [ | ||
| ("--streamlit-version", "latest", "Streamlit version for which tests will be run."), |
There was a problem hiding this comment.
Can you extract each argument to a new variable to reduce code duplication?
ARG_STREAMLIT_VERSION=....
ARG_PYTHON_VERSION=....
.github/workflows/ci.yaml
Outdated
|
|
||
| - name: Run e2e tests | ||
| run: ./dev.py run-e2e | ||
| run: ./dev.py e2e-run-tests |
There was a problem hiding this comment.
We want to run E2E tests for only one version of NodeJS and one version of Python, but we should use different versions of Streamlit and The Streamlit Component Library.
There was a problem hiding this comment.
I will add this in https://snowflakecomputing.atlassian.net/browse/STREAMLIT-3898
| @@ -98,17 +98,14 @@ jobs: | |||
| path: dist/*.whl | |||
There was a problem hiding this comment.
This action job is called build-examples-templates, but I think it does a little more now.
While working on e2e setup for component-template (streamlit/component-template#70) we extract example to separate file, so command for run example component is now invalid.
3b03a96 to
a38f1bd
Compare
.github/workflows/ci.yaml
Outdated
|
|
||
| name: Examples + Templates / node-version=${{ matrix.node-version }} / component_lib_version=${{ matrix.component_lib_version }} | ||
| env: | ||
| NODE_VERSION: ${{ matrix.node-version }} |
There was a problem hiding this comment.
| NODE_VERSION: ${{ matrix.node-version }} | |
| NODE_VERSION: ${{ matrix.node_version }} |
.github/workflows/ci.yaml
Outdated
| run: ./dev.py install-wheel-packages | ||
| - name: Set up Docker Buildx | ||
| if: matrix.node_version == '19.x' | ||
| uses: docker/setup-buildx-action@7703e82fbced3d0c9eec08dff4429c023a5fd9a9 |
There was a problem hiding this comment.
Can you add human-readable version in the comments?
https://github.blog/changelog/2022-10-31-dependabot-now-updates-comments-in-github-actions-workflows-referencing-action-versions/
While working on e2e setup for component-template (streamlit/component-template#70) we extract example to separate file, so command for run example component is now invalid.
Each component's tests are run in a separate Docker image for environment isolation