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

[Cloud Deployment I]: Main dockerfile #383

Merged
merged 129 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
1ee0231
Create neuroconv_dockerfile
CodyCBakerPhD Mar 27, 2023
ee8873b
Create docker_images.rst
CodyCBakerPhD Mar 27, 2023
a0871e1
Update developer_guide.rst
CodyCBakerPhD Mar 27, 2023
9c148a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2023
91bbd36
add use instructions
CodyCBakerPhD Mar 30, 2023
66a0aff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 30, 2023
7de44dc
Update neuroconv_dockerfile
CodyCBakerPhD Mar 30, 2023
dee4842
Rename neuroconv_dockerfile to neuroconv_latest_release_dockerfile
CodyCBakerPhD Mar 30, 2023
17031c9
added dev build
CodyCBakerPhD Mar 30, 2023
de6b5f6
Update docker_images.rst
CodyCBakerPhD Mar 30, 2023
a55749e
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Mar 30, 2023
37862f2
Update neuroconv_developer_build_dockerfile
CodyCBakerPhD Mar 30, 2023
45fe266
Update docker_images.rst
CodyCBakerPhD Mar 31, 2023
c8d6edd
Update docker_images.rst
CodyCBakerPhD Apr 2, 2023
c3940b7
Update docker_images.rst
CodyCBakerPhD Apr 2, 2023
c3984d3
Create neuroconv_developer_build_auto_config
CodyCBakerPhD Apr 2, 2023
dd0f2a2
Create rclone_auto_config_dockerfile
CodyCBakerPhD Apr 2, 2023
fcea20a
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Apr 2, 2023
c406e76
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Apr 24, 2023
3488379
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Jun 29, 2023
c08ed01
add workflow for docker release
CodyCBakerPhD Jun 29, 2023
e7b5557
add docker publish for dev branch
CodyCBakerPhD Jun 29, 2023
23285ed
initial trigger to show up on interface
CodyCBakerPhD Jun 29, 2023
9a02034
trying to fix dev image publish
CodyCBakerPhD Jun 29, 2023
73ffcba
update username and ghcr name
CodyCBakerPhD Jun 29, 2023
e0c6046
try fixing action path
CodyCBakerPhD Jun 29, 2023
5419ce1
Update neuroconv_developer_build_dockerfile
CodyCBakerPhD Jun 29, 2023
05944f5
retrigger with new credentials
CodyCBakerPhD Jun 29, 2023
a09904f
need to keep push until on main
CodyCBakerPhD Jun 29, 2023
744cb56
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Jan 25, 2024
dd481a0
Merge branch 'main' into add_first_dockerfile
bendichter Feb 16, 2024
e8ed3ea
update credentials
CodyCBakerPhD Feb 22, 2024
8330621
try to add tag
CodyCBakerPhD Feb 22, 2024
73a7e16
Update dockerfiles/neuroconv_developer_build_auto_config
CodyCBakerPhD Feb 22, 2024
2479d05
Apply suggestions from code review
CodyCBakerPhD Feb 22, 2024
675abcf
Update .github/workflows/auto-publish-docker-dev-branch.yml
CodyCBakerPhD Feb 22, 2024
323e17f
add docker tests
CodyCBakerPhD Mar 18, 2024
5dd6ffa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 18, 2024
0d92791
add CI
CodyCBakerPhD Mar 18, 2024
b932329
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Mar 18, 2024
99e673b
update installation for pytest checks
CodyCBakerPhD Mar 18, 2024
64f4fee
debug attributes
CodyCBakerPhD Mar 18, 2024
11ac0bb
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Mar 21, 2024
729cc81
fix docs rendering
CodyCBakerPhD Mar 21, 2024
da3bd58
improve docs
CodyCBakerPhD Mar 21, 2024
3729115
add full demo
CodyCBakerPhD Mar 21, 2024
055f226
move to user guide
CodyCBakerPhD Mar 21, 2024
51e74f1
add to index
CodyCBakerPhD Mar 21, 2024
18d518f
remove from dev guide
CodyCBakerPhD Mar 21, 2024
778ede9
try non-slim and normal python path
CodyCBakerPhD Mar 21, 2024
2b97324
push once and add manual
CodyCBakerPhD Mar 21, 2024
1b4ad26
remove push after first time
CodyCBakerPhD Mar 21, 2024
f2ca5fb
printout tag in action
CodyCBakerPhD Mar 21, 2024
663ee2e
clarify workflow name
CodyCBakerPhD Mar 21, 2024
9bc34b5
add doc ref
CodyCBakerPhD Mar 21, 2024
3fe08b1
push again for new name
CodyCBakerPhD Mar 21, 2024
56bba2e
specify output directory
CodyCBakerPhD Mar 21, 2024
db81628
set version tag through explicit output
CodyCBakerPhD Mar 21, 2024
09a3ccf
try dot context in v5
CodyCBakerPhD Mar 21, 2024
7d2322b
correct names for latest release
CodyCBakerPhD Mar 21, 2024
65634d7
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Mar 21, 2024
67b7ad5
undo push after success
CodyCBakerPhD Mar 21, 2024
586828a
correct docs indent
CodyCBakerPhD Mar 21, 2024
da7835b
polish demo
CodyCBakerPhD Mar 21, 2024
af9e86f
try to determine if slim is the problem
CodyCBakerPhD Mar 21, 2024
b76a18e
re-add push
CodyCBakerPhD Mar 21, 2024
8cb41c7
update dev version too
CodyCBakerPhD Mar 21, 2024
153f95c
shorten
CodyCBakerPhD Mar 21, 2024
edc6e19
adjust dockerfile name
CodyCBakerPhD Mar 21, 2024
1ad92c4
correct file reference
CodyCBakerPhD Mar 21, 2024
5e967fa
update demo
CodyCBakerPhD Mar 21, 2024
714aa4b
swap to conda for git in dev
CodyCBakerPhD Mar 21, 2024
2a0896d
debugging dev file
CodyCBakerPhD Mar 21, 2024
019cf5c
include szonja fix
CodyCBakerPhD Mar 21, 2024
62d0b49
debug dev file
CodyCBakerPhD Mar 21, 2024
ab82d22
cancel past triggers
CodyCBakerPhD Mar 21, 2024
25f080f
cancel past triggers
CodyCBakerPhD Mar 21, 2024
d07d750
debug dev file
CodyCBakerPhD Mar 21, 2024
e5a6e63
move docker tests out of main scopes
CodyCBakerPhD Mar 21, 2024
33b7b4c
clarify docs
CodyCBakerPhD Mar 21, 2024
22434b6
dev file debugging
CodyCBakerPhD Mar 21, 2024
eab9ab2
move rclone stuff to other branch
CodyCBakerPhD Mar 21, 2024
ff95795
re-order user guide
CodyCBakerPhD Mar 21, 2024
088026a
update dev docs
CodyCBakerPhD Mar 21, 2024
2bf30e3
update yaml variable dockerfile
CodyCBakerPhD Mar 21, 2024
47967b9
adjust name
CodyCBakerPhD Mar 21, 2024
d590878
add workflow for YAML alternative
CodyCBakerPhD Mar 21, 2024
b3423e8
adjust docker test
CodyCBakerPhD Mar 21, 2024
8ccace1
add test for yaml variable
CodyCBakerPhD Mar 21, 2024
60bf1d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2024
5589e2f
update dockerfile with flags
CodyCBakerPhD Mar 21, 2024
32c18f8
update dev docs
CodyCBakerPhD Mar 21, 2024
7f4f5d1
remove push
CodyCBakerPhD Mar 21, 2024
1a3771d
Update CHANGELOG.md
CodyCBakerPhD Mar 21, 2024
7601724
bypass git, just do direct local install
CodyCBakerPhD Mar 21, 2024
f3dee1b
fix scope
CodyCBakerPhD Mar 21, 2024
8278e57
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2024
3bc6b30
Update docker_testing.yml
CodyCBakerPhD Mar 21, 2024
03e5fff
Update neuroconv_dev_dockerfile
CodyCBakerPhD Mar 21, 2024
f20acba
Update build_and_upload_docker_image_dev.yml
CodyCBakerPhD Mar 21, 2024
58990b7
Update neuroconv_dev_dockerfile
CodyCBakerPhD Mar 21, 2024
2423f28
debugs to tests
CodyCBakerPhD Mar 21, 2024
339ee36
Update build_and_upload_docker_image_dev.yml
CodyCBakerPhD Mar 21, 2024
b18465d
debug environment variable paths
CodyCBakerPhD Mar 21, 2024
843049d
printout docker results; remove one test case
CodyCBakerPhD Mar 21, 2024
f50ffab
correct GHCR base
CodyCBakerPhD Mar 21, 2024
bce202d
force rebuild
CodyCBakerPhD Mar 21, 2024
8172be5
restore login
CodyCBakerPhD Mar 21, 2024
e4666d0
debugging
CodyCBakerPhD Mar 22, 2024
61ccba5
debugging
CodyCBakerPhD Mar 22, 2024
a7a91a1
debugging
CodyCBakerPhD Mar 22, 2024
36d52f4
debugging
CodyCBakerPhD Mar 22, 2024
008d448
debugging
CodyCBakerPhD Mar 22, 2024
45aafee
try to pull images first
CodyCBakerPhD Mar 22, 2024
0aa5d28
already was apparently
CodyCBakerPhD Mar 22, 2024
38206fc
add missing quotes
CodyCBakerPhD Mar 22, 2024
abc7a24
add missing f-string
CodyCBakerPhD Mar 22, 2024
9ce262a
add description
CodyCBakerPhD Mar 22, 2024
a6ab697
add description
CodyCBakerPhD Mar 22, 2024
29cbcc5
add description
CodyCBakerPhD Mar 22, 2024
87704f3
try this
CodyCBakerPhD Mar 22, 2024
36ce2c0
remove pushes; add date tag to dev
CodyCBakerPhD Mar 22, 2024
0e246b8
increase dev to weekly
CodyCBakerPhD Mar 22, 2024
8f5bdbc
one last rebuild
CodyCBakerPhD Mar 22, 2024
1669604
try without provenance
CodyCBakerPhD Mar 22, 2024
d7858bd
try without provenance
CodyCBakerPhD Mar 22, 2024
d4ddb67
disable all push
CodyCBakerPhD Mar 22, 2024
87e5373
disable all push
CodyCBakerPhD Mar 22, 2024
c29264e
Merge branch 'main' into add_first_dockerfile
CodyCBakerPhD Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dockerfiles/neuroconv_developer_build_auto_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.10
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
LABEL org.opencontainers.image.source=https://github.com/catalystneuro/neuroconv
ADD /neuroconv /neuroconv
RUN cd neuroconv \
&& pip install -e .[full]
CMD echo "$YAML_STREAM" > run.yml \
&& cat run.yml \
&& neuroconv run.yml
6 changes: 6 additions & 0 deletions dockerfiles/neuroconv_developer_build_dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.10
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
LABEL org.opencontainers.image.source=https://github.com/catalystneuro/neuroconv
ADD /neuroconv /neuroconv
RUN cd neuroconv \
&& pip install -e .[full]
CMD ["python3 -m"]
4 changes: 4 additions & 0 deletions dockerfiles/neuroconv_latest_release_dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM python:3.10
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
LABEL org.opencontainers.image.source=https://github.com/catalystneuro/neuroconv
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
RUN pip install neuroconv[full]
CMD ["python3 -m"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I also had an error after running

docker run -it neuroconv_latest_release
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "python3 -m": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled

So I changed this to:

Suggested change
CMD ["python3 -m"]
CMD ["python3", "-c", "import neuroconv"]

Copy link
Member Author

@CodyCBakerPhD CodyCBakerPhD Mar 21, 2024

Choose a reason for hiding this comment

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

The point of a CMD is to define the prepend to the entrypoint - since we want this docker image, when run as a container, to effectively emulate an entire functioning Python environment, I'm trying to design it in such a way that it is pretty much just like calling the CLI from a normal Python environment

That is, in a typical Python NeuroConv environment you would do

neuroconv my_yaml_file.yml

now with the docker we want

docker run <other docker required stuff> neuroconv my_yaml_file.yml

While it is conceptually possible to just rely on implicit entrypoint definition from successful installation and association inside the docker container, it is much safer apparently to call python -m directly on the module

CMD ["python3", "-c", "import neuroconv"]

This simply verifies that the module is importable, it does not route the CLI - I don't even think it would facilitate prepending of a command sent to the container either

Anyway, I think the problem was python vs. python3 usage. This seems to be working now, and I added a full demo if you want to check that out and see if that works for you

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, seems fine

5 changes: 5 additions & 0 deletions dockerfiles/rclone_auto_config_dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM rclone/rclone:latest
CMD printf "[$DRIVE_NAME]\ntype = drive\nscope = drive\ntoken = {\"access_token\":\"$TOKEN\",\"token_type\":\"Bearer\",\"refresh_token\":\"$REFRESH_TOKEN\",\"expiry\":\"$EXPIRY\"}" > /mnt/data/rclone.conf \
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
&& cat /mnt/data/rclone.conf \
&& rclone $RCLONE_COMMAND
ENTRYPOINT [""]
1 change: 1 addition & 0 deletions docs/developer_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ The most common contribution is for a user/developer to help us integrate a new
Testing Suite <developer_guide/testing_suite>
Coding Style <developer_guide/style_guide>
Building the Documentation <developer_guide/building_documentation>
Building the Docker Image <developer_guide/docker_images.rst>

Or feel free to raise a `bug report <https://github.com/catalystneuro/neuroconv/issues/new?assignees=&labels=bug&template=bug_report.yml&title=%5BBug%5D%3A+>`_ or `feature request <https://github.com/catalystneuro/neuroconv/issues/new?assignees=&labels=enhancement&template=feature_request.yml&title=%5BFeature%5D%3A+>`_ for our maintainers to prioritize!
94 changes: 94 additions & 0 deletions docs/developer_guide/docker_images.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Manually Build Docker Images
----------------------------

.. note: It is highly recommended to build the docker image on the same basic system or architecture type that you intend to run it on, *i.e.*, AWS Linux AMI 64-bit (x86), as it may experience difficulties running on other radically different systems (like an M1 Mac).

.. note: The NeuroConv docker container comes prepackaged with all required installations, *i.e.*, equivalent to `pip install neuroconv[full]`. As such it is fairly heavy, so be sure that whatever system (or specifically CI environment) you build with has sufficient disk space.


Latest Release
~~~~~~~~~~~~~~

.. code:

docker build -f neuroconv_latest_release_dockerfile -t neuroconv_latest_release .


Dev Branch
~~~~~~~~~~

Checkout to a specific branch on a local clone, then

.. code:

docker build -f neuroconv_developer_build_dockerfile -t neuroconv_dev .



Publish Container to GitHub
---------------------------

The `LABEL` is the important item here; it determines the host repository on the GitHub Container Registry (GHCR). In each docker file we wish to publish on the GHCR, we will add this label right after the `FROM` clause

.. code:

FROM PARENT_IMAGE:TAG
LABEL org.opencontainers.image.source=https://github.com/catalystneuro/neuroconv

After building the image itself, we can publish the container with

.. code:

docker tag IMAGE_NAME ghcr.io/catalystneuro/IMAGE_NAME:TAG
export CR_PAT="<YOUR GITHUB SECRET TOKEN>"
echo $CR_PAT | docker login ghcr.io -u <YOUR GITHUB USERNAME> --password-stdin
docker push ghcr.io/catalystneuro/IMAGE_NAME:TAG

.. note: Though it may appear confusing, the use of the `IMAGE_NAME` in these steps determines only the _name_ of the package as available from the 'packages' screen of the host repository; the `LABEL` itself ensured the upload and linkage to the NeuroConv GHCR.



Running Docker Container on local YAML (Linux)
----------------------------------------------

You can either perform a manual build locally following the instructions above, or pull the container from the GitHub Container Registry (GHCR) with

.. code:

docker pull ghcr.io/catalystneuro/neuroconv:latest

and can then run the entrypoint (equivalent to the usual CLI usage) on a YAML specification file (named `your_specification_file.yml`) with

.. code:

docker run -it --volume /your/local/drive/:/desired/alias/of/drive/ ghcr.io/catalystneuro/neuroconv:latest neuroconv /desired/alias/of/drive/your_specification_file.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @CodyCBakerPhD, and sorry this has taken be so long to review. This looks great, but as you note in the comment, I think this needs testing. Could you at least create or point to a YAML file that can be used as input for this docker run command?




Running Docker Container with a YAML_STREAM (Linux)
---------------------------------------------------

An alternative approach that simplifies usage on AWS Batch is to specify the YAML contents as an environment variable. The file is constructed in the first step of the container launch. The only potential downside with this usage is maximum file size (~13,000 characters; current example files do not come remotely close to this).

Otherwise, the YAML file transfer will have to managed separately, likely as a part of the data transfer or an entirely separate transfer step.

To use manually outside of AWS Batch,

.. code:

export YAML_STREAM="<copy and paste contents of YAML file (manually replace instances of double quotes with single quotes)>"
docker run -it --volume /your/local/drive/:/desired/alias/of/drive/ ghcr.io/catalystneuro/neuroconv:dev_auto_yaml

To use automatically via a Python helper function (coming in a separate PR)

.. code:
import os

with open(file="my_yaml_file.yml") as file:
yaml_stream = "".join(file.readlines()).replace("\"", "'")

os.environ["YAML_STREAM"] = yaml_stream

.. note:

When using YAML files through the docker containers, always be sure that the NWB file paths are absolute paths stemming from the mounted volume; otherwise, the NWB file will indeed be written inside the container but will not be accessible outside of it.