Skip to content

Commit

Permalink
[2023.05.14] Update all software and use Coder parameters instead of …
Browse files Browse the repository at this point in the history
…Terraform values
  • Loading branch information
auguwu committed May 14, 2023
1 parent 18fb49b commit f0c59b3
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 109 deletions.
6 changes: 3 additions & 3 deletions images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ RUN usermod -aG docker ${USERNAME}

# stuff here
ENV BAZEL_BUILDTOOLS_VERSION="6.1.2"
ENV GITHUB_CLI_VERSION="2.28.0"
ENV CODER_CLI_VERSION="0.23.0"
ENV GITHUB_CLI_VERSION="2.29.0"
ENV CODER_CLI_VERSION="0.23.2"
ENV TERRAFORM_VERSION="1.4.6"
ENV BAZELISK_VERSION="1.16.0"
ENV KUBECTL_VERSION="1.27.1"
ENV HELM_VERSION="3.11.3"
ENV HELM_VERSION="3.12.0"

# Get current architecture and download software here
# also this looks like shit, i know!
Expand Down
18 changes: 9 additions & 9 deletions images/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ This image is the main base for all of the images in this repository.
| Name | Description | Version |
| ---------------- | --------------------------------------------------------------------------------- | -------------------------- |
| Bazel Buildtools | A bazel BUILD file formatter and editor | [v6.1.2][bazel-buildtools] |
| GitHub CLI | GitHub's official command line utility | [v2.28.0][github-cli] |
| Coder (OSS) | Remote development environments on your infrastructure provisioned with Terraform | [v0.23.0][coder] |
| GitHub CLI | GitHub's official command line utility | [v2.29.0][github-cli] |
| Coder (OSS) | Remote development environments on your infrastructure provisioned with Terraform | [v0.23.2][coder] |
| Terraform | Automate Infrastructure on Any Cloud | [v1.4.6][terraform] |
| Bazelisk | A user-friendly launcher for Bazel. | [v1.16.0][bazelisk] |
| `kubectl` | kubectl controls the Kubernetes cluster manager. | [v1.27.1][kubectl] |
| `bazel` | a fast, scalable, multi-language and extensible build system | [v6.1.2][bazel] |
| `helm` | The Kubernetes Package Manager | [v3.11.3][helm] |
| `bazel` | a fast, scalable, multi-language and extensible build system | [v6.2.0][bazel] |
| `helm` | The Kubernetes Package Manager | [v3.12.0][helm] |

[bazel-buildtools]: https://github.com/bazelbuild/buildtools/releases/tag/6.1.2
[github-cli]: https://github.com/cli/cli/releases/tag/v2.28.0
[bazel-buildtools]: https://github.com/bazelbuild/buildtools/releases/tag/v6.1.2
[github-cli]: https://github.com/cli/cli/releases/tag/v2.29.0
[terraform]: https://github.com/hashicorp/terraform/releases/tag/v1.4.6
[bazelisk]: https://github.com/bazelbuild/bazelisk/releases/tag/v1.16.0
[kubectl]: https://github.com/kubernetes/kubernetes/releases/tag/v1.27.1
[coder]: https://github.com/coder/coder/releases/tag/v0.23.0
[bazel]: https://github.com/bazelbuild/bazel/releases/tag/6.1.2
[helm]: https://github.com/helm/helm/releases/tag/v3.11.3
[coder]: https://github.com/coder/coder/releases/tag/v0.23.2
[bazel]: https://github.com/bazelbuild/bazel/releases/tag/6.2.0
[helm]: https://github.com/helm/helm/releases/tag/v3.12.0

### Helm
Helm comes with Bitnami's charts library preconfigured.
4 changes: 2 additions & 2 deletions images/golang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ ENV USERNAME=noel
USER root

# Put versions in environment variables
ENV GOLANG_VERSION="1.20.3"
ENV GORELEASER_VERSION="1.17.2"
ENV GOLANG_VERSION="1.20.4"
ENV GORELEASER_VERSION="1.18.2"
ENV GOLANGCI_VERSION="1.52.2"

# Install packages here.
Expand Down
8 changes: 4 additions & 4 deletions images/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This is the Docker image that bundles the Go compiler with **goreleaser** and **
## Bundled Software
| Name | Description | Version |
| ---------- | -------------------------------------------------- | --------------------- |
| Go | The Go programming language | [v1.20.3][golang] |
| GoReleaser | Deliver Go binaries as fast and easily as possible | [v1.17.2][goreleaser] |
| Go | The Go programming language | [v1.20.4][golang] |
| GoReleaser | Deliver Go binaries as fast and easily as possible | [v1.18.2][goreleaser] |
| Golang CI | Fast linters Runner for Go | [v1.52.2][golangci] |

[goreleaser]: https://github.com/goreleaser/goreleaser/releases/tag/v1.17.2
[goreleaser]: https://github.com/goreleaser/goreleaser/releases/tag/v1.18.2
[golangci]: https://github.com/golangci/golangci-lint/releases/tag/v1.52.2
[golang]: https://github.com/golang/go/releases/tag/go1.20.3
[golang]: https://github.com/golang/go/releases/tag/go1.20.4
11 changes: 6 additions & 5 deletions images/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# use April 26th image (since Adoptium doesn't support Ubuntu Lunar yet)
FROM ghcr.io/auguwu/coder-images/base:2023.04.26
FROM ghcr.io/auguwu/coder-images/base

ENV USERNAME=noel

Expand All @@ -29,14 +28,16 @@ USER root

# Set version environment variables
ENV GRADLE_VERSION="8.1.1"
ENV MAVEN_VERSION="3.9.1"
ENV MAVEN_VERSION="3.9.2"

# install required things
RUN DEBIAN_FRONTEND="noninteractive" apt install -y wget libarchive-tools

# Install Temurin 19
# Install Temurin JDK 20
RUN wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo apt-key add -
RUN echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list

# force it to use the Kinetic repository until it supports 23.04
RUN echo "deb https://packages.adoptium.net/artifactory/deb kinetic main" | sudo tee /etc/apt/sources.list.d/adoptium.list
RUN DEBIAN_FRONTEND="noninteractive" apt update && \
DEBIAN_FRONTEND="noninteractive" apt install -y temurin-20-jdk

Expand Down
4 changes: 2 additions & 2 deletions images/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This image extends the [base image](https://github.com/auguwu/coder-images/pkgs/
| ------ | --------------------------------------------------- | ------------------------------- |
| JDK | The Java development kit. | [jdk-20.0.1+9][temurin-release] |
| Gradle | Adaptable, fast automation for all | [v8.1.1][gradle-release] |
| Maven | Software project management and comprehension tool. | [v3.9.1][maven-release] |
| Maven | Software project management and comprehension tool. | [v3.9.2][maven-release] |

[temurin-release]: https://github.com/adoptium/temurin20-binaries/releases/tag/jdk-20.0.1%2B9
[gradle-release]: https://github.com/gradle/gradle/releases/tag/v8.1.1
[maven-release]: https://github.com/apache/maven/releases/tag/maven-3.9.1
[maven-release]: https://github.com/apache/maven/releases/tag/maven-3.9.2
2 changes: 1 addition & 1 deletion images/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ENV USERNAME=noel
USER root

# versions here
ENV NODE_VERSION="20.0.0"
ENV NODE_VERSION="20.1.0"

# Install xz-utils so we can unpack the Node.js installation
RUN DEBIAN_FRONTEND="noninteractive" apt install -y xz-utils
Expand Down
4 changes: 2 additions & 2 deletions images/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ This image extends from the [base image](https://github.com/auguwu/coder-images/
## Bundled Software
| Name | Description | Version |
| ------- | ----------------------------------- | ---------------- |
| Node.js | Node.js JavaScript runtime ✨🐢🚀✨ | [v20.0.0][node] |
| Node.js | Node.js JavaScript runtime ✨🐢🚀✨ | [v20.1.0][node] |

[node]: https://github.com/nodejs/node/releases/v20.0.0
[node]: https://github.com/nodejs/node/releases/v20.1.0
89 changes: 41 additions & 48 deletions template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,39 @@ data "coder_workspace" "me" {

resource "coder_agent" "main" {
arch = "amd64"
dir = var.home_dir
dir = data.coder_parameter.volume_dir.value
os = "linux"

metadata {
display_name = "Processes"
key = "proc_count"
interval = 1
timeout = 1
script = "ps aux | wc -l"
key = "proc_count"
}

metadata {
display_name = "CPU Usage"
interval = 1
timeout = 1
script = "vmstat | awk 'FNR==3 {printf \"%2.0f%%\", $13+14+16}'"
key = "cpu"
}

metadata {
display_name = "Load Average"
key = "load"
script = "awk '{print $1}' /proc/loadavg"
interval = 1
timeout = 1
script = "awk '{print $1}' /proc/loadavg"
key = "load"
}

metadata {
display_name = "Disk Usage"
key = "disk"
script = "df -h | awk '$6 ~ /^\\/$/ { print $5 }'"
interval = 1
timeout = 1
script = "df -h | awk '$6 ~ /^\\/$/ { print $5 }'"
key = "disk"
}

metadata {
Expand All @@ -81,10 +89,18 @@ resource "coder_agent" "main" {
key = "containers"
}

metadata {
display_name = "Memory Usage"
interval = 1
timeout = 1
script = "free | awk '/^Mem/ { printf(\"%.0f%%\", $4/$2 * 100.0) }'"
key = "memory"
}

startup_script = <<-EOL
#!/bin/bash
# Fix folder permissions since root owns /home/noel for some reason???
sudo chown -R noel:noel /home/noel
sudo chown -R $USER:$USER /home/$USER
if [ ! -f ~/.profile ]; then
cp /etc/skel/.profile $HOME/.profile
Expand All @@ -110,37 +126,29 @@ resource "coder_agent" "main" {
sleep 1
done
# Install code-server if enabled
${var.install_codeserver == true ? "curl -fsSL https://code-server.dev/install.sh | sh" : ""}
${var.install_codeserver == true ? "code-server --auth none --port 3621 > /dev/null 2>&1 &" : ""}
# Clone the given repository if needed
if ! [ -d "${var.workspace_dir}" ]; then
${var.git_repository != "" ? "git clone ${var.git_repository} ${var.workspace_dir}" : ""}
fi
if ! [ -d "${var.workspace_dir}" ]; then
mkdir ${var.workspace_dir}
if ! [ -d "${data.coder_parameter.workspace.value}" ]; then
${data.coder_parameter.git_repository.value != "" ? "git clone ${data.coder_parameter.git_repository.value} ${data.coder_parameter.workspace.value}" : "mkdir ${data.coder_parameter.workspace.value}"}
fi
if [ -n "${var.docker_network_name}" ]; then
docker network create "${var.docker_network_name}" --driver=bridge >/dev/null 2>&1
echo "Created Docker network \`${var.docker_network_name}\`, you can use it with .coder/docker-compose.yml as a external network!"
if [ -n "${data.coder_parameter.docker_network_name.value}" ]; then
docker network create "${data.coder_parameter.docker_network_name.value}" --driver=bridge >/dev/null 2>&1
echo "Created Docker network \`${data.coder_parameter.docker_network_name.value}\`, you can use it with .coder/docker-compose.yml as a external network!"
fi
# if ${var.workspace_dir}/.coder exists, then we will run the pre-init scripts
# if ${data.coder_parameter.workspace.value}/.coder exists, then we will run the pre-init scripts
# and then the Docker Compose project (if any).
if [ -d "${var.workspace_dir}/.coder" ]; then
if [ -d "${data.coder_parameter.workspace.value}/.coder" ]; then
# Run any pre-init scripts in .coder/scripts/pre-init
if [ -d "${var.workspace_dir}/.coder/scripts/pre-init" ]; then
files=$(find "${var.workspace_dir}/.coder/scripts/pre-init" -maxdepth 1 -type f -executable -name '*.sh')
if [ -d "${data.coder_parameter.workspace.value}/.coder/scripts/pre-init" ]; then
files=$(find "${data.coder_parameter.workspace.value}/.coder/scripts/pre-init" -maxdepth 1 -type f -executable -name '*.sh')
for f in "$files"; do
(cd "${var.workspace_dir}/.coder" && bash $f) || echo "[coder::preinit] Unable to run pre-init script [$f]"
(cd "${data.coder_parameter.workspace.value}/.coder" && bash $f) || echo "[coder::preinit] Unable to run pre-init script [$f]"
done
fi
# Run the docker compose project
if [ -f "${var.workspace_dir}/.coder/docker-compose.yml" ]; then
if [ -f "${data.coder_parameter.workspace.value}/.coder/docker-compose.yml" ]; then
dc=""
if command -v docker-compose &>/dev/null; then
Expand All @@ -153,41 +161,26 @@ resource "coder_agent" "main" {
if [ -n "$dc" ]; then
echo "[coder::docker-compose] Using \`$dc\` as the Docker compose command!"
$dc -f "${var.workspace_dir}/.coder/docker-compose.yml" up -d
$dc -f "${data.coder_parameter.workspace.value}/.coder/docker-compose.yml" up -d
fi
fi
# run post-init scripts
if [ -d "${var.workspace_dir}/.coder/scripts/post-init" ]; then
files=$(find "${var.workspace_dir}/.coder/scripts/post-init" -maxdepth 1 -type f -executable -name '*.sh')
if [ -d "${data.coder_parameter.workspace.value}/.coder/scripts/post-init" ]; then
files=$(find "${data.coder_parameter.workspace.value}/.coder/scripts/post-init" -maxdepth 1 -type f -executable -name '*.sh')
for f in "$files"; do
(cd "${var.workspace_dir}/.coder" && bash $f) || echo "[coder::postinit] Unable to run post-init script [$f]"
(cd "${data.coder_parameter.workspace.value}/.coder" && bash $f) || echo "[coder::postinit] Unable to run post-init script [$f]"
done
fi
fi
# initialize dotfiles
${var.dotfiles_repo != "" ? "coder dotfiles -y ${var.dotfiles_repo}" : ""}
${data.coder_parameter.dotfiles.value != "" ? "coder dotfiles \"${data.coder_parameter.dotfiles.value}\" -y" : ""}
EOL
}

resource "coder_app" "code-server" {
count = var.install_codeserver ? 1 : 0
agent_id = coder_agent.main.id
slug = "code-server"
display_name = "Visual Studio Code"
url = "http://localhost:3621/?folder=${var.workspace_dir}"
icon = "/icon/code.svg"

healthcheck {
threshold = 10
interval = 10
url = "http://localhost:3621/healthz"
}
}

data "docker_registry_image" "image" {
name = var.custom_image != "" ? var.custom_image : "ghcr.io/auguwu/coder-images/${var.base_image}:latest"
name = data.coder_parameter.custom_docker_image.value != "" ? data.coder_parameter.custom_docker_image.value : "ghcr.io/auguwu/coder-images/${data.coder_parameter.base_docker_image.value}"
}

resource "docker_image" "docker_image" {
Expand All @@ -208,7 +201,7 @@ resource "docker_container" "workspace" {
]

volumes {
container_path = var.home_dir
container_path = data.coder_parameter.volume_dir.value
host_path = docker_volume.coder_workspace.mountpoint
}

Expand Down
Loading

0 comments on commit f0c59b3

Please sign in to comment.