Skip to content

Commit e350b94

Browse files
committed
deploy: support running sc2 on azure vms
1 parent a30685d commit e350b94

13 files changed

+380
-1
lines changed

ansible/ansible.cfg

Whitespace-only changes.

ansible/inventory/vms.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[all]
2+
sc2-snp-test ansible_host=4.246.173.77 ansible_user=sc2

ansible/tasks/apt.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
# Currently the provisioned VM image for CoCo on Azure VMs uses Ubuntu 20.04
4+
# so we need to add an APT repository to install python3.10
5+
# - name: "Add deadsnakes APT repository"
6+
# become: yes
7+
# apt_repository:
8+
# repo: "ppa:deadsnakes/ppa"
9+
10+
- name: "Install APT depdencencies"
11+
become: yes
12+
apt:
13+
name:
14+
- apt-transport-https
15+
- ca-certificates
16+
- curl
17+
- gnupg2
18+
- software-properties-common
19+
- python3.10-dev
20+
- python3-pip
21+
- python3.10-venv
22+
- unzip
23+
update_cache: yes

ansible/tasks/code.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
3+
- name: "Create code dir"
4+
file:
5+
path: "/home/{{ ansible_user }}/git"
6+
state: directory
7+
8+
- name: "Clone repos"
9+
git:
10+
repo: "https://www.github.com/sc2-sys/{{ item }}.git"
11+
dest: "/home/{{ ansible_user }}/git/sc2-sys/{{ item }}"
12+
depth: 1
13+
update: yes
14+
recursive: no
15+
clone: yes
16+
force: yes
17+
accept_hostkey: yes
18+
with_items:
19+
- "applications"
20+
- "deploy"
21+
- "experiments"
22+

ansible/tasks/docker.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
3+
- name: "Add Docker GPG key"
4+
become: yes
5+
apt_key: url=https://download.docker.com/linux/ubuntu/gpg
6+
7+
- name: "Add Docker APT repository"
8+
become: yes
9+
apt_repository:
10+
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable"
11+
12+
- name: "Install Docker"
13+
become: yes
14+
apt:
15+
name:
16+
- docker-ce
17+
- docker-ce-cli
18+
- containerd.io
19+
- docker-compose-plugin
20+
update_cache: yes
21+
22+
- name: "Add user to docker group"
23+
become: yes
24+
user:
25+
name: "{{ ansible_user }}"
26+
groups: docker
27+
append: yes

ansible/tasks/pull_images.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
3+
- name: "Extract version numbers from versions.py"
4+
shell: |
5+
grep -oP '{{ item.regex }}' "/home/{{ ansible_user }}/git/sc2-sys/deploy/tasks/util/versions.py"
6+
register: versions
7+
loop:
8+
- { name: "containerd", regex: 'CONTAINERD_VERSION\s*=\s*"\K[^"]+' }
9+
- { name: "kata-containers", regex: 'KATA_VERSION\s*=\s*"\K[^"]+' }
10+
- { name: "nydus", regex: 'NYDUS_VERSION\s*=\s*"\K[^"]+' }
11+
- { name: "nydus-snapshotter", regex: 'NYDUS_SNAPSHOTTER_VERSION\s*=\s*"\K[^"]+' }
12+
13+
- name: "Pull Docker images with extracted versions"
14+
shell: "docker pull ghcr.io/sc2-sys/{{ item.item.name }}:{{ item.stdout }}"
15+
loop: "{{ versions.results }}"

ansible/tasks/rust.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
- name: "Install Rust using rustup"
4+
shell: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
5+
args:
6+
creates: ~/.cargo/bin/rustc
7+
8+
- name: "Add Cargo bin directory to PATH"
9+
lineinfile:
10+
path: ~/.bashrc
11+
line: 'export PATH="$HOME/.cargo/bin:$PATH"'
12+
create: yes
13+
14+
- name: "Reload shell profile"
15+
shell: source ~/.bashrc
16+
args:
17+
executable: /bin/bash

ansible/tasks/update_host_kernel.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
3+
- name: "Download the kernel with Azure's patches"
4+
get_url:
5+
url: "https://github.com/jepio/AMDSEV/releases/download/v2024.02.24/linux-image-6.8.0-rc5-next-20240221-snp-host-2cfe07293708_6.8.0-rc5-g2cfe07293708-2_amd64.deb"
6+
dest: "/tmp/linux-image.deb"
7+
mode: '0644'
8+
9+
# Step 2: Install the .deb kernel package
10+
- name: "Install the new kernel package"
11+
apt:
12+
deb: "/tmp/linux-image.deb"
13+
state: present
14+
15+
# Step 3: Update the grub configuration to use the new kernel
16+
- name: "Update GRUB to use the new kernel"
17+
command: update-grub
18+
19+
# Step 4: Reboot the system to load the new kernel
20+
- name: "Reboot the system to apply the new kernel"
21+
reboot:
22+
reboot_timeout: 600
23+
test_command: uname -r
24+
register: reboot_result
25+
26+
# Step 5: Verify the kernel version after reboot
27+
# TODO: delete me
28+
- name: Check the new kernel version after reboot
29+
debug:
30+
msg: "Using host kernel: {{ reboot_result.stdout }}"
31+
when: reboot_result is succeeded

ansible/vm.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
3+
- hosts: all
4+
gather_facts: yes
5+
tasks:
6+
- include_tasks: tasks/apt.yaml
7+
- include_tasks: tasks/rust.yaml
8+
- include_tasks: tasks/docker.yaml
9+
- include_tasks: tasks/code.yaml
10+
- include_tasks: tasks/pull_images.yaml
11+
- include_tasks: tasks/update_host_kernel.yaml
12+
# - include_tasks: tasks/sc2.yml

bin/create_venv.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ THIS_DIR=$(dirname $(readlink -f $0))
66
PROJ_ROOT=${THIS_DIR}/..
77
VENV_PATH="${PROJ_ROOT}/venv"
88

9+
PYTHON=python3.10
910
PIP=${VENV_PATH}/bin/pip3
1011

1112
function pip_cmd {
@@ -15,7 +16,7 @@ function pip_cmd {
1516
pushd ${PROJ_ROOT} >> /dev/null
1617

1718
if [ ! -d ${VENV_PATH} ]; then
18-
python3 -m venv ${VENV_PATH}
19+
${PYTHON} -m venv ${VENV_PATH}
1920
fi
2021

2122
pip_cmd install -U pip setuptools wheel

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ansible>=8.4.0
2+
azure-cli>=2.68.0
23
black>=23.9.1
34
flake8>=7.1.1
45
invoke>=2.1.0

tasks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from invoke import Collection
22

3+
from . import azure
34
from . import base
45
from . import coco
56
from . import containerd
@@ -27,6 +28,7 @@
2728
from tasks.coconut import ns as coconut_ns
2829

2930
ns = Collection(
31+
azure,
3032
base,
3133
coco,
3234
containerd,

0 commit comments

Comments
 (0)