Skip to content

Commit 95d66ac

Browse files
authored
docs: explain using Artifactory as a template store (#9071)
1 parent 7261f0a commit 95d66ac

File tree

6 files changed

+77
-13
lines changed

6 files changed

+77
-13
lines changed

docs/platforms/jfrog.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Use Coder and JFrog together to secure your development environments without dis
55
This guide will demonstrate how to use JFrog Artifactory as a package registry
66
within a workspace. We'll use Docker as the underlying compute. But, these concepts apply to any compute platform.
77

8-
The full example template can be found [here](https://github.com/coder/coder/tree/main/examples/templates/jfrog-docker).
8+
The full example template can be found [here](https://github.com/coder/coder/tree/main/examples/templates/jfrog/docker).
99

1010
## Requirements
1111

@@ -74,7 +74,7 @@ coder templates push --var 'jfrog_host=YYY.jfrog.io' --var 'artifactory_access_t
7474
we'll focus on its ability to configure package managers, as that's the relevant
7575
functionality for most developers.
7676

77-
The generic method of installing the JFrog CLI is the following command:
77+
Most users should be able to install `jf` by running the following command:
7878

7979
```sh
8080
curl -fL https://install-cli.jfrog.io | sh
@@ -165,7 +165,7 @@ Default: true
165165

166166
## Installing the JFrog VS Code Extension
167167

168-
You can install the JFrog VS Code extension into workspaces automatically
168+
You can install the JFrog VS Code extension into workspaces
169169
by inserting the following lines into your `startup_script`:
170170

171171
```sh
@@ -228,5 +228,6 @@ supported by Artifactory. See the [JFrog documentation](https://jfrog.com/help/r
228228
229229
## More reading
230230
231-
- See the full example template [here](https://github.com/coder/coder/tree/main/examples/templates/jfrog-docker).
231+
- See the full example template [here](https://github.com/coder/coder/tree/main/examples/templates/jfrog/docker).
232232
- To serve extensions from your own VS Code Marketplace, check out [code-marketplace](https://github.com/coder/code-marketplace#artifactory-storage).
233+
- To store templates in Artifactory, check out our [Artifactory modules](../templates/modules.md#artifactory) docs.

docs/templates/modules.md

+47
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,50 @@ coder:
8787
subPath: .git-credentials
8888
readOnly: true
8989
```
90+
91+
## Artifactory
92+
93+
JFrog Artifactory can serve as a Terraform module registry, allowing you to simplify
94+
a Coder-stored template to a `module` block and input variables.
95+
96+
With this approach, you can:
97+
98+
- Easily share templates across multiple Coder instances
99+
- Store templates far larger than the 1MB limit of Coder's template storage
100+
- Apply JFrog platform security policies to your templates
101+
102+
### Basic Scaffolding
103+
104+
For example, a template with:
105+
106+
```hcl
107+
module "frontend" {
108+
source = "cdr.jfrog.io/tf__main/frontend/docker"
109+
}
110+
```
111+
112+
References the `frontend` module in the `main` namespace of the `tf` repository.
113+
Remember to replace `cdr.jfrog.io` with your Artifactory instance URL.
114+
115+
You can upload the underlying module to Artifactory with:
116+
117+
```console
118+
# one-time setup commands
119+
# run this on the coder server (or external provisioners, if you have them)
120+
terraform login cdr.jfrog.io; jf tfc --global
121+
122+
# jf tf p assumes the module name is the same as the current directory name.
123+
jf tf p --namespace=main --provider=docker --tag=v0.0.1
124+
```
125+
126+
### Example template
127+
128+
We have an example template [here](https://github.com/coder/coder/tree/main/examples/templates/jfrog/remote) that uses our [JFrog Docker](../platforms/jfrog.md) template
129+
as the underlying module.
130+
131+
### Next up
132+
133+
Learn more about
134+
135+
- JFrog's Terraform Registry support [here](https://jfrog.com/help/r/jfrog-artifactory-documentation/terraform-registry).
136+
- Configuring the JFrog toolchain inside a workspace [here](../platforms/jfrog.md).

examples/templates/jfrog-docker/README.md renamed to examples/templates/jfrog/docker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tags: [local, docker, jfrog]
55
icon: /icon/docker.png
66
---
77

8-
# jfrog-docker
8+
# docker
99

1010
To get started, run `coder templates init`. When prompted, select this template.
1111
Follow the on-screen instructions to proceed.

examples/templates/jfrog-docker/main.tf renamed to examples/templates/jfrog/docker/main.tf

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ terraform {
1616
}
1717

1818
locals {
19-
# if the jfrog username is same as the coder username, you can use the following
20-
# artifactory_username = data.coder_workspace.me.owner
21-
# if the username is same as email, you can use the following
22-
# artifactory_username = urlencode(data.coder_workspace.me.owner_email)
23-
artifactory_username = data.coder_workspace.me.owner
19+
# take care to use owner_email instead of owner because users can change
20+
# their username.
21+
artifactory_username = data.coder_workspace.me.owner_email
2422
artifactory_repository_keys = {
2523
"npm" = "npm"
2624
"python" = "python"
@@ -55,7 +53,9 @@ provider "artifactory" {
5553
}
5654

5755
resource "artifactory_scoped_token" "me" {
58-
username = local.artifactory_username
56+
# This is hacky, but on terraform plan the data source gives empty strings,
57+
# which fails validation.
58+
username = length(local.artifactory_username) > 0 ? local.artifactory_username : "plan"
5959
}
6060

6161
resource "coder_agent" "main" {
@@ -125,13 +125,13 @@ resource "docker_volume" "home_volume" {
125125
resource "docker_image" "main" {
126126
name = "coder-${data.coder_workspace.me.id}"
127127
build {
128-
context = "./build"
128+
context = "${path.module}/build"
129129
build_args = {
130130
USER = local.workspace_user
131131
}
132132
}
133133
triggers = {
134-
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
134+
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1("${path.module}/${f}")]))
135135
}
136136
}
137137

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module "docker" {
2+
source = "cdr.jfrog.io/tf__main/docker/docker"
3+
jfrog_host = var.jfrog_host
4+
artifactory_access_token = var.artifactory_access_token
5+
}
6+
7+
variable "jfrog_host" {
8+
type = string
9+
description = "JFrog instance hostname. For example, 'YYY.jfrog.io'."
10+
}
11+
12+
variable "artifactory_access_token" {
13+
type = string
14+
description = "The admin-level access token to use for JFrog."
15+
}
16+

0 commit comments

Comments
 (0)