Skip to content

Conversation

@sfc-gh-gpijanski
Copy link
Contributor

@sfc-gh-gpijanski sfc-gh-gpijanski commented Aug 16, 2023

Each component's tests are run in a separate Docker image for environment isolation

@sfc-gh-gpijanski sfc-gh-gpijanski marked this pull request as ready for review August 18, 2023 12:45
""""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:
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's possible. Let's discuss it with Kamil tomorrow, but I like the idea :)

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, fine for me for now. Do you agree @sfc-gh-pbelczyk ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine by me

dev.py Outdated
)
e2e_dir = next(project_dir.glob("**/e2e/"), None)
if e2e_dir:
mount_catalog = e2e_dir.parts[-2]
Copy link
Contributor

Choose a reason for hiding this comment

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

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

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 possible that you had an empty catalog "e2e" in this component

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have hadolint setup for this repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

run_verbose([
"docker",
"run",
"--tty",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"--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
Comment on lines 91 to 94
"--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} && "
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"--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
Comment on lines 95 to 96
f"pip install dist/*.whl && " # Install whl package
f"pip install -e .[devel] && " # Install dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about?

find /dist/ -name '*.whl' | xargs -I {} echo '{}[devel]' | xargs pip install

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works. Thanks

- name: Install python dependencies
run: ./dev.py install-python-deps
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
Copy link
Contributor

@sfc-gh-kbregula sfc-gh-kbregula Aug 22, 2023

Choose a reason for hiding this comment

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

dev.py Outdated

ARGUMENTS = {
"e2e-build-images": [
("--streamlit-version", "latest", "Streamlit version for which tests will be run."),
Copy link
Contributor

@sfc-gh-kbregula sfc-gh-kbregula Aug 22, 2023

Choose a reason for hiding this comment

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

Can you extract each argument to a new variable to reduce code duplication?

ARG_STREAMLIT_VERSION=....
ARG_PYTHON_VERSION=....


- name: Run e2e tests
run: ./dev.py run-e2e
run: ./dev.py e2e-run-tests
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

uses: actions/upload-artifact@v3
with:
name: all-wheel
path: dist/*.whl
Copy link
Contributor

Choose a reason for hiding this comment

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

This action job is called build-examples-templates, but I think it does a little more now.

sfc-gh-pbelczyk added a commit to streamlit/docs that referenced this pull request Aug 22, 2023
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.

name: Examples + Templates / node-version=${{ matrix.node-version }} / component_lib_version=${{ matrix.component_lib_version }}
env:
NODE_VERSION: ${{ matrix.node-version }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
NODE_VERSION: ${{ matrix.node-version }}
NODE_VERSION: ${{ matrix.node_version }}

run: ./dev.py install-wheel-packages
- name: Set up Docker Buildx
if: matrix.node_version == '19.x'
uses: docker/setup-buildx-action@7703e82fbced3d0c9eec08dff4429c023a5fd9a9
Copy link
Contributor

Choose a reason for hiding this comment

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

@sfc-gh-gpijanski sfc-gh-gpijanski merged commit 3abafe8 into master Aug 23, 2023
snehankekre pushed a commit to streamlit/docs that referenced this pull request Aug 23, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants