Skip to content

Commit

Permalink
refactor(ansible/docker): split docker roles (#241)
Browse files Browse the repository at this point in the history
* refactor(ansible/docker): split docker roles

Signed-off-by: Kenji Miyake <[email protected]>

* update README

* fix name

* fix README
  • Loading branch information
kenji-miyake authored Apr 27, 2022
1 parent b892bea commit 2b1d5ea
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 204 deletions.
1 change: 0 additions & 1 deletion ansible/playbooks/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
- rmw_implementation: "{{ rmw_implementation }}"
roles:
- role: autoware.dev_env.autoware_core
- role: autoware.dev_env.docker
- role: autoware.dev_env.pre_commit
- role: autoware.dev_env.ros2
- role: autoware.dev_env.ros2_dev_tools
Expand Down
5 changes: 4 additions & 1 deletion ansible/playbooks/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
- hosts: localhost
connection: local
roles:
- role: autoware.dev_env.docker
- role: autoware.dev_env.docker_compose
- role: autoware.dev_env.docker_engine
- role: autoware.dev_env.nvidia_docker
- role: autoware.dev_env.rocker
1 change: 0 additions & 1 deletion ansible/playbooks/universe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
roles:
# Core
- role: autoware.dev_env.autoware_core
- role: autoware.dev_env.docker
- role: autoware.dev_env.pre_commit
- role: autoware.dev_env.ros2
- role: autoware.dev_env.ros2_dev_tools
Expand Down
140 changes: 0 additions & 140 deletions ansible/roles/docker/README.md

This file was deleted.

34 changes: 34 additions & 0 deletions ansible/roles/docker_compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# docker_compose

This role installs Docker environment following [this page](https://docs.docker.com/engine/install/ubuntu/) and sets up rootless execution following [this page](https://docs.docker.com/engine/install/linux-postinstall/).

Also, it installs some additional tools:

- [Docker Compose](https://github.com/docker/compose) following the [installation guide](https://github.com/docker/compose#linux).

## Inputs

| Name | Required | Description |
| ---------------------- | -------- | ------------------------------ |
| docker_compose_version | false | The version of Docker Compose. |

## Manual Installation

Install Docker Compose:

The `docker_compose_version` can also be found in:
[./defaults/main.yaml](./defaults/main.yaml)

```bash
# Modified from: https://docs.docker.com/compose/cli-command/#install-on-linux

# Run this command to download the Docker Compose:
docker_compose_version=v2.2.2
sudo curl -SL https://github.com/docker/compose/releases/download/${docker_compose_version}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

# Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose

# Test the installation.
docker-compose --version
```
File renamed without changes.
Empty file.
7 changes: 7 additions & 0 deletions ansible/roles/docker_compose/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Install Docker Compose
become: true
ansible.builtin.get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-{{ ansible_system }}-{{ ansible_architecture }}
dest: /usr/local/bin/docker-compose
force: true
mode: 0775
57 changes: 57 additions & 0 deletions ansible/roles/docker_engine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# docker_engine

This role installs [Docker Engine](https://docs.docker.com/engine/) following the [installation guide](https://docs.docker.com/engine/install/ubuntu/) and sets up execution from non-root users following the [manual](https://docs.docker.com/engine/install/linux-postinstall/).

## Inputs

None.

## Manual Installation

Install Docker Engine:

```bash
# Taken from: https://docs.docker.com/engine/install/ubuntu/
# And: https://docs.docker.com/engine/install/linux-postinstall/

# Uninstall old versions
sudo apt-get remove docker docker-engine docker.io containerd runc

# Install using the repository
sudo apt-get update

sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

# Verify that Docker Engine is installed correctly by running the hello-world image.
sudo docker run hello-world
# Note: This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.
```

Perform the post-installation steps:

```bash
# Post-installation steps for Linux

# Create the docker group.
sudo groupadd docker

# Add your user to the docker group.
sudo usermod -aG docker $USER

# Log out and log back in so that your group membership is re-evaluated.

# Verify that you can run docker commands without sudo
docker run hello-world
# Note: This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.
```
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -74,63 +74,3 @@
name: "{{ ansible_user_id }}"
groups: docker
append: true

- name: Authorize NVIDIA Docker GPG key
become: true
ansible.builtin.apt_key:
url: https://nvidia.github.io/nvidia-docker/gpgkey

- name: Save result of '. /etc/os-release;echo $ID$VERSION_ID'
ansible.builtin.shell: . /etc/os-release;echo $ID$VERSION_ID
register: distribution
changed_when: false

- name: Save result of 'curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list'
ansible.builtin.uri:
url: https://nvidia.github.io/nvidia-docker/{{ distribution.stdout }}/nvidia-docker.list
return_content: true
register: nvidia_docker_list

# curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
- name: Add NVIDIA Docker apt repository to source list
become: true
ansible.builtin.copy:
dest: /etc/apt/sources.list.d/nvidia-docker.list
content: "{{ nvidia_docker_list.content }}"
mode: 0644

- name: Install NVIDIA Container Toolkit
become: true
ansible.builtin.apt:
name:
- nvidia-docker2
update_cache: true

- name: Install Docker Compose
become: true
ansible.builtin.get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-{{ ansible_system }}-{{ ansible_architecture }}
dest: /usr/local/bin/docker-compose
force: true
mode: 0775

- name: Authorize OSRF GPG key
become: true
ansible.builtin.apt_key:
url: https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc

# echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros-latest.list > /dev/null
- name: Add OSRF apt repository to source list
become: true
ansible.builtin.apt_repository:
repo: deb http://packages.ros.org/ros/ubuntu {{ lsb_release_cs.stdout }} main
filename: ros-latest
state: present
update_cache: true

- name: Install rocker
become: true
ansible.builtin.apt:
name:
- python3-rocker
update_cache: true
53 changes: 53 additions & 0 deletions ansible/roles/nvidia_docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# nvidia_docker

This role installs [NVIDIA Container Toolkit](https://github.com/NVIDIA/nvidia-docker) following the [installation guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker).

## Inputs

None.

## Manual Installation

Install Nvidia Container Toolkit:

<!-- cspell:ignore Disp, Uncorr -->

```bash
# Taken from https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit

# Setup the package repository and the GPG key:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | sudo apt-key add - \
&& curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

# Install the nvidia-docker2 package (and dependencies) after updating the package listing:
sudo apt-get update
sudo apt-get install -y nvidia-docker2

# Restart the Docker daemon to complete the installation after setting the default runtime:
sudo systemctl restart docker

# At this point, a working setup can be tested by running a base CUDA container:
sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

# This should result in a console output shown below:
# +-----------------------------------------------------------------------------+
# | NVIDIA-SMI 450.51.06 Driver Version: 450.51.06 CUDA Version: 11.0 |
# |-------------------------------+----------------------+----------------------+
# | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
# | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
# | | | MIG M. |
# |===============================+======================+======================|
# | 0 Tesla T4 On | 00000000:00:1E.0 Off | 0 |
# | N/A 34C P8 9W / 70W | 0MiB / 15109MiB | 0% Default |
# | | | N/A |
# +-------------------------------+----------------------+----------------------+
#
# +-----------------------------------------------------------------------------+
# | Processes: |
# | GPU GI CI PID Type Process name GPU Memory |
# | ID ID Usage |
# |=============================================================================|
# | No running processes found |
# +-----------------------------------------------------------------------------+
```
Empty file.
Empty file.
Loading

0 comments on commit 2b1d5ea

Please sign in to comment.