diff --git a/docs/platforms/jfrog.md b/docs/platforms/jfrog.md index 341adb42d6..5ed569632c 100644 --- a/docs/platforms/jfrog.md +++ b/docs/platforms/jfrog.md @@ -41,33 +41,35 @@ terraform { required_providers { coder = { source = "coder/coder" - version = "~> 0.11.1" } docker = { source = "kreuzwerker/docker" - version = "~> 3.0.1" } artifactory = { source = "registry.terraform.io/jfrog/artifactory" - version = "~> 8.4.0" } } } -variable "jfrog_host" { +variable "jfrog_url" { type = string - description = "JFrog instance hostname. e.g. YYY.jfrog.io" + description = "JFrog instance URL. e.g. https://jfrog.example.com" + # validate the URL to ensure it starts with https:// or http:// + validation { + condition = can(regex("^https?://", var.jfrog_url)) + error_message = "JFrog URL must start with https:// or http://" + } } -variable "artifactory_access_token" { +variable "artifactory_admin_access_token" { type = string - description = "The admin-level access token to use for JFrog." + description = "The admin-level access token to use for JFrog with scope applied-permissions/admin" } # Configure the Artifactory provider provider "artifactory" { - url = "https://${var.jfrog_host}/artifactory" - access_token = "${var.artifactory_access_token}" + url = "${var.jfrog_url}/artifactory" + access_token = "${var.artifactory_admin_access_token}" } resource "artifactory_scoped_token" "me" { @@ -80,7 +82,7 @@ resource "artifactory_scoped_token" "me" { When pushing the template, you can pass in the variables using the `--var` flag: ```shell -coder templates push --var 'jfrog_host=YYY.jfrog.io' --var 'artifactory_access_token=XXX' +coder templates push --var 'jfrog_url=https://YYY.jfrog.io' --var 'artifactory_admin_access_token=XXX' ``` ## Installing JFrog CLI @@ -118,6 +120,10 @@ locals { python = "pypi" go = "go" } + # Make sure to use the same field as the username field in the Artifactory + # It can be either the username or the email address. + artifactory_username = data.coder_workspace.me.owner_email + jfrog_host = replace(var.jfrog_url, "^https://", "") } ``` @@ -133,7 +139,7 @@ resource "coder_agent" "main" { set -e # install and start code-server - curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0 + curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server /tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 & # The jf CLI checks $CI when determining whether to use interactive @@ -142,12 +148,12 @@ resource "coder_agent" "main" { jf c rm 0 || true echo ${artifactory_scoped_token.me.access_token} | \ - jf c add --access-token-stdin --url https://${var.jfrog_host} 0 + jf c add --access-token-stdin --url ${var.jfrog_url} 0 # Configure the `npm` CLI to use the Artifactory "npm" repository. cat << EOF > ~/.npmrc email = ${data.coder_workspace.me.owner_email} - registry = https://${var.jfrog_host}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]} + registry = ${var.jfrog_url}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]} EOF jf rt curl /api/npm/auth >> .npmrc @@ -155,13 +161,13 @@ resource "coder_agent" "main" { mkdir -p ~/.pip cat << EOF > ~/.pip/pip.conf [global] - index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple + index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple EOF EOT # Set GOPROXY to use the Artifactory "go" repository. env = { - GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}" + GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local..jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}" } } ``` @@ -192,9 +198,7 @@ following lines into your `startup_script`: # Install the JFrog VS Code extension. # Find the latest version number at # https://open-vsx.org/extension/JFrog/jfrog-vscode-extension. -JFROG_EXT_VERSION=2.4.1 -curl -o /tmp/jfrog.vsix -L "https://open-vsx.org/api/JFrog/jfrog-vscode-extension/$JFROG_EXT_VERSION/file/JFrog.jfrog-vscode-extension-$JFROG_EXT_VERSION.vsix" -/tmp/code-server/bin/code-server --install-extension /tmp/jfrog.vsix +/tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension ``` Note that this method will only work if your developers use code-server. @@ -208,7 +212,7 @@ Artifactory: # Configure the `npm` CLI to use the Artifactory "npm" registry. cat << EOF > ~/.npmrc email = ${data.coder_workspace.me.owner_email} - registry = https://${var.jfrog_host}/artifactory/api/npm/npm/ + registry = ${var.jfrog_url}/artifactory/api/npm/npm/ EOF jf rt curl /api/npm/auth >> .npmrc ``` @@ -227,7 +231,7 @@ Artifactory: mkdir -p ~/.pip cat << EOF > ~/.pip/pip.conf [global] - index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/pypi/pypi/simple + index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/pypi/pypi/simple EOF ``` @@ -243,7 +247,7 @@ Add the following environment variable to your `coder_agent` block to configure ```hcl env = { - GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/go" + GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/go" } ``` diff --git a/examples/jfrog/docker/README.md b/examples/jfrog/docker/README.md index 4db4676e8a..139bdbd80f 100644 --- a/examples/jfrog/docker/README.md +++ b/examples/jfrog/docker/README.md @@ -5,7 +5,7 @@ tags: [local, docker, jfrog] icon: /icon/docker.png --- -# docker +# Docker To get started, run `coder templates init`. When prompted, select this template. Follow the on-screen instructions to proceed. @@ -22,5 +22,5 @@ the dashboard UI over `localhost:13337`. # Next steps -Check out our [Docker](../docker/) template for a more fully featured Docker +Check out our [Docker](../../templates/docker/) template for a more fully featured Docker example. diff --git a/examples/jfrog/docker/main.tf b/examples/jfrog/docker/main.tf index 9a1d8a2cbb..0d6b2e4dfe 100644 --- a/examples/jfrog/docker/main.tf +++ b/examples/jfrog/docker/main.tf @@ -13,8 +13,8 @@ terraform { } locals { - # take care to use owner_email instead of owner because users can change - # their username. + # Make sure to use the same field as the username field in the Artifactory + # It can be either the username or the email address. artifactory_username = data.coder_workspace.me.owner_email artifactory_repository_keys = { "npm" = "npm" @@ -22,31 +22,34 @@ locals { "go" = "go" } workspace_user = data.coder_workspace.me.owner + jfrog_host = replace(var.jfrog_url, "^https://", "") } -data "coder_provisioner" "me" { -} +data "coder_provisioner" "me" {} -provider "docker" { -} +provider "docker" {} -data "coder_workspace" "me" { -} +data "coder_workspace" "me" {} -variable "jfrog_host" { +variable "jfrog_url" { type = string - description = "JFrog instance hostname. For example, 'YYY.jfrog.io'." + description = "JFrog instance URL. For example, https://jfrog.example.com." + # validate the URL to ensure it starts with https:// or http:// + validation { + condition = can(regex("^https?://", var.jfrog_url)) + error_message = "JFrog URL must start with https:// or http://" + } } -variable "artifactory_access_token" { +variable "artifactory_admin_access_token" { type = string - description = "The admin-level access token to use for JFrog." + description = "The admin-level access token to use for JFrog with scope applied-permissions/admin." } -# Configure the Artifactory provider +# Configure the Artifactory provider with the admin-level access token. provider "artifactory" { - url = "https://${var.jfrog_host}/artifactory" - access_token = var.artifactory_access_token + url = "${var.jfrog_url}/artifactory" + access_token = var.artifactory_admin_access_token } resource "artifactory_scoped_token" "me" { @@ -63,7 +66,7 @@ resource "coder_agent" "main" { set -e # install and start code-server - curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0 + curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server /tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 & # Install the JFrog VS Code extension. @@ -77,12 +80,12 @@ resource "coder_agent" "main" { jf c rm 0 || true echo ${artifactory_scoped_token.me.access_token} | \ - jf c add --access-token-stdin --url https://${var.jfrog_host} 0 + jf c add --access-token-stdin --url ${var.jfrog_url} 0 # Configure the `npm` CLI to use the Artifactory "npm" repository. cat << EOF > ~/.npmrc email = ${data.coder_workspace.me.owner_email} - registry = https://${var.jfrog_host}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]} + registry = ${var.jfrog_url}/artifactory/api/npm/${local.artifactory_repository_keys["npm"]} EOF jf rt curl /api/npm/auth >> .npmrc @@ -90,15 +93,15 @@ resource "coder_agent" "main" { mkdir -p ~/.pip cat << EOF > ~/.pip/pip.conf [global] - index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple + index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple EOF EOT # Set GOPROXY to use the Artifactory "go" repository. env = { - GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}" + GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}" # Authenticate with JFrog extension. - JFROG_IDE_URL : "https://${var.jfrog_host}" + JFROG_IDE_URL : "${var.jfrog_url}" JFROG_IDE_USERNAME : "${local.artifactory_username}" JFROG_IDE_PASSWORD : "${artifactory_scoped_token.me.access_token}" JFROG_IDE_ACCESS_TOKEN : "${artifactory_scoped_token.me.access_token}"