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

build and push docker on release #213

Closed
wants to merge 6 commits into from
Closed

build and push docker on release #213

wants to merge 6 commits into from

Conversation

mpnowacki-reef
Copy link

No description provided.

@mpnowacki-reef mpnowacki-reef changed the title pushing docker test build and push docker on release Oct 27, 2023
Copy link

@mjurbanski-reef mjurbanski-reef left a comment

Choose a reason for hiding this comment

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

nice work

Comment on lines -1 to +4
# Including project:version breaks `version` number generation under gha CD
# [project]
# requires-python = ">=3.7"
# name = "b2"
# version = "0.0.0" # this is wrong, but setuptools>61 insists its here
[project]
requires-python = ">=3.7"
name = "b2"
dynamic = ["version"]

Choose a reason for hiding this comment

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

nice

tmp_readme = pathlib.Path(f'{TEMPDIR}/README.md')
if not tmp_readme.exists():
tmp_readme.write_text(
(pathlib.Path(__file__).parent.parent.parent / 'README.md').read_text()

Choose a reason for hiding this comment

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

ROOT_PATH = pathlib.Path(__file__).parent.parent.parent on top of this file would be improve readability

@@ -61,7 +64,7 @@ def get_bucketinfo() -> Tuple[str, str]:

def test_download(b2_tool, bucket_name):

file_to_upload = 'README.md'
file_to_upload = f'{TEMPDIR}/README.md'

Choose a reason for hiding this comment

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

would be better as sample_file fixture/constant so we can change it in single place next time

Copy link
Author

Choose a reason for hiding this comment

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

good idea

def copy_readme_for_tests():
"""Copy the README.md file to /tmp so that docker tests can access it"""
tmp_readme = pathlib.Path(f'{TEMPDIR}/README.md')
if not tmp_readme.exists():

Choose a reason for hiding this comment

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

I wanted to comment how this won't always update the readme... but I see now this doesn't matter at all as we do not care about readme contents as at all as we really ne ANY sample file;

which brings again this would better be served by sample_file fixture that would return sample file path - if that file happens to be a readme copied from somewhere wouldn't matter then.

Copy link
Author

Choose a reason for hiding this comment

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

agreed

Comment on lines +2677 to +2678
if is_running_on_docker:
pytest.skip('Not supported on Docker')

Choose a reason for hiding this comment

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

why not?

Copy link
Author

Choose a reason for hiding this comment

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

To the best of my knowledge this can’t work. Running it yields strange errors about file descriptors not existing on the container os

Choose a reason for hiding this comment

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

oh, right. thanks

Comment on lines 2416 to 2418
shutil.copyfile(
pathlib.Path(__file__).parent.parent.parent / 'CHANGELOG.md', f'{TEMPDIR}/CHANGELOG.md'
)

Choose a reason for hiding this comment

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

seems like we have two different places in which we create these sample files

Copy link
Author

Choose a reason for hiding this comment

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

good catch!

:param cmd: a command to run
:param args: command's arguments
:param additional_env: environment variables to pass to the command, overwriting parent process ones
:param env_file_cmd_placeholder: If specified, all occurrences of this string in `args` will be substituted with a

Choose a reason for hiding this comment

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

no such argument

Comment on lines +1201 to +1204
sse_c_key_id = 'user-generated-key-id \nąóźćż\nœøΩ≈ç\nßäöü'
if is_running_on_docker:
# TODO: fix this once we figure out how to pass env vars with \n in them to docker, docker-compose should work
sse_c_key_id = sse_c_key_id.replace('\n', '')

Choose a reason for hiding this comment

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

export TEST_VAR=$(echo "a\nb")
docker run --rm -e TEST_VAR ubuntu env

this will require dropping env-file support and replacing it with -e ENVVAR listing, but what can you do.
If you don't like idea of putting docker-specific solutions into pytest (which we already do with skips), we can potentially write a docker_env_run.sh that would prepare -e $(env | awk -F "=" '{printf "-e %s=%s ", $1, $2}' inside of it and pytest would call it thru --sut as any other command

Copy link
Author

Choose a reason for hiding this comment

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

honestly I'm not sure this is worth, do you think so? It's a rare corner case, that probably doesn't require testing anyway

Choose a reason for hiding this comment

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

I'm just scared about someone loosing a ton of time on debugging this when they actually need it.

I guess solution in the middle would be to emit logger warning in https://github.com/reef-technologies/B2_Command_Line_Tool/pull/213/files#diff-0457e1c77e315509ddcb03e30c7d249298c33f012541c7e3654b6728e7cf56b5R424 IF any of the vars contains newlines. That way when adding a new test it blows up the warning will be visible in pytest output.

log = logfile.read()
assert re.search(log_file_regex, log), log
os.remove('b2_cli.log')
if not is_running_on_docker: # It's difficult to read the log in docker in CI

Choose a reason for hiding this comment

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

looking at this and README problem, I wonder if mounting local folder as workdir in docker would kill both birds with one stone
using -u $(id -u):$(id -g) it make it also pretty safe to do as well

Copy link
Author

Choose a reason for hiding this comment

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

I have considered this and don't like this approach, because it makes the tests work in significantly different environment than the target one. Users will not necessarily want to mount container user's homedir to a host directory. Before this PR, there were docker tests, and they worked by copying test code to the container and running everything in the container. Tests passed, but just running docker run b2 ls bucket failed, as the container user didn't have read rights to his own homedir, which flew under the radar of all tests. The tested image and the released image were slightly different, enough to invalidate all integration tests.

README.md Outdated Show resolved Hide resolved
Comment on lines +2677 to +2678
if is_running_on_docker:
pytest.skip('Not supported on Docker')

Choose a reason for hiding this comment

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

oh, right. thanks

Comment on lines +1201 to +1204
sse_c_key_id = 'user-generated-key-id \nąóźćż\nœøΩ≈ç\nßäöü'
if is_running_on_docker:
# TODO: fix this once we figure out how to pass env vars with \n in them to docker, docker-compose should work
sse_c_key_id = sse_c_key_id.replace('\n', '')

Choose a reason for hiding this comment

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

I'm just scared about someone loosing a ton of time on debugging this when they actually need it.

I guess solution in the middle would be to emit logger warning in https://github.com/reef-technologies/B2_Command_Line_Tool/pull/213/files#diff-0457e1c77e315509ddcb03e30c7d249298c33f012541c7e3654b6728e7cf56b5R424 IF any of the vars contains newlines. That way when adding a new test it blows up the warning will be visible in pytest output.

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.

2 participants