SeedSigner / seedsigner

Use an air-gapped Raspberry Pi Zero to sign for Bitcoin transactions! (and do other cool stuff)
MIT License
720 stars 168 forks source link

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

Closed newtonick closed 1 year ago

newtonick commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago
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 commented 1 year ago

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

jdlcdl commented 1 year ago

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.

newtonick commented 1 year ago

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 commented 1 year ago

As of cd85142

This is still working for me.