From a565cf1effae1ff8c91872955e1c706067c0cdef Mon Sep 17 00:00:00 2001 From: LamGC Date: Mon, 30 Oct 2023 22:06:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=9B=E4=B8=AA=E6=94=B9?= =?UTF-8?q?=E5=A5=BD=E7=9A=84=E6=A8=A1=E6=9D=BF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-golang/build/Dockerfile | 23 +++ docker-golang/main.tf | 218 ++++++++++++++++++++++++++++ docker-nodejs/build/Dockerfile | 25 ++++ docker-nodejs/main.tf | 218 ++++++++++++++++++++++++++++ docker-ubuntu-base/build/Dockerfile | 18 +++ docker-ubuntu-base/main.tf | 218 ++++++++++++++++++++++++++++ docker-ubuntu-rust/build/Dockerfile | 18 +++ docker-ubuntu-rust/main.tf | 218 ++++++++++++++++++++++++++++ 8 files changed, 956 insertions(+) create mode 100644 docker-golang/build/Dockerfile create mode 100644 docker-golang/main.tf create mode 100644 docker-nodejs/build/Dockerfile create mode 100644 docker-nodejs/main.tf create mode 100644 docker-ubuntu-base/build/Dockerfile create mode 100644 docker-ubuntu-base/main.tf create mode 100644 docker-ubuntu-rust/build/Dockerfile create mode 100644 docker-ubuntu-rust/main.tf diff --git a/docker-golang/build/Dockerfile b/docker-golang/build/Dockerfile new file mode 100644 index 0000000..8109d69 --- /dev/null +++ b/docker-golang/build/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu + +RUN apt-get update \ + && apt-get install -y \ + curl \ + git \ + golang \ + sudo \ + vim \ + wget \ + && rm -rf /var/lib/apt/lists/* + +RUN wget https://go.dev/dl/go1.21.3.linux-amd64.tar.gz \ + && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz + +ENV PATH="/usr/local/go/bin:${PATH}" + +ARG USER=coder +RUN useradd --groups sudo --shell /bin/bash ${USER} \ + && echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \ + && chmod 0440 /etc/sudoers.d/${USER} +USER ${USER} +WORKDIR /home/${USER} diff --git a/docker-golang/main.tf b/docker-golang/main.tf new file mode 100644 index 0000000..0b047b2 --- /dev/null +++ b/docker-golang/main.tf @@ -0,0 +1,218 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + docker = { + source = "kreuzwerker/docker" + } + } +} + +locals { + username = data.coder_workspace.me.owner +} + +data "coder_provisioner" "me" { +} + +provider "docker" { +} + +data "coder_workspace" "me" { +} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + startup_script_timeout = 180 + startup_script = <<-EOT + set -e + + mkdir -p ~/workspace + + # install and start code-server + curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0 + /tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 & + + if [[ -f ~/.startup.sh ]]; then + echo "Executing startup script..." + ~/.startup.sh || echo "Startup script failure!" + else + echo "Startup script not found, skipped." + fi + + EOT + + # These environment variables allow you to make Git commits right away after creating a + # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! + # You can remove this block if you'd prefer to configure Git manually or using + # dotfiles. (see docs/dotfiles.md) + env = { + GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" + GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" + GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" + GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" + } + + # The following metadata blocks are optional. They are used to display + # information about your workspace in the dashboard. You can remove them + # if you don't want to display any information. + # For basic resources, you can use the `coder stat` command. + # If you need more control, you can write your own script. + metadata { + display_name = "CPU Usage" + key = "0_cpu_usage" + script = "coder stat cpu" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "RAM Usage" + key = "1_ram_usage" + script = "coder stat mem" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Home Disk" + key = "3_home_disk" + script = "coder stat disk --path $${HOME}" + interval = 60 + timeout = 1 + } + + metadata { + display_name = "CPU Usage (Host)" + key = "4_cpu_usage_host" + script = "coder stat cpu --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Memory Usage (Host)" + key = "5_mem_usage_host" + script = "coder stat mem --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Load Average (Host)" + key = "6_load_host" + # get load avg scaled by number of cores + script = </etc/sudoers.d/${USER} \ + && chmod 0440 /etc/sudoers.d/${USER} +USER ${USER} +WORKDIR /home/${USER} diff --git a/docker-nodejs/main.tf b/docker-nodejs/main.tf new file mode 100644 index 0000000..0b047b2 --- /dev/null +++ b/docker-nodejs/main.tf @@ -0,0 +1,218 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + docker = { + source = "kreuzwerker/docker" + } + } +} + +locals { + username = data.coder_workspace.me.owner +} + +data "coder_provisioner" "me" { +} + +provider "docker" { +} + +data "coder_workspace" "me" { +} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + startup_script_timeout = 180 + startup_script = <<-EOT + set -e + + mkdir -p ~/workspace + + # install and start code-server + curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0 + /tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 & + + if [[ -f ~/.startup.sh ]]; then + echo "Executing startup script..." + ~/.startup.sh || echo "Startup script failure!" + else + echo "Startup script not found, skipped." + fi + + EOT + + # These environment variables allow you to make Git commits right away after creating a + # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! + # You can remove this block if you'd prefer to configure Git manually or using + # dotfiles. (see docs/dotfiles.md) + env = { + GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" + GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" + GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" + GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" + } + + # The following metadata blocks are optional. They are used to display + # information about your workspace in the dashboard. You can remove them + # if you don't want to display any information. + # For basic resources, you can use the `coder stat` command. + # If you need more control, you can write your own script. + metadata { + display_name = "CPU Usage" + key = "0_cpu_usage" + script = "coder stat cpu" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "RAM Usage" + key = "1_ram_usage" + script = "coder stat mem" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Home Disk" + key = "3_home_disk" + script = "coder stat disk --path $${HOME}" + interval = 60 + timeout = 1 + } + + metadata { + display_name = "CPU Usage (Host)" + key = "4_cpu_usage_host" + script = "coder stat cpu --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Memory Usage (Host)" + key = "5_mem_usage_host" + script = "coder stat mem --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Load Average (Host)" + key = "6_load_host" + # get load avg scaled by number of cores + script = </etc/sudoers.d/${USER} \ + && chmod 0440 /etc/sudoers.d/${USER} +USER ${USER} +WORKDIR /home/${USER} diff --git a/docker-ubuntu-base/main.tf b/docker-ubuntu-base/main.tf new file mode 100644 index 0000000..0b047b2 --- /dev/null +++ b/docker-ubuntu-base/main.tf @@ -0,0 +1,218 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + docker = { + source = "kreuzwerker/docker" + } + } +} + +locals { + username = data.coder_workspace.me.owner +} + +data "coder_provisioner" "me" { +} + +provider "docker" { +} + +data "coder_workspace" "me" { +} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + startup_script_timeout = 180 + startup_script = <<-EOT + set -e + + mkdir -p ~/workspace + + # install and start code-server + curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0 + /tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 & + + if [[ -f ~/.startup.sh ]]; then + echo "Executing startup script..." + ~/.startup.sh || echo "Startup script failure!" + else + echo "Startup script not found, skipped." + fi + + EOT + + # These environment variables allow you to make Git commits right away after creating a + # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! + # You can remove this block if you'd prefer to configure Git manually or using + # dotfiles. (see docs/dotfiles.md) + env = { + GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" + GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" + GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" + GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" + } + + # The following metadata blocks are optional. They are used to display + # information about your workspace in the dashboard. You can remove them + # if you don't want to display any information. + # For basic resources, you can use the `coder stat` command. + # If you need more control, you can write your own script. + metadata { + display_name = "CPU Usage" + key = "0_cpu_usage" + script = "coder stat cpu" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "RAM Usage" + key = "1_ram_usage" + script = "coder stat mem" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Home Disk" + key = "3_home_disk" + script = "coder stat disk --path $${HOME}" + interval = 60 + timeout = 1 + } + + metadata { + display_name = "CPU Usage (Host)" + key = "4_cpu_usage_host" + script = "coder stat cpu --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Memory Usage (Host)" + key = "5_mem_usage_host" + script = "coder stat mem --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Load Average (Host)" + key = "6_load_host" + # get load avg scaled by number of cores + script = </etc/sudoers.d/${USER} \ + && chmod 0440 /etc/sudoers.d/${USER} +USER ${USER} +WORKDIR /home/${USER} diff --git a/docker-ubuntu-rust/main.tf b/docker-ubuntu-rust/main.tf new file mode 100644 index 0000000..0b047b2 --- /dev/null +++ b/docker-ubuntu-rust/main.tf @@ -0,0 +1,218 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + docker = { + source = "kreuzwerker/docker" + } + } +} + +locals { + username = data.coder_workspace.me.owner +} + +data "coder_provisioner" "me" { +} + +provider "docker" { +} + +data "coder_workspace" "me" { +} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + startup_script_timeout = 180 + startup_script = <<-EOT + set -e + + mkdir -p ~/workspace + + # install and start code-server + curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0 + /tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 & + + if [[ -f ~/.startup.sh ]]; then + echo "Executing startup script..." + ~/.startup.sh || echo "Startup script failure!" + else + echo "Startup script not found, skipped." + fi + + EOT + + # These environment variables allow you to make Git commits right away after creating a + # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! + # You can remove this block if you'd prefer to configure Git manually or using + # dotfiles. (see docs/dotfiles.md) + env = { + GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" + GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" + GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" + GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" + } + + # The following metadata blocks are optional. They are used to display + # information about your workspace in the dashboard. You can remove them + # if you don't want to display any information. + # For basic resources, you can use the `coder stat` command. + # If you need more control, you can write your own script. + metadata { + display_name = "CPU Usage" + key = "0_cpu_usage" + script = "coder stat cpu" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "RAM Usage" + key = "1_ram_usage" + script = "coder stat mem" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Home Disk" + key = "3_home_disk" + script = "coder stat disk --path $${HOME}" + interval = 60 + timeout = 1 + } + + metadata { + display_name = "CPU Usage (Host)" + key = "4_cpu_usage_host" + script = "coder stat cpu --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Memory Usage (Host)" + key = "5_mem_usage_host" + script = "coder stat mem --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Load Average (Host)" + key = "6_load_host" + # get load avg scaled by number of cores + script = <