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:
- 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}

58
main.tf
View file

@ -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" {
}
@ -217,6 +270,9 @@ resource "hcloud_server" "root" {
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" {