Skip to content

Commit

Permalink
Add Dockerfile and instructions for vscode and google cloud (#58)
Browse files Browse the repository at this point in the history
* add dockerfile

* push ci file

* fix dockerfile

* modify dockerfile

* push image to registery

* fix syntax error

* missing parenthesis

* trigger pipeline

* syntax error

* trigger pipeline

* fix tag

* syntax error

* use PR id number instead

* fix registry name

* visual studio config.

* - add workaround for qiskit version number
- create folder for mne_data
- update README

* comment docker login and docker push

* edit readme

* test modification of example to see if google cloud run it.

* add home/mne_data for google cloud

* Revert "test modification of example to see if google cloud run it."

This reverts commit 0eae2bf.

* Update README.md

* Revert "Revert "test modification of example to see if google cloud run it.""

This reverts commit 64c1e3a.

* made another test with the example

* Revert "Revert "Revert "test modification of example to see if google cloud run it."""

This reverts commit a970391.

* reset modification to example

* Update README.md

Co-authored-by: gcattan <gregoire.cattan@ibm.com>
  • Loading branch information
gcattan and gcattan authored Jul 18, 2022
1 parent 9aab53f commit e24bb6f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.0/containers/docker-existing-dockerfile
{
"name": "Existing Dockerfile",

"context": "..",

"dockerFile": "../Dockerfile",

"settings": {},

"extensions": [
],

"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
]
}
22 changes: 22 additions & 0 deletions .github/workflows/create_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest
env:
tag: ${{ github.event.pull_request.number }}
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag ghcr.io/${{ github.actor }}/pyriemann-qiskit:$tag
# docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
# docker push ghcr.io/${{ github.actor }}/pyriemann-qiskit:$tag
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.8-slim-buster
ADD pyriemann_qiskit /pyriemann_qiskit
ADD examples /examples
ADD setup.py /
ADD README.md /

RUN apt-get update
RUN apt-get -y install git

RUN apt-get --allow-releaseinfo-change update
RUN python -m pip install --upgrade pip
RUN apt-get -y install --fix-missing git-core
RUN apt-get -y install build-essential

RUN python setup.py develop
RUN pip install .[docs]

# WORKAROUNDS
## Qiskit problem in parsing version number
RUN echo 0.21.0 > /usr/local/lib/python3.8/site-packages/qiskit_terra-0.21.0rc1-py3.8-linux-x86_64.egg/qiskit/VERSION.txt
## Creating folders for mne data
RUN mkdir /root/mne_data
RUN mkdir /home/mne_data

ENTRYPOINT [ "python", "/examples/ERP/classify_P300_bi.py" ]
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ Then you can run the python example of your choice like:
python examples\ERP\classify_P300_bi.py
```

### Installation with docker

We also offer the possibility to set up the dev environment within docker.
To this end, we recommand to use `vscode` with the `Remote Containers` extension
from Microsoft.

Once the installation is successful, just open the project in `vscode` and enter `F1`.
In the search bar that opens, type `Rebuild and Reopen Container`.

Wait for the container to build, and open a python shell within the container.
Then ensure everything went smoothly by typing:

```
import pyriemann_qiskit
```

## Contributor Guidelines

Everyone is welcomed to contribute to this repository. There are two types of contributions:
Expand Down Expand Up @@ -138,8 +154,43 @@ Code contribution (pull request) can be either on core functionalities, document
Workflows are automatically triggered when you push a commit. However, the worflow for example execution is only triggered when you modify one of the examples or the documentation as the execution take a lot of time. You can enable [Github Actions](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository) in your fork to see the result of the CI pipeline. Results are also indicated at the end of your pull request when raised. However note, that workflows in the pull request need approval from the maintainers before being executed.
### Deploy an example on the cloud
When creating an example, your local computer may be limited in terms of ressources to emulate a quantum computer.
Instead, you might want to use a cloud provider to run the example.
Here we will provide the steps with the Google Cloud Plateform (other cloud providers offer similar functionnalities):
1. Create a new branch with you example in your fork repository. Modify the `/Dockerfile` to redirect the `entrypoint` to your example.
Make sure that the `create_docker_image` workflow passed.
2. Open an account on Google Cloud (it required a billing account, but you will not be charged until you upgrade your account).
3. Create a [Cloud Run Service](https://console.cloud.google.com/run/create?project=pyriemann-qiskit) called `pyriemmann-qiskit` (or any project name which is suitable for you).
For the moment use the default configuration, although you may want to already indicate the physical ressources:
![image](https://user-images.githubusercontent.com/6229031/176449146-d3c3da37-0382-46e6-a20b-1b963ce6c12a.png)
4. Create an [artifactory repository](https://console.cloud.google.com/artifacts/create-repo?project=pyriemann-qiskit), following
the `Create a Docker repository in Artifactory` tutorial. Tutorials are displayed in the right side panel of the plateform.
Make sure to indicate `pyriemann-qiskit` as a project (or the one you created instead).
5. Create a new [Cloud Build Trigger](https://console.cloud.google.com/cloud-build/triggers?project=pyriemann-qiskit). Provide the required permissions to install the `Google Build app` on Github. This will allow Google Cloud to build a container image directly from your fork repository. The process is automated and you only need to follow the steps. For more details click [here](https://cloud.google.com/build/docs/automating-builds/build-repos-from-github).
6. Under `Configuration>Type`, select `Dockerfile`.
7. Under `Configuration>Location`, select `Repository` and type `Dockerfile` in the input box `Dockerfile name`.
8. Under `Configuration>Location` provide a value for the image name.
It should be in the form: `<XXX>-docker.pkg.dev/<name of your cloud run service>/<name of your docker repo>/<custom image name>:$COMMIT_SHA`.
You can copy the first part of this URL (except the image name) from your artifactory settings:
![image](https://user-images.githubusercontent.com/6229031/176449496-daf5f263-3bb9-4eb9-aad3-7bcf289b8f59.png)
9. Validate the trigger, and run it. Check everything passed.
10. Edit the service you created in step `3`, and select a `Container Image URL`. If everything went well,
a new image should have been pushed in your artifact repository. It is also possible to specify a different entrypoint that the one provided in setp `1`
![image](https://user-images.githubusercontent.com/6229031/176448796-8d2472c5-5662-4b69-8d47-c31ebbe9a7e5.png)
11. Validate the service and click on the `Logs` tab to see the output.
# Troubleshooting
## Version of pyRiemann not updated
There is a known issue when you install `pyRiemann-qiskit` in an environement where there is already `pyRiemann` installed. In such case, the `pyRiemann` version is not updated. Therefore before installing or updating `pyRiemann-qiskit`, we recommend to install `pyRiemann` as it follows:
```
Expand Down

0 comments on commit e24bb6f

Please sign in to comment.