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

Add dockerfile and docker-compose.yml for easy pytest and screenshot environment #476

Merged
merged 4 commits into from
Sep 14, 2023

Conversation

newtonick
Copy link
Collaborator

@newtonick newtonick commented Sep 7, 2023

Another option for those who want to do development locally and run pytest and the screenshot generator without worrying about installing python 3.10 and the correct dependencies (or deal with virtualenvwrapper).

To spin up a docker container:
docker compose up -d

Then to create a shell session inside the container:
docker exec -it seedsigner-seedsigner-dev-1 bash

Then run pytest or pytest tests/screenshot_generator/generator.py.

@jdlcdl
Copy link

jdlcdl commented Sep 7, 2023

I used docker-compose up -d instead of docker compose up -d. At first, I got:

ERROR: yaml.scanner.ScannerError: while scanning for the next token
found character '\t' that cannot start any token
  in "./docker-compose.yml", line 13, column 1

Switching tabs to 4-spaces on the last two lines of docker-compose.yml resolved the above error and docker container built in around 6 minutes.

Jumping into the new container, many tests failed at first, but running the 3 pip install commands helped a bit (even though the Dockerfile seems to do this already), but was still having font-file errors, not found.

Referencing @dbast's pr #469 resolutions here, I made progress. After adding a MANIFEST.in file w/ recursive-include src/seedsigner/resources *, editing setup.py to add include_package_data=True,, and re-running the 3 pip install commands, I succeeded in getting all tests to run -- passing at 100%, and also got screenshot_generator to run.

I note that this pr was based on 0.7.0-rc1 and not the head of the 'dev' at 5b75dbe so I'm not getting very latest bug-fixes or screenshots.

@newtonick
Copy link
Collaborator Author

ERROR: yaml.scanner.ScannerError: while scanning for the next token
found character '\t' that cannot start any token
  in "./docker-compose.yml", line 13, column 1

Switching tabs to 4-spaces on the last two lines of docker-compose.yml resolved the above error and docker container built in around 6 minutes.

Commit ee4d914 hopefully resolves this.

Jumping into the new container, many tests failed at first, but running the 3 pip install commands helped a bit (even though the Dockerfile seems to do this already), but was still having font-file errors, not found.

I'm not able to recreate this. This is what I see when create a new image/container and run the pytest.

$> docker --version
Docker version 24.0.5, build ced0996
$> docker compose version
Docker Compose version v2.20.2-desktop.1
$> docker compose up -d
no configuration file provided: not found
$> cd Source/seedsigner
$> clear
$> cd ..
$> clear
$> cd seedsigner
$> docker --version
Docker version 24.0.5, build ced0996
$> docker compose version
Docker Compose version v2.20.2-desktop.1
$> docker compose up -d
[+] Building 129.3s (15/15) FINISHED                                                                                                                                                     docker:desktop-linux
 => [seedsigner-dev internal] load build definition from Dockerfile                                                                                                                                      0.0s
 => => transferring dockerfile: 549B                                                                                                                                                                     0.0s
 => [seedsigner-dev internal] load .dockerignore                                                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                                                                          0.0s
 => [seedsigner-dev internal] load metadata for docker.io/library/python:3.10-bullseye                                                                                                                   1.4s
 => CACHED [seedsigner-dev  1/11] FROM docker.io/library/python:3.10-bullseye@sha256:73b92ab3d34c083eb67425cb22c682d459acb49da0e3c1dc6f24dad998298b2d                                                    0.0s
 => => resolve docker.io/library/python:3.10-bullseye@sha256:73b92ab3d34c083eb67425cb22c682d459acb49da0e3c1dc6f24dad998298b2d                                                                            0.0s
 => [seedsigner-dev internal] load build context                                                                                                                                                         0.2s
 => => transferring context: 3.19MB                                                                                                                                                                      0.2s
 => [seedsigner-dev  2/11] RUN apt-get -qq update                                                                                                                                                        3.5s
 => [seedsigner-dev  3/11] RUN apt-get -y -qq install zbar-tools                                                                                                                                         1.4s
 => [seedsigner-dev  4/11] ADD . /seedsigner                                                                                                                                                             0.5s
 => [seedsigner-dev  5/11] WORKDIR /seedsigner                                                                                                                                                           0.0s
 => [seedsigner-dev  6/11] RUN pip3 install -r requirements.txt                                                                                                                                        119.5s
 => [seedsigner-dev  7/11] RUN pip3 install -r tests/requirements.txt                                                                                                                                    1.6s
 => [seedsigner-dev  8/11] RUN pip3 install -e .                                                                                                                                                         0.6s
 => [seedsigner-dev  9/11] RUN rm -r /seedsigner                                                                                                                                                         0.3s
 => [seedsigner-dev 10/11] WORKDIR /seedsigner                                                                                                                                                           0.0s
 => [seedsigner-dev] exporting to image                                                                                                                                                                  0.4s
 => => exporting layers                                                                                                                                                                                  0.4s
 => => writing image sha256:f6b6f2ccb84c9663cd6d2135dea47ccb786b72f890c35fc46f3b3999ac3b6774                                                                                                             0.0s
 => => naming to docker.io/library/seedsigner-seedsigner-dev                                                                                                                                             0.0s
[+] Running 1/1
 ✔ Container seedsigner-seedsigner-dev-1  Started                                                                                                                                                        0.2s
$> docker ps
CONTAINER ID   IMAGE                       COMMAND                   CREATED         STATUS         PORTS     NAMES
a90a80dec4c2   seedsigner-seedsigner-dev   "sh -c 'bash -c \"tai…"   9 seconds ago   Up 8 seconds             seedsigner-seedsigner-dev-1
$> docker exec -it seedsigner-seedsigner-dev-1 bash
root@a90a80dec4c2:/seedsigner# pytest
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.13, pytest-6.2.4, py-1.11.0, pluggy-0.13.1
rootdir: /seedsigner, configfile: pytest.ini, testpaths: tests
collected 83 items

tests/test_bip85.py .                                                                                                                                                                                  [  1%]
tests/test_controller.py .....                                                                                                                                                                         [  7%]
tests/test_decodepsbtqr.py ............                                                                                                                                                                [ 21%]
tests/test_embit_utils.py .....                                                                                                                                                                        [ 27%]
tests/test_encodepsbtqr.py ......                                                                                                                                                                      [ 34%]
tests/test_flows.py ........                                                                                                                                                                           [ 44%]
tests/test_flows_psbt.py ..                                                                                                                                                                            [ 46%]
tests/test_flows_seed.py ...........                                                                                                                                                                   [ 60%]
tests/test_flows_settings.py ....                                                                                                                                                                      [ 65%]
tests/test_flows_tools.py ....                                                                                                                                                                         [ 69%]
tests/test_flows_view.py ....                                                                                                                                                                          [ 74%]
tests/test_mnemonic_generation.py ........                                                                                                                                                             [ 84%]
tests/test_psbt_parser.py .                                                                                                                                                                            [ 85%]
tests/test_seed.py .                                                                                                                                                                                   [ 86%]
tests/test_seedqr.py ...                                                                                                                                                                               [ 90%]
tests/test_settings.py ......                                                                                                                                                                          [ 97%]
tests/test_settingsqr_decoder.py ..                                                                                                                                                                    [100%]

============================================================================================= 83 passed in 0.82s =============================================================================================

@newtonick
Copy link
Collaborator Author

newtonick commented Sep 7, 2023

I did find an issue with the pyzbar dependency in requirements.txt. I'll fix this later. Fixed with cd85142.

@jdlcdl
Copy link

jdlcdl commented Sep 7, 2023

I'm not able to recreate this. This is what I see when create a new image/container and run the pytest.

After cleaning up docker more than once, I too am unable to re-create the same errors I saw earlier.

As of ee4d914

This is working for me.


RUN pip3 install -r requirements.txt
RUN pip3 install -r tests/requirements.txt
RUN pip3 install -e .
Copy link
Contributor

Choose a reason for hiding this comment

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

Could avoid the ADD . /seedsigner and invoke the pip3 install -e . in a bashrc file that we copy over (it could either check for "seedsigner" in pip freeze or just run the install on every login).

I tend to set a bashrc anyway that has terminal coloring and whatnot:
COPY docker/bashrc /root/.bashrc

case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

cd /seedsigner
pip install -e .

@newtonick
Copy link
Collaborator Author

I've added a setup.sh that executes when the container starts. This will run pip install -e ..

I've also updated requirements.txt to install pyzbar to ignore setuptools and just install from the GitHub repo specified. I'm open to other suggestions on how to do this in a better way.

@jdlcdl
Copy link

jdlcdl commented Sep 10, 2023

As of cd85142

This is still working for me.

@newtonick newtonick merged commit b5d244a into SeedSigner:dev Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged Not Yet Released
Development

Successfully merging this pull request may close these issues.

3 participants