feat: setup Podman as Docker replacement

This commit is contained in:
Peter 2023-06-14 08:32:05 +02:00
parent 21ffbe33e7
commit 1fcab667ed
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
2 changed files with 93 additions and 8 deletions

View file

@ -7,24 +7,46 @@ users:
packages: packages:
- zsh - zsh
- git - git
- git-delta
- difftastic
- curl - curl
- jq - jq
- htop
- exa
- ripgrep
- bat
- fzf
- dnf-plugins-core
%{ if install_podman_setup ~}
- podman - podman
- podman-docker
- docker-compose
%{ endif ~}
%{ if install_go_setup ~}
- golang - golang
%{ endif ~}
%{ if install_dotnet_setup ~}
- dotnet-sdk-6.0 - dotnet-sdk-6.0
- dotnet-sdk-7.0 - dotnet-sdk-7.0
%{ endif ~}
mounts: mounts:
- [ - [
"${volume_path}", "${volume_path}",
"/home/${username}", "/home/${username}",
ext4, ext4,
"discard,defaults", "mode=0755,uid=1000,discard,rw,suid,exec,auto,async",
] ]
write_files: write_files:
- path: /opt/coder/init - path: /opt/coder/init
permissions: "0755" permissions: "0755"
encoding: b64 encoding: b64
content: ${init_script} 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 - path: /etc/systemd/system/coder-agent.service
permissions: "0644" permissions: "0644"
content: | content: |
@ -56,9 +78,16 @@ write_files:
cert: false cert: false
%{ endif ~} %{ endif ~}
runcmd: runcmd:
- chown ${username}:${username} /home/${username} - chown -R ${username}:${username} /home/${username}
- systemctl enable coder-agent - systemctl enable coder-agent
- systemctl start 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 ~} %{ 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") - 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} - systemctl enable --now code-server@${username}

68
main.tf
View file

@ -71,7 +71,7 @@ data "coder_parameter" "instance_type" {
display_name = "Instance type" display_name = "Instance type"
default = "cpx11" default = "cpx11"
type = "string" type = "string"
mutable = false mutable = true
option { option {
name = "cx11" name = "cx11"
@ -162,6 +162,7 @@ data "coder_parameter" "code_server" {
description = "Should Code Server be installed?" description = "Should Code Server be installed?"
default = "true" default = "true"
type = "string" type = "string"
mutable = true
option { option {
name = "Install" 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" { data "coder_workspace" "me" {
} }
@ -212,11 +265,14 @@ resource "hcloud_server" "root" {
ssh_keys = [hcloud_ssh_key.root.id] ssh_keys = [hcloud_ssh_key.root.id]
user_data = templatefile("cloud-config.yaml.tftpl", { user_data = templatefile("cloud-config.yaml.tftpl", {
username = data.coder_workspace.me.owner username = data.coder_workspace.me.owner
volume_path = "/dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id}" volume_path = "/dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id}"
init_script = base64encode(coder_agent.dev.init_script) init_script = base64encode(coder_agent.dev.init_script)
coder_agent_token = coder_agent.dev.token coder_agent_token = coder_agent.dev.token
code_server_setup = data.coder_parameter.code_server.value 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" { dynamic "network" {