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

General image build #220

Open
wants to merge 25 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
9 changes: 4 additions & 5 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
warn_list: # or 'skip_list' to silence them completely
- '208' # File permissions unset or incorrect
- '301' # Commands should not change things if nothing needs doing
- '305' # Use shell only when shell functionality is required
- '504' # Do not use 'local_action', use 'delegate_to: localhost'
- syntax-check
- '208' # File permissions unset or incorrect
- '301' # Commands should not change things if nothing needs doing
- '305' # Use shell only when shell functionality is required
- '504' # Do not use 'local_action', use 'delegate_to: localhost'
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- uses: pre-commit/action@v3.0.0

# docs:
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
46 changes: 46 additions & 0 deletions docs/developers/build-apple-silicon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.
The VirtualBox software is not yet available for Apple Silicon, so we need to use a different virtualization software which is the [UTM](https://mac.getutm.app/).

## Install and start the VM
- Download latest version of UTM
- browse gallery to have a image setup, we select ubuntu 20.04 LTS https://docs.getutm.app/guides/ubuntu/
- The arm64 ISO image can be dowloaded from https://cdimage.ubuntu.com/releases/focal/release/
- During import and setup from ISO, select settings with: 64GB disk space (default), 4096MB RAM (default), 4 (works for 2020 macbook air so should be good for other later model) cores.
- Remember to install OpenSSH server during setup, so we can ssh to the VM for ansible deployment. Check [here](https://github.com/utmapp/UTM/discussions/2465#discussioncomment-6931047) for a detail setup so host can ssh to the virtual machine.
- Create system user `max` with password `moritz` and enable auto login. This will be used for ansible deployment.
- 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.

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

You can config ssh with setting in `~/.ssh/config`:

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

- The default `max` user is granted with the sudo permission and the password is `moritz`.
- To reboot, remember to unmount the image and boot again.

## Configure the VM

In the localhost (control machine), prepare the python environment and tox.
Check the [prerequisites section](../build-vagrant.md#prerequisites-installation) for detailes

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

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

## troubleshotings

### import from utm copy

- If you see "Failed to access data from shortcut", try the methods from https://github.com/utmapp/UTM/discussions/3774
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: "24.04.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 }}"

- 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