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

qeapp specific image by running AiiDAlab from docker image #213

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on:

Check warning on line 3 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / pre-commit

3:1 [truthy] truthy value should be one of [false, true]
push:
branches: [main]
tags:
Expand All @@ -17,10 +17,10 @@
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- uses: pre-commit/[email protected]

# docs:

Check warning on line 23 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / pre-commit

23:3 [comments-indentation] comment not indented like content
# runs-on: ubuntu-latest

# steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ submodules/roles/marvel-nccr*
submodules/roles/gantsign*
submodules/roles/geerlingguy*
submodules/ansible_collections/

local/modules/__pycache__/*.pyc
27 changes: 17 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@
# See usage instructions at https://pre-commit.com
repos:

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.3.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, "2", --preserve-quotes]

- repo: https://github.com/adrienverge/yamllint
rev: v1.26.3
rev: v1.33.0
hooks:
- id: yamllint

- repo: https://github.com/ansible/ansible-lint
rev: v6.3.0
rev: v6.22.1
hooks:
- id: ansible-lint
args: [--exclude, roles/]
# these should bring back after fixing the ansible-lint issues
# we exclude most of the roles and tasks, as they are not update to the new ansible version
args: [
--exclude,
roles/,
submodules/roles/,
playbook-aiidalab-qe.yml,
playbook-build.yml,
playbook-package.yml,
.pre-commit-config.yaml,
local/tasks/,
.github/workflows/ci.yml,
submodules/ansible_collections/,
]

- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.11.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Vagrant.configure(2) do |config|
# Disable the default shared folder of vagrant
config.vm.synced_folder ".", "/vagrant", disabled: true

# provisioner: set up VM via ansible. To (re-)run this step:
# provisioner: set up VM with ansible. To (re-)run this step:
# vagrant provision --provision-with ansible
# Note we use a static inventory, see: https://www.vagrantup.com/docs/provisioning/ansible_intro#static-inventory
config.vm.network :private_network, ip: gconfig["ansible_host"]
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

project = "Quantum Mobile"
copyright = "2020, NCCR MARVEL"
author = "Chris Sewell, Giovanni Pizzi, Leopold Talirz"
author = "Jusong Yu, Chris Sewell, Giovanni Pizzi, Leopold Talirz"

version = inventory["all"]["vars"]["vm_version"]
release = version
Expand Down
96 changes: 96 additions & 0 deletions docs/developers/build-apple-silicon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Build for Apple Silicon

Apple Silicon is the new CPU architecture for Apple Macs.
The new architecture is based on ARM64, which means that software compiled for x86_64 will not run on Apple Silicon without translation.
VirtualBox does not yet support Apple Silicon, so instead we use a different virtualization software called [UTM](https://mac.getutm.app/).

## Prerequisites

To build the UTM image, first:

- install the latest version of UTM [from the Apple store](https://apps.apple.com/us/app/utm-virtual-machines/id1538878817).
- download the "64-bit ARM (ARMv8/AArch64) server install image" from https://cdimage.ubuntu.com/releases/focal/release/.


Then, clone the `quantum-mobile` repository:

```console
git clone https://github.com/marvel-nccr/quantum-mobile.git
cd quantum-mobile
```

Create a fresh Python environment with a manager of your choosing and simply install `tox`:

```
pip install tox
```

Finally, we need the `sshpass` tool to have password access to the VM when running the Ansible playbook:

```console
brew install hudochenkov/sshpass/sshpass
```

## Install and start the VM

Create a new virtual machine from the downloaded Ubuntu server ISO using "File -> New".
Select the following:

- Virtualize
- Operating system: Select Custom -> Other, then use "Browse" to find the ISO image and continue.
- select the following hardware/storage settings: 4096MB RAM (default), 4 CPU cores and 64GB disk space (default).

Next, **create** (be careful not delete the existing one, it is used for connecting the internet) a new network setting with type "Emulated VLAN" and forward port 22 to 2200 of localhost so you can ssh to VM from localhost.
Check [here](https://github.com/utmapp/UTM/discussions/2465#discussioncomment-6931047) for detailed instructions.

<img src="images/utm_ports_mapping.png" width="350px">

Finally. run the VM and follow the installation instructions.
In most steps you can take the default option, keeping in mind the following exceptions:

- Remember to install OpenSSH server during setup, so we can ssh to the VM during the Ansible deployment.
- Create system user `max` with password `moritz` and enable auto login.

**Important**: Once the installation is complete, select reboot and then _shut down the VM_.
Rebooting with the ISO image still selected for the CD/DVD input will result in the installation process starting again.
Hence, unselect the image before booting the machine after the installation.

## Configure the VM with Ansible

Set the following SSH configuration in the `~/.ssh/config`:

```
Host qmobile
HostName 127.0.0.1
User max
Port 2200
```

In the localhost (control machine), activate the Python environment and run the Ansible playbook in the root directory of the repository:

```
BUILD_PLAYBOOK=playbook-aiidalab-qe.yml tox -e ansible -- --extra-vars "build_hosts=utm" -kK
```

It will ask for the password of the `max` user, which should be `moritz`.

## Troubleshooting

### Import from UTM copy

- If you see "Failed to access data from shortcut", try the methods from https://github.com/utmapp/UTM/discussions/3774

### Failing to connect via SSH using password

In case you run into the following error:

```
fatal: [utm]: FAILED! =>
msg: to use the 'ssh' connection type with passwords, you must install the sshpass program
```

It means that the `sshpass` tool has not been installed correctly using:

```
brew install hudochenkov/sshpass/sshpass
```
7 changes: 7 additions & 0 deletions docs/developers/build-vagrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ Building the Desktop Edition is tested on GitHub Actions on every commit to the
For the tested steps see the `.github/workflows/build.yml` file.
:::

### Build QeApp dedicated VM

To build a VM dedicated to the QeApp, run:

```bash
BUILD_PLAYBOOK=playbook-aiidalab-qe.yml tox -e vagrant
```

### Continuing a failed build

Expand Down
Binary file added docs/developers/images/utm_ports_mapping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ users/troubleshoot.md
developers/customize.md
developers/build-vagrant.md
developers/build-cloud.md
developers/build-apple-silicon.md
developers/roles.md
```

Expand Down
20 changes: 15 additions & 5 deletions inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ all:
vars:
# VM Metadata
vm_name: "Quantum Mobile"
vm_version: "23.04.03"
vm_version: "23.10.0"
vm_description: "A Virtual Machine for Computational Materials Science"
vm_url: "https://github.com/marvel-nccr/marvel-virtualmachine"
vm_author: "MARVEL NCCR and MaX CoE"
Expand All @@ -22,11 +22,12 @@ all:
vm_hostname: "qmobile"
vm_user: "max"
vm_password: "moritz"
vm_memory: 1536
vm_cpus: 2
vm_vram: 128
vm_memory: 4096
vm_cpus: 4
vm_vram: 256
vm_headless: false
vm_browser: chromium-browser # 'chromium-browser' or 'firefox'
vm_browser: firefox # 'chromium-browser' or 'firefox'
vm_wm_package: ubuntu-desktop-minimal # 'lxde' or 'ubuntu-desktop-minimal'
vm_data_folder: "/usr/local/share" # this is used to put shared data files in
# vm_shared_folder: "/shared" # this is currently inactive in Vagrant config
vm_timezone: "Europe/Zurich"
Expand All @@ -39,6 +40,9 @@ all:
build_dir: "/tmp"
run_tests: true

# AiiDAlab options
vm_qeapp_image: "ghcr.io/aiidalab/qe:v23.10.0"

# Readme and Release Notes (populated by roles during build)
qm_homepage: "https://quantum-mobile.readthedocs.io"
readme_vm_path: "/home/{{ vm_user }}/README.md"
Expand Down Expand Up @@ -108,3 +112,9 @@ all:
ansible_user: max
vm_headless: true
# add_user_public_key: "{{ lookup('file', './keys/user-key.pub') }}"
utm:
cloud_platform: utm
ansible_host: 127.0.0.1
ansible_port: 2200
ansible_user: max
vm_headless: false
2 changes: 1 addition & 1 deletion local/tasks/aiida-jupyter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- name: create desktop shortcut to Jupyter Lab
copy:
dest: "${HOME}/Desktop/jupyterlab.desktop"
mode: "0753"
mode: "0644"
content: |
[Desktop Entry]
Encoding=UTF-8
Expand Down
47 changes: 47 additions & 0 deletions local/tasks/aiidalab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
- name: Create folder for AiiDAlab QE
become: true
become_user: "{{ vm_user }}"
file:
path: /home/{{ vm_user }}/qeapp-home
state: directory
mode: 0775

- name: check if qeapp container is running
become: true
become_user: "{{ vm_user }}"
shell: "docker inspect -f '{{ '{{' }} .State.Running {{ '}}' }}' qeapp"
register: qe_container_stat
ignore_errors: true

- name: Pull qeapp image
command: "docker pull {{ qeapp_image }}"

- name: echo qe_container
debug:
var: qe_container

- name: Create and run qeapp container
become: true
become_user: "{{ vm_user }}"
command: "docker run -d --name qeapp -p 8899:8888 --volume /home/{{ vm_user }}/qeapp-home:/home/jovyan -e JUPYTER_TOKEN='max' -e NB_UMASK=002 --restart always {{ qeapp_image }}"
when: qe_container_stat.stdout == ""

- name: Copy AiiDAlab logo
become: true
become_user: "{{ root_user }}"
copy:
src: images/aiidalab-qe-logo.png
dest: /usr/share/icons/

- name: create desktop shortcut to AiiDALab
copy:
dest: "${HOME}/Desktop/aiidalab.desktop"
mode: "0644"
content: |
[Desktop Entry]
Name=AiiDAlab QE
Comment=Launch AiiDAlab QE
Exec={{ vm_browser }} "http://localhost:8899/apps/apps/quantum-espresso/qe.ipynb?token=max"
Terminal=false
Icon=/usr/share/icons/aiidalab-qe-logo.png
Type=Application
8 changes: 8 additions & 0 deletions local/tasks/customise-bash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
- regexp: HISTFILESIZE=
line: HISTFILESIZE=100000

- name: Set umask to 002
blockinfile:
path: "${HOME}/.bashrc"
marker: "# {mark} ANSIBLE MANAGED BLOCK (umask)"
block: |
# Set umask to 002
umask 002

- name: hide possible sudo message
file:
path: ~/.sudo_as_admin_successful
Expand Down
4 changes: 2 additions & 2 deletions local/tasks/customise-gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
become: true
become_user: "{{ root_user }}"
copy:
src: images/quantum-mobile-bg.png
src: "images/{{ bg_image | default('quantum-mobile-bg.png')}}"
dest: "{{ vm_data_folder }}/qm-customizations/quantum-mobile-bg.png"
mode: 0755

Expand Down Expand Up @@ -55,7 +55,7 @@
- name: create desktop shortcut to QM homepage
copy:
dest: "${HOME}/Desktop/homepage.desktop"
mode: "0753"
mode: "0644"
content: |
[Desktop Entry]
Encoding=UTF-8
Expand Down
13 changes: 13 additions & 0 deletions local/tasks/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: Install docker
include_role:
name: geerlingguy.docker
vars:
docker_users:
- "{{ vm_user }}"

Check failure on line 6 in local/tasks/docker.yml

View workflow job for this annotation

GitHub Actions / pre-commit

6:7 [indentation] wrong indentation: expected 4 but found 6

- name: Install docker pip
include_role:
name: geerlingguy.pip
vars:
pip_install_packages:
- docker
23 changes: 23 additions & 0 deletions local/tasks/files/README-qeapp.md.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Welcome to {{ vm_name }} version {{ vm_version }}

*Quantum Mobile* is a Virtual Machine for computational materials science, distributed by the {{ vm_author }}.

It comes with a collection of software packages for quantum mechanical calculations, including:

{% for name, url in software_urls.items() %}
* [{{ name }}]({{ url }})
{% endfor %}

all of which are set up and ready to be used on their own or through [AiiDA](http://www.aiida.net).

# Getting started

* Start the Quantum ESPRESSO app by double-clicking on the icon on the desktop.

* If the virtual machine is just started, you may need to wait a few minutes for the server to be fully ready. If you see an error message, try again after a few minutes.

* The data you create over the app can be accessed from the `~/qeapp-home` folder. Vise versa, you can copy files into this folder to make them available in the app.

* For more information on how to use the app, see the [Quantum ESPRESSO app documentation](https://aiidalab-quantumespresso.readthedocs.io/en/latest/).

For troubleshooting and other information, see: {{ qm_homepage }}.
Binary file added local/tasks/images/aiidalab-qe-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified local/tasks/images/quantum-mobile-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading