Addresses part of https://github.com/coder/internal/issues/532 (but doesn't fully close it out). This is a huge PR, but chunking it up seemed pointless, since we're largely copying over existing files. I'm going to try commenting on the main areas I think are worth paying attention to ## Changes made - Migrated over all Coder modules from coder/modules, and put them in their correct user namespaces. - Added README.md files to all newly-created user namespaces - Updated all image paths for every image used, to make sure they don't break (I switched the paths programmatically, and then manually verified every README to guarantee this). - Added README.md files for each contributor who previously made a module - Updated our `tsconfig.json` file to use modern libraries when run from the server, and made a custom `tsconfig.json` just for the `windows-rdp` module (which has more restrictive browser concerns) - Added CI step to run all the module tests we currently have ## Notes - There were a lot of Bash script files that weren't carried over in this PR, partly because I don't know Bash well enough to know (1) whether they're still needed, or (2) modify them to account for the new file structure. Those can be brought over later. - We had a `lint.ts` file that provided some light validation of some of the modules. After going through it, there were so many bugs and issues with the code that I legitimately think that it barely provided a safety net at all. I got rid of it entirely, with the intention of adding the functionality that was originally intended to the current validation logic (to be handled in a separate PR). - I changed how we set up the `.images` directory, because it felt like it would be chaos if a bunch of users try to throw all their images in one giant directory, with no guidelines on how to do it. I instead made it so that images should be scoped by namespace, which felt a lot more manageable. The `.icons` directory is still at the top level, because realistically, there are only going to be so many types of icons referenced, so it's fine for those to be shared. - I don't think the `maintainer_github` and `contributor_github` fields make sense anymore, but those can be stripped out once we've updated the Registry site build step to use the new Registry repo - My gut instinct is to use the user namespace to determine the main owner of the module, and then add a `contributors` string list to indicate which other users have contributed meaningfully to it. We can then add validation to make sure that every value in that list exists as another namespace in the repo ## What still needs to be migrated (in separate PRs) These are the main files of interest that still probably need to be copied over from the `/modules` repo: - `new.sh` - `terraform_validate.sh` - `update-version.sh` They're probably going to require enough changes that it's worth handling them in a separate PR.
122 lines
3.6 KiB
HCL
122 lines
3.6 KiB
HCL
terraform {
|
|
required_version = ">= 1.0"
|
|
|
|
required_providers {
|
|
coder = {
|
|
source = "coder/coder"
|
|
version = ">= 0.12"
|
|
}
|
|
}
|
|
}
|
|
|
|
variable "url" {
|
|
description = "The URL of the Git repository."
|
|
type = string
|
|
}
|
|
|
|
variable "base_dir" {
|
|
default = ""
|
|
description = "The base directory to clone the repository. Defaults to \"$HOME\"."
|
|
type = string
|
|
}
|
|
|
|
variable "agent_id" {
|
|
description = "The ID of a Coder agent."
|
|
type = string
|
|
}
|
|
|
|
variable "git_providers" {
|
|
type = map(object({
|
|
provider = string
|
|
}))
|
|
description = "A mapping of URLs to their git provider."
|
|
default = {
|
|
"https://github.com/" = {
|
|
provider = "github"
|
|
},
|
|
"https://gitlab.com/" = {
|
|
provider = "gitlab"
|
|
},
|
|
}
|
|
validation {
|
|
error_message = "Allowed values for provider are \"github\" or \"gitlab\"."
|
|
condition = alltrue([for provider in var.git_providers : contains(["github", "gitlab"], provider.provider)])
|
|
}
|
|
}
|
|
|
|
variable "branch_name" {
|
|
description = "The branch name to clone. If not provided, the default branch will be cloned."
|
|
type = string
|
|
default = ""
|
|
}
|
|
|
|
variable "folder_name" {
|
|
description = "The destination folder to clone the repository into."
|
|
type = string
|
|
default = ""
|
|
}
|
|
|
|
locals {
|
|
# Remove query parameters and fragments from the URL
|
|
url = replace(replace(var.url, "/\\?.*/", ""), "/#.*/", "")
|
|
|
|
# Find the git provider based on the URL and determine the tree path
|
|
provider_key = try(one([for key in keys(var.git_providers) : key if startswith(local.url, key)]), null)
|
|
provider = try(lookup(var.git_providers, local.provider_key).provider, "")
|
|
tree_path = local.provider == "gitlab" ? "/-/tree/" : local.provider == "github" ? "/tree/" : ""
|
|
|
|
# Remove tree and branch name from the URL
|
|
clone_url = var.branch_name == "" && local.tree_path != "" ? replace(local.url, "/${local.tree_path}.*/", "") : local.url
|
|
# Extract the branch name from the URL
|
|
branch_name = var.branch_name == "" && local.tree_path != "" ? replace(replace(local.url, local.clone_url, ""), "/.*${local.tree_path}/", "") : var.branch_name
|
|
# Extract the folder name from the URL
|
|
folder_name = var.folder_name == "" ? replace(basename(local.clone_url), ".git", "") : var.folder_name
|
|
# Construct the path to clone the repository
|
|
clone_path = var.base_dir != "" ? join("/", [var.base_dir, local.folder_name]) : join("/", ["~", local.folder_name])
|
|
# Construct the web URL
|
|
web_url = startswith(local.clone_url, "git@") ? replace(replace(local.clone_url, ":", "/"), "git@", "https://") : local.clone_url
|
|
}
|
|
|
|
output "repo_dir" {
|
|
value = local.clone_path
|
|
description = "Full path of cloned repo directory"
|
|
}
|
|
|
|
output "git_provider" {
|
|
value = local.provider
|
|
description = "The git provider of the repository"
|
|
}
|
|
|
|
output "folder_name" {
|
|
value = local.folder_name
|
|
description = "The name of the folder that will be created"
|
|
}
|
|
|
|
output "clone_url" {
|
|
value = local.clone_url
|
|
description = "The exact Git repository URL that will be cloned"
|
|
}
|
|
|
|
output "web_url" {
|
|
value = local.web_url
|
|
description = "Git https repository URL (may be invalid for unsupported providers)"
|
|
}
|
|
|
|
output "branch_name" {
|
|
value = local.branch_name
|
|
description = "Git branch name (may be empty)"
|
|
}
|
|
|
|
resource "coder_script" "git_clone" {
|
|
agent_id = var.agent_id
|
|
script = templatefile("${path.module}/run.sh", {
|
|
CLONE_PATH = local.clone_path,
|
|
REPO_URL : local.clone_url,
|
|
BRANCH_NAME : local.branch_name,
|
|
})
|
|
display_name = "Git Clone"
|
|
icon = "/icon/git.svg"
|
|
run_on_start = true
|
|
start_blocks_login = true
|
|
}
|