#!/bin/bash
# Update packages
apt-get update -y
apt-get install -y apt-transport-https ca-certificates curl software-properties-common

# Install Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
usermod -aG docker ubuntu

# Possible NVIDIA Docker installation
{{ nvidia_docker_install }}

# Sleep after possible multiple docker restarts
sleep 5

# Pull and run the Docker image
docker pull {{ docker_image }}
docker run \
    -d {{ gpu_attach }} \
    -p {{ api_port }}:{{ api_port }} \
    {{ docker_image }}