#cloud-config

# Tested on:
# - RHEL 8.6
#
# Sources:
# - https://github.com/trajano/terraform-docker-swarm-aws/blob/master/common.cloud-config

# Add the official Docker repository.
#
# Got from the official installation guide at
# https://docs.docker.com/engine/install/
#
# Sources:
# - https://cloudinit.readthedocs.io/en/latest/topics/modules.html#yum-add-repo
# - https://cloudinit.readthedocs.io/en/latest/topics/examples.html#adding-a-yum-repository
yum_repos:
  docker-ce-stable:
    name: Docker CE Stable - $basearch
    enabled: true
    baseurl: https://download.docker.com/linux/centos/$releasever/$basearch/stable
    priority: 1
    gpgcheck: true
    gpgkey: https://download.docker.com/linux/centos/gpg

# Install required packages.
# This will *always* update the list of packages, regardless of the value of the
# 'package_update' setting.
#
# docker-ce already depends on 'docker-ce-cli' and 'containerd.io'
#
# Sources:
# - https://cloudinit.readthedocs.io/en/latest/topics/modules.html#package-update-upgrade-install
# - https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages
packages:
  - docker-ce
  - docker-compose-plugin

runcmd:
  # Enable and start the service after installation.
  - systemctl daemon-reload
  - systemctl enable --now docker.service

  # Give the default user permission to use docker without privilege escalation.
  - grep docker /etc/group -q && sudo usermod -a -G docker user
