From 1fcab667ed04504ab210623d534aaaec0c0f6765 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Wed, 14 Jun 2023 08:32:05 +0200 Subject: [PATCH] feat: setup Podman as Docker replacement --- cloud-config.yaml.tftpl | 33 ++++++++++++++++++-- main.tf | 68 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 93 insertions(+), 8 deletions(-) diff --git a/cloud-config.yaml.tftpl b/cloud-config.yaml.tftpl index 83bff2d..f178194 100644 --- a/cloud-config.yaml.tftpl +++ b/cloud-config.yaml.tftpl @@ -7,24 +7,46 @@ users: packages: - zsh - git + - git-delta + - difftastic - curl - jq + - htop + - exa + - ripgrep + - bat + - fzf + - dnf-plugins-core +%{ if install_podman_setup ~} - podman + - podman-docker + - docker-compose +%{ endif ~} +%{ if install_go_setup ~} - golang +%{ endif ~} +%{ if install_dotnet_setup ~} - dotnet-sdk-6.0 - dotnet-sdk-7.0 +%{ endif ~} mounts: - [ "${volume_path}", "/home/${username}", ext4, - "discard,defaults", + "mode=0755,uid=1000,discard,rw,suid,exec,auto,async", ] write_files: - path: /opt/coder/init permissions: "0755" encoding: b64 content: ${init_script} +%{ if install_podman_setup ~} + - path: /etc/profile.d/podman.sh + permissions: "0644" + content: | + export DOCKER_HOST=unix:///run/user/$UID/podman/podman.sock +%{ endif ~} - path: /etc/systemd/system/coder-agent.service permissions: "0644" content: | @@ -56,9 +78,16 @@ write_files: cert: false %{ endif ~} runcmd: - - chown ${username}:${username} /home/${username} + - chown -R ${username}:${username} /home/${username} - systemctl enable coder-agent - systemctl start coder-agent +%{ if install_dotnet_setup ~} + - loginctl enable-linger ${username} + - mkdir -p /home/${username}/.config/systemd/user/sockets.target.wants + - chown -R ${username}:${username} /home/${username} + - ln -sf /usr/lib/systemd/system/podman.socket /home/${username}/.config/systemd/user/sockets.target.wants/ + - sudo -u ${username} DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" systemctl --user start podman +%{ endif ~} %{ if code_server_setup ~} - dnf install -y $(curl -sL https://api.github.com/repos/coder/code-server/releases/latest | jq -r '.assets[].browser_download_url' | grep "amd64.rpm") - systemctl enable --now code-server@${username} diff --git a/main.tf b/main.tf index 9c6edf7..d266474 100644 --- a/main.tf +++ b/main.tf @@ -71,7 +71,7 @@ data "coder_parameter" "instance_type" { display_name = "Instance type" default = "cpx11" type = "string" - mutable = false + mutable = true option { name = "cx11" @@ -162,6 +162,7 @@ data "coder_parameter" "code_server" { description = "Should Code Server be installed?" default = "true" type = "string" + mutable = true option { name = "Install" @@ -174,6 +175,58 @@ data "coder_parameter" "code_server" { } } +data "coder_parameter" "install_go" { + name = "install_go" + description = "Should Go SDK be installed?" + default = "true" + type = "string" + mutable = true + option { + name = "Install" + value = "true" + } + + option { + name = "Don't install" + value = "false" + } +} + +data "coder_parameter" "install_dotnet" { + name = "install_dotnet" + description = "Should .NET SDK be installed?" + default = "true" + type = "string" + mutable = true + + option { + name = "Install" + value = "true" + } + + option { + name = "Don't install" + value = "false" + } +} + +data "coder_parameter" "install_podman" { + name = "install_podman" + description = "Should Podman be installed?" + default = "true" + type = "string" + mutable = true + option { + name = "Install" + value = "true" + } + + option { + name = "Don't install" + value = "false" + } +} + data "coder_workspace" "me" { } @@ -212,11 +265,14 @@ resource "hcloud_server" "root" { ssh_keys = [hcloud_ssh_key.root.id] user_data = templatefile("cloud-config.yaml.tftpl", { - username = data.coder_workspace.me.owner - volume_path = "/dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id}" - init_script = base64encode(coder_agent.dev.init_script) - coder_agent_token = coder_agent.dev.token - code_server_setup = data.coder_parameter.code_server.value + username = data.coder_workspace.me.owner + volume_path = "/dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id}" + init_script = base64encode(coder_agent.dev.init_script) + coder_agent_token = coder_agent.dev.token + code_server_setup = data.coder_parameter.code_server.value + install_go_setup = data.coder_parameter.install_go.value + install_dotnet_setup = data.coder_parameter.install_dotnet.value + install_podman_setup = data.coder_parameter.install_podman.value }) dynamic "network" {