feat: add git clone module (#46)
* feat: add `git-clone` module * Fix script expansion for personalize * Update READMEpull/49/head
parent
842a2caaed
commit
84bad159a3
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="97" height="97">
|
||||
<path fill="#F05133" d="M92.71 44.408 52.591 4.291c-2.31-2.311-6.057-2.311-8.369 0l-8.33 8.332L46.459 23.19c2.456-.83 5.272-.273 7.229 1.685 1.969 1.97 2.521 4.81 1.67 7.275l10.186 10.185c2.465-.85 5.307-.3 7.275 1.671 2.75 2.75 2.75 7.206 0 9.958-2.752 2.751-7.208 2.751-9.961 0-2.068-2.07-2.58-5.11-1.531-7.658l-9.5-9.499v24.997c.67.332 1.303.774 1.861 1.332 2.75 2.75 2.75 7.206 0 9.959-2.75 2.749-7.209 2.749-9.957 0-2.75-2.754-2.75-7.21 0-9.959.68-.679 1.467-1.193 2.307-1.537v-25.23c-.84-.344-1.625-.853-2.307-1.537-2.083-2.082-2.584-5.14-1.516-7.698L31.798 16.715 4.288 44.222c-2.311 2.313-2.311 6.06 0 8.371l40.121 40.118c2.31 2.311 6.056 2.311 8.369 0L92.71 52.779c2.311-2.311 2.311-6.06 0-8.371z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 802 B |
@ -0,0 +1,38 @@
|
||||
---
|
||||
display_name: Git Clone
|
||||
description: Clone a Git repository by URL and skip if it exists.
|
||||
icon: ../.icons/git.svg
|
||||
maintainer_github: coder
|
||||
verified: true
|
||||
tags: [git, helper]
|
||||
---
|
||||
# Git Clone
|
||||
|
||||
This module allows you to automatically clone a repository by URL and skip if it exists in the path provided.
|
||||
|
||||
```hcl
|
||||
module "git-clone" {
|
||||
source = "https://registry.coder.com/modules/git-clone"
|
||||
url = "https://github.com/coder/coder"
|
||||
}
|
||||
```
|
||||
|
||||
To use with [Git Authentication](https://coder.com/docs/v2/latest/admin/git-providers), add the provider by ID to your template:
|
||||
|
||||
```hcl
|
||||
data "coder_git_auth" "github" {
|
||||
id = "github"
|
||||
}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Custom Path
|
||||
|
||||
```hcl
|
||||
module "git-clone" {
|
||||
source = "https://registry.coder.com/modules/git-clone"
|
||||
url = "https://github.com/coder/coder"
|
||||
path = "~/projects/coder/coder"
|
||||
}
|
||||
```
|
@ -0,0 +1,37 @@
|
||||
terraform {
|
||||
required_version = ">= 1.0"
|
||||
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = ">= 0.11"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "url" {
|
||||
description = "The URL of the Git repository."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "path" {
|
||||
default = ""
|
||||
description = "The path to clone the repository. Defaults to \"$HOME/<basename of url>\"."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "agent_id" {
|
||||
description = "The ID of a Coder agent."
|
||||
type = string
|
||||
}
|
||||
|
||||
resource "coder_script" "git_clone" {
|
||||
agent_id = var.agent_id
|
||||
display_name = "Git Clone"
|
||||
icon = "/icons/git.svg"
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
CLONE_PATH: var.path != "" ? var.path : join("/", ["~", basename(var.url)]),
|
||||
REPO_URL: var.url,
|
||||
})
|
||||
run_on_start = true
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
REPO_URL="${REPO_URL}"
|
||||
CLONE_PATH="${CLONE_PATH}"
|
||||
# Expand home if it's specified!
|
||||
CLONE_PATH="$${CLONE_PATH/#\~/$${HOME}}"
|
||||
|
||||
# Check if the variable is empty...
|
||||
if [ -z "$REPO_URL" ]; then
|
||||
echo "No repository specified!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the variable is empty...
|
||||
if [ -z "$CLONE_PATH" ]; then
|
||||
echo "No clone path specified!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if `git` is installed...
|
||||
if ! command -v git >/dev/null; then
|
||||
echo "Git is not installed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the directory exists...
|
||||
if [ ! -d "$CLONE_PATH" ]; then
|
||||
echo "Creating directory $CLONE_PATH..."
|
||||
mkdir -p "$CLONE_PATH"
|
||||
else
|
||||
echo "$CLONE_PATH already exists, skipping clone!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Clone the repository...
|
||||
echo "Cloning $REPO_URL to $CLONE_PATH..."
|
||||
git clone "$REPO_URL" "$CLONE_PATH"
|
||||
|
Loading…
Reference in New Issue