Skip to content

Commit

Permalink
refactor: Rename MATLAB CPU template files and update workflow paths
Browse files Browse the repository at this point in the history
  • Loading branch information
matifali committed Jun 3, 2024
1 parent c6f978f commit b98a510
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 107 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/matlab-gpu.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# An action to push templates to coder server

name: MATLAB CPU Template
name: MATLAB Template

on:
push:
branches:
- main
paths:
- "matlab-cpu/main.tf"
- ".github/workflows/matlab-cpu.yaml"
- "matlab/main.tf"
- ".github/workflows/matlab.yaml"
workflow_dispatch:

jobs:
Expand Down
6 changes: 3 additions & 3 deletions matlab-cpu/README.md → matlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A matlab template for [coder](https://coder.com/).

```bash
git clone https://github,com/matifali/coder-templates
cd coder-templates/matlab-cpu
cd coder-templates/matlab
```

2. Login to coder
Expand All @@ -29,13 +29,13 @@ A matlab template for [coder](https://coder.com/).
3. Create a template

```bash
coder templates create matlab-cpu
coder templates create matlab
```

4. Create a workspace

```bash
coder create matlab --template matlab-cpu
coder create matlab --template matlab
```

Or,
Expand Down
145 changes: 83 additions & 62 deletions matlab-cpu/main.tf → matlab/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~>0.17.0"
}
docker = {
source = "kreuzwerker/docker"
Expand All @@ -11,46 +10,85 @@ terraform {
}
}


locals {
# define ssh docker hosts
servers = {
CTAR-301 = "ssh://ctar@CTAR-301"
CTAR-302 = "ssh://ctar@CTAR-302"
}
}

provider "docker" {
host = try(lookup(local.servers, data.coder_parameter.server.value), "unix:///var/run/docker.sock")
ssh_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"]
}

provider "coder" {
}

data "coder_workspace" "me" {
}

data "coder_parameter" "server" {
name = "server"
display_name = "Server Name"
display_name = "Server"
icon = "/icon/container.svg"
description = "Choose server"
default = "ssh://ctar@ctar301"
type = "string"
mutable = false
order = 1
option {
name = "ctar401"
description = "CTAR 401"
value = "ssh://ctar@ctar401"
icon = "/icon/container.svg"
}
option {
name = "ctar402"
description = "CTAR 402"
value = "ssh://ctar@ctar402"
icon = "/icon/container.svg"
}
option {
name = "ctar403"
description = "CTAR 403"
value = "ssh://ctar@ctar403"
icon = "/icon/container.svg"
}
option {
name = "ctar404"
description = "CTAR 404"
value = "ssh://ctar@ctar404"
icon = "/icon/container.svg"
}
option {
name = "ctar405"
description = "CTAR 405"
value = "ssh://ctar@ctar405"
icon = "/icon/container.svg"
}
option {
name = "CTAR-301"
value = "CTAR-301"
name = "ctar301"
description = "CTAR 301"
value = "ssh://ctar@ctar301"
icon = "/icon/container.svg"
}
option {
name = "CTAR-302"
value = "CTAR-302"
name = "ctar302"
description = "CTAR 302"
value = "ssh://ctar@ctar302"
icon = "/icon/container.svg"
}
option {
name = "ctar303"
description = "CTAR 303"
value = "ssh://ctar@ctar303"
icon = "/icon/container.svg"
}
}


provider "docker" {
host = data.coder_parameter.server.value
ssh_opts = [
"-i", "/home/coder/.ssh/id_bilkent_ctar_servers",
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null"
]
}

provider "coder" {}

data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

module "filebrowser" {
source = "registry.coder.com/modules/filebrowser/coder"
version = "1.0.8"
agent_id = coder_agent.main.id
folder = "/home/matlab"
}

# Matlab
Expand All @@ -77,7 +115,6 @@ resource "coder_app" "matlab_desktop" {
resource "coder_agent" "main" {
arch = "amd64"
os = "linux"
startup_script_timeout = 180
startup_script = <<EOT
#!/bin/bash
set -euo pipefail
Expand All @@ -96,70 +133,55 @@ resource "coder_agent" "main" {
}

metadata {
display_name = "CPU Usage Workspace"
display_name = "CPU Usage"
interval = 10
key = "0_cpu_usage"
order = 1
key = "cpu_usage"
script = "coder stat cpu"
}

metadata {
display_name = "RAM Usage Workspace"
display_name = "RAM Usage"
interval = 10
key = "1_ram_usage"
order = 2
key = "ram_usage"
script = "coder stat mem"
}

metadata {
display_name = "CPU Usage Host"
interval = 10
key = "2_cpu_usage"
script = "coder stat cpu --host"
}

metadata {
display_name = "RAM Usage Host"
interval = 10
key = "3_ram_usage"
script = "coder stat mem --host"
}

metadata {
display_name = "Disk Usage"
interval = 600
key = "6_disk_usage"
order = 3
key = "disk_usage"
script = "coder stat disk $HOME"
}

metadata {
display_name = "Word of the Day"
interval = 86400
key = "5_word_of_the_day"
order = 4
key = "word_of_the_day"
script = <<EOT
curl -o - --silent https://www.merriam-webster.com/word-of-the-day 2>&1 | awk ' $0 ~ "Word of the Day: [A-z]+" { print $5; exit }'
EOT
}
}

data "docker_registry_image" "matlab" {
name = "matifali/matlab:latest"
}

resource "docker_image" "matlab" {
name = data.docker_registry_image.matlab.name
pull_triggers = [data.docker_registry_image.matlab.sha256_digest]
name = "matifali/matlab:r2023a"
keep_locally = true
}

#home_volume
resource "docker_volume" "home_volume" {
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}-home"
}

resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = docker_image.matlab.image_id
# Uses lower() to avoid Docker restriction on container names.
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = lower(data.coder_workspace.me.name)
dns = ["1.1.1.1"]
Expand All @@ -184,11 +206,11 @@ resource "docker_container" "workspace" {
# Add labels in Docker to keep track of orphan resources.
labels {
label = "coder.owner"
value = data.coder_workspace.me.owner
value = data.coder_workspace_owner.me.name
}
labels {
label = "coder.owner_id"
value = data.coder_workspace.me.owner_id
value = data.coder_workspace_owner.me.id
}
labels {
label = "coder.workspace_id"
Expand All @@ -203,9 +225,8 @@ resource "docker_container" "workspace" {
resource "coder_metadata" "workspace" {
count = data.coder_workspace.me.start_count
resource_id = docker_container.workspace[count.index].id
daily_cost = 50
item {
key = "Server"
value = data.coder_parameter.server.value
key = "Server Name"
value = data.coder_parameter.server.option[index(data.coder_parameter.server.option.*.value, data.coder_parameter.server.value)].description
}
}
}
File renamed without changes

0 comments on commit b98a510

Please sign in to comment.