From 0421dfed9f3d4d15fe393b7fee58a0d16db5fa44 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Dec 2023 18:42:24 +0300 Subject: [PATCH 01/52] add JFrog extension configuration --- jfrog-oauth/main.tf | 44 +++++++++++++++++++++++++++++++++++++++++++- jfrog-oauth/run.sh | 18 ++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 8a81594c..78017c46 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -4,7 +4,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = ">= 0.12" + version = ">= 0.12.4" } } } @@ -35,6 +35,12 @@ variable "agent_id" { description = "The ID of a Coder agent." } +variable "configure_code_server" { + type = bool + description = "Whether to configure code-server to use JFrog." + default = false +} + variable "package_managers" { type = map(string) description = < /dev/null 2>&1; then + echo "📦 Installing JFrog extension..." + code-server --install-extension jfrog.jfrog-vscode-extension + echo "🥳 JFrog extension installed!" + elif command /tmp/coder-server/bin/code-server > /dev/null 2>&1; then + echo "📦 Installing JFrog extension..." + /tmp/coder-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension + echo "🥳 JFrog extension installed!" + else + echo "🤔 code-server is not installed, skipping JFrog extension installation." + fi +else + echo "🤔 CONFIGURE_CODE_SERVER is not set to true, skipping JFrog extension installation." +fi \ No newline at end of file From cb49f8ddf171efdf7b31d79622f063397472f581 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Dec 2023 18:46:34 +0300 Subject: [PATCH 02/52] add example to README --- jfrog-oauth/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/jfrog-oauth/README.md b/jfrog-oauth/README.md index 4e6d7e77..1a8b0cb1 100644 --- a/jfrog-oauth/README.md +++ b/jfrog-oauth/README.md @@ -60,6 +60,25 @@ jf pip install requests pip install requests ``` +### Configure code-server to with JFrog extension + +The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extension) for VS Code allows you to interact with Artifactory from within the IDE. + +```hcl +module "jfrog" { + source = "https://registry.coder.com/modules/jfrog-oauth" + agent_id = coder_agent.example.id + jfrog_url = "https://jfrog.example.com" + auth_method = "oauth" + username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" + configure_code_server = true + package_managers = { + "npm": "npm", + "go": "go", + "pypi": "pypi" + } +} +``` ### Using the access token in other terraform resources JFrog Access token is also available as a terraform output. You can use it in other terraform resources. For example, you can use it to configure an [Artifactory docker registry](https://jfrog.com/help/r/jfrog-artifactory-documentation/docker-registry) with the [docker terraform provider](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs). From 85e92970ec3c90186e7ca509debf7c7e11fa2f4d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Dec 2023 18:48:53 +0300 Subject: [PATCH 03/52] fmt --- jfrog-oauth/README.md | 1 + jfrog-oauth/main.tf | 22 ++++++++-------- jfrog-oauth/run.sh | 2 +- jfrog-token/README.md | 59 ++++++++++++++++++++++++++++--------------- 4 files changed, 52 insertions(+), 32 deletions(-) diff --git a/jfrog-oauth/README.md b/jfrog-oauth/README.md index 1a8b0cb1..3827e2ea 100644 --- a/jfrog-oauth/README.md +++ b/jfrog-oauth/README.md @@ -79,6 +79,7 @@ module "jfrog" { } } ``` + ### Using the access token in other terraform resources JFrog Access token is also available as a terraform output. You can use it in other terraform resources. For example, you can use it to configure an [Artifactory docker registry](https://jfrog.com/help/r/jfrog-artifactory-documentation/docker-registry) with the [docker terraform provider](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs). diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 78017c46..8af19abe 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -95,35 +95,35 @@ output "username" { } resource "coder_env" "jfrog_ide_url" { - count = var.configure_code_server ? 1 : 0 + count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id - name = "JFROG_IDE_URL" - value = var.jfrog_url + name = "JFROG_IDE_URL" + value = var.jfrog_url } resource "coder_env" "jfrog_ide_username" { - count = var.configure_code_server ? 1 : 0 + count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id - name = "JFROG_IDE_USERNAME" - value = local.username + name = "JFROG_IDE_USERNAME" + value = local.username } resource "coder_env" "jfrog_ide_password" { - count = var.configure_code_server ? 1 : 0 + count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id - name = "JFROG_IDE_PASSWORD" - value = data.coder_external_auth.jfrog.access_token + name = "JFROG_IDE_PASSWORD" + value = data.coder_external_auth.jfrog.access_token } resource "coder_env" "jfrog_ide_access_token" { - count = var.configure_code_server ? 1 : 0 + count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id name = "JFROG_IDE_ACCESS_TOKEN" value = data.coder_external_auth.jfrog.access_token } resource "coder_env" "jfrog_ide_store_connection" { - count = var.configure_code_server ? 1 : 0 + count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id name = "JFROG_IDE_STORE_CONNECTION" value = true diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index ebcac53b..b20b0f2d 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -73,4 +73,4 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then fi else echo "🤔 CONFIGURE_CODE_SERVER is not set to true, skipping JFrog extension installation." -fi \ No newline at end of file +fi diff --git a/jfrog-token/README.md b/jfrog-token/README.md index 512c8634..3b66319b 100644 --- a/jfrog-token/README.md +++ b/jfrog-token/README.md @@ -14,15 +14,15 @@ Install the JF CLI and authenticate package managers with Artifactory using Arti ```hcl module "jfrog" { - source = "https://registry.coder.com/modules/jfrog-token" - agent_id = coder_agent.example.id - jfrog_url = "https://XXXX.jfrog.io" - artifactory_access_token = var.artifactory_access_token - package_managers = { - "npm": "npm", - "go": "go", - "pypi": "pypi" - } + source = "https://registry.coder.com/modules/jfrog-token" + agent_id = coder_agent.example.id + jfrog_url = "https://XXXX.jfrog.io" + artifactory_access_token = var.artifactory_access_token + package_managers = { + "npm": "npm", + "go": "go", + "pypi": "pypi" + } } ``` @@ -30,8 +30,8 @@ Get a JFrog access token from your Artifactory instance. The token must be an [a ```hcl variable "artifactory_access_token" { - type = string - sensitive = true + type = string + sensitive = true } ``` @@ -43,15 +43,15 @@ variable "artifactory_access_token" { ```hcl module "jfrog" { - source = "https://registry.coder.com/modules/jfrog-token" - agent_id = coder_agent.example.id - jfrog_url = "https://YYYY.jfrog.io" - artifactory_access_token = var.artifactory_access_token # An admin access token - package_managers = { - "npm": "npm-local", - "go": "go-local", - "pypi": "pypi-local" - } + source = "https://registry.coder.com/modules/jfrog-token" + agent_id = coder_agent.example.id + jfrog_url = "https://YYYY.jfrog.io" + artifactory_access_token = var.artifactory_access_token # An admin access token + package_managers = { + "npm": "npm-local", + "go": "go-local", + "pypi": "pypi-local" + } } ``` @@ -69,6 +69,25 @@ go get github.com/golang/example/hello pip install requests ``` +### Configure code-server with JFrog extension + +The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extension) for VS Code allows you to interact with Artifactory from within the IDE. + +```hcl +module "jfrog" { + source = "https://registry.coder.com/modules/jfrog-token" + agent_id = coder_agent.example.id + jfrog_url = "https://XXXX.jfrog.io" + artifactory_access_token = var.artifactory_access_token + configure_code_server = true + package_managers = { + "npm": "npm",Add JFrog extension configuration for code-server + "go": "go", + "pypi": "pypi" + } +} +``` + ### Using the access token in other terraform resources JFrog Access token is also available as a terraform output. You can use it in other terraform resources. For example, you can use it to configure an [Artifactory docker registry](https://jfrog.com/help/r/jfrog-artifactory-documentation/docker-registry) with the [docker terraform provider](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs). From 902b382843b72ccc71ae28322305a9df190bfd59 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Dec 2023 18:50:42 +0300 Subject: [PATCH 04/52] update JFrog Token module --- jfrog-token/main.tf | 44 +++++++++++++++++++++++++++++++++++++++++++- jfrog-token/run.sh | 18 ++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index d9aa55ff..9ea0c20d 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -4,7 +4,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = ">= 0.12" + version = ">= 0.12.4" } artifactory = { source = "registry.terraform.io/jfrog/artifactory" @@ -56,6 +56,12 @@ variable "agent_id" { description = "The ID of a Coder agent." } +variable "configure_code_server" { + type = bool + description = "Whether to configure code-server to use JFrog." + default = false +} + variable "package_managers" { type = map(string) description = < /dev/null 2>&1; then + echo "📦 Installing JFrog extension..." + code-server --install-extension jfrog.jfrog-vscode-extension + echo "🥳 JFrog extension installed!" + elif command /tmp/coder-server/bin/code-server > /dev/null 2>&1; then + echo "📦 Installing JFrog extension..." + /tmp/coder-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension + echo "🥳 JFrog extension installed!" + else + echo "🤔 code-server is not installed, skipping JFrog extension installation." + fi +else + echo "🤔 CONFIGURE_CODE_SERVER is not set to true, skipping JFrog extension installation." +fi From cf60e2064fe8c8e70a7099b6d9cb8f292cb517e5 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Dec 2023 18:52:09 +0300 Subject: [PATCH 05/52] fixup! --- jfrog-oauth/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/README.md b/jfrog-oauth/README.md index 3827e2ea..12bf3b42 100644 --- a/jfrog-oauth/README.md +++ b/jfrog-oauth/README.md @@ -60,7 +60,7 @@ jf pip install requests pip install requests ``` -### Configure code-server to with JFrog extension +### Configure code-server with JFrog extension The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extension) for VS Code allows you to interact with Artifactory from within the IDE. @@ -73,7 +73,7 @@ module "jfrog" { username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" configure_code_server = true package_managers = { - "npm": "npm", + "npm": "npm",Add JFrog extension configuration for code-server "go": "go", "pypi": "pypi" } From 68cbcd1721ba222f3695713c2064cc229c9fb486 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Dec 2023 18:53:56 +0300 Subject: [PATCH 06/52] update artifactory terraform provider --- jfrog-token/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index 9ea0c20d..cba86ba8 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -8,7 +8,7 @@ terraform { } artifactory = { source = "registry.terraform.io/jfrog/artifactory" - version = "~> 9.8.0" + version = "~> 10.0.2" } } } @@ -160,4 +160,4 @@ resource "coder_env" "jfrog_ide_store_connection" { agent_id = var.agent_id name = "JFROG_IDE_STORE_CONNECTION" value = true -} \ No newline at end of file +} From 44f9a1ec9adc5073b0a81f825a85bcc05433f1ea Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 26 Dec 2023 08:40:21 +0300 Subject: [PATCH 07/52] fix tests --- jfrog-token/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index cba86ba8..7aa1de0e 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -145,14 +145,14 @@ resource "coder_env" "jfrog_ide_password" { count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id name = "JFROG_IDE_PASSWORD" - value = data.coder_external_auth.jfrog.access_token + value = artifactory_scoped_token.me.access_token } resource "coder_env" "jfrog_ide_access_token" { count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id name = "JFROG_IDE_ACCESS_TOKEN" - value = data.coder_external_auth.jfrog.access_token + value = artifactory_scoped_token.me.access_token } resource "coder_env" "jfrog_ide_store_connection" { From 97a6613e25205bc0a71c721156a05b3910a17d63 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:07:21 +0300 Subject: [PATCH 08/52] Update README.md --- jfrog-oauth/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/jfrog-oauth/README.md b/jfrog-oauth/README.md index ce640d68..d9d285fd 100644 --- a/jfrog-oauth/README.md +++ b/jfrog-oauth/README.md @@ -21,7 +21,6 @@ module "jfrog" { source = "https://registry.coder.com/modules/jfrog-oauth" agent_id = coder_agent.example.id jfrog_url = "https://jfrog.example.com" - auth_method = "oauth" username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" package_managers = { "npm": "npm", @@ -115,7 +114,6 @@ module "jfrog" { source = "https://registry.coder.com/modules/jfrog-oauth" agent_id = coder_agent.example.id jfrog_url = "https://jfrog.example.com" - auth_method = "oauth" username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" configure_code_server = true package_managers = { From c6d8f39a838ddd93bce92e1a277005d3c9700952 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:09:30 +0300 Subject: [PATCH 09/52] Update run.sh --- jfrog-oauth/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index b20b0f2d..f6fb36ce 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -53,7 +53,6 @@ if [ -z "${REPOSITORY_GO}" ]; then else echo "🐹 Configuring go..." jf go-config --global --repo-resolve "${REPOSITORY_GO}" - export GOPROXY="https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/go/${REPOSITORY_GO}" fi echo "🥳 Configuration complete!" From eea0274078b5d72f39f8171ae07b9e3d4248e4ff Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:09:51 +0300 Subject: [PATCH 10/52] Update run.sh --- jfrog-token/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index b20b0f2d..f6fb36ce 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -53,7 +53,6 @@ if [ -z "${REPOSITORY_GO}" ]; then else echo "🐹 Configuring go..." jf go-config --global --repo-resolve "${REPOSITORY_GO}" - export GOPROXY="https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/go/${REPOSITORY_GO}" fi echo "🥳 Configuration complete!" From e36c28497def7bdf10efdf54a88b46c75e84723a Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:17:21 +0300 Subject: [PATCH 11/52] Update main.tf --- jfrog-oauth/main.tf | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 8af19abe..f26394e3 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -56,7 +56,8 @@ EOF locals { # The username field to use for artifactory - username = var.username_field == "email" ? data.coder_workspace.me.owner_email : data.coder_workspace.me.owner + username = var.username_field == "email" ? data.coder_workspace.me.owner_email : data.coder_workspace.me.owner + jfrog_host = replace(var.jfrog_url, "https://", "") } data "coder_workspace" "me" {} @@ -71,7 +72,7 @@ resource "coder_script" "jfrog" { icon = "/icon/jfrog.svg" script = templatefile("${path.module}/run.sh", { JFROG_URL : var.jfrog_url, - JFROG_HOST : replace(var.jfrog_url, "https://", ""), + JFROG_HOST : var.jfrog_host, ARTIFACTORY_USERNAME : local.username, ARTIFACTORY_EMAIL : data.coder_workspace.me.owner_email, ARTIFACTORY_ACCESS_TOKEN : data.coder_external_auth.jfrog.access_token, @@ -83,17 +84,6 @@ resource "coder_script" "jfrog" { run_on_start = true } -output "access_token" { - description = "value of the JFrog access token" - value = data.coder_external_auth.jfrog.access_token - sensitive = true -} - -output "username" { - description = "value of the JFrog username" - value = local.username -} - resource "coder_env" "jfrog_ide_url" { count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id @@ -127,4 +117,22 @@ resource "coder_env" "jfrog_ide_store_connection" { agent_id = var.agent_id name = "JFROG_IDE_STORE_CONNECTION" value = true -} \ No newline at end of file +} + +resource "coder_env" "go_proxy" { + count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 + agent_id = var.agent_id + name = "GOPROXY" + value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" +} + +output "access_token" { + description = "value of the JFrog access token" + value = data.coder_external_auth.jfrog.access_token + sensitive = true +} + +output "username" { + description = "value of the JFrog username" + value = local.username +} From d36b580d6cfd9b6af015039f5f8f1008308ef9ca Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:17:25 +0300 Subject: [PATCH 12/52] Update main.tf --- jfrog-token/main.tf | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index 7aa1de0e..37e7629d 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -77,7 +77,8 @@ EOF locals { # The username field to use for artifactory - username = var.username_field == "email" ? data.coder_workspace.me.owner_email : data.coder_workspace.me.owner + username = var.username_field == "email" ? data.coder_workspace.me.owner_email : data.coder_workspace.me.owner + jfrog_host = replace(var.jfrog_url, "https://", "") } # Configure the Artifactory provider @@ -104,7 +105,7 @@ resource "coder_script" "jfrog" { icon = "/icon/jfrog.svg" script = templatefile("${path.module}/run.sh", { JFROG_URL : var.jfrog_url, - JFROG_HOST : replace(var.jfrog_url, "https://", ""), + JFROG_HOST : var.jfrog_host, ARTIFACTORY_USERNAME : local.username, ARTIFACTORY_EMAIL : data.coder_workspace.me.owner_email, ARTIFACTORY_ACCESS_TOKEN : artifactory_scoped_token.me.access_token, @@ -116,17 +117,6 @@ resource "coder_script" "jfrog" { run_on_start = true } -output "access_token" { - description = "value of the JFrog access token" - value = artifactory_scoped_token.me.access_token - sensitive = true -} - -output "username" { - description = "value of the JFrog username" - value = local.username -} - resource "coder_env" "jfrog_ide_url" { count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id @@ -161,3 +151,21 @@ resource "coder_env" "jfrog_ide_store_connection" { name = "JFROG_IDE_STORE_CONNECTION" value = true } + +resource "coder_env" "go_proxy" { + count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 + agent_id = var.agent_id + name = "GOPROXY" + value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" +} + +output "access_token" { + description = "value of the JFrog access token" + value = artifactory_scoped_token.me.access_token + sensitive = true +} + +output "username" { + description = "value of the JFrog username" + value = local.username +} From 4a0fd4c1e4f4070acb8be02bf2146ce077215579 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:19:16 +0300 Subject: [PATCH 13/52] Update main.tf --- jfrog-oauth/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index f26394e3..92c4d499 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -72,7 +72,7 @@ resource "coder_script" "jfrog" { icon = "/icon/jfrog.svg" script = templatefile("${path.module}/run.sh", { JFROG_URL : var.jfrog_url, - JFROG_HOST : var.jfrog_host, + JFROG_HOST : local.jfrog_host, ARTIFACTORY_USERNAME : local.username, ARTIFACTORY_EMAIL : data.coder_workspace.me.owner_email, ARTIFACTORY_ACCESS_TOKEN : data.coder_external_auth.jfrog.access_token, @@ -123,7 +123,7 @@ resource "coder_env" "go_proxy" { count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 agent_id = var.agent_id name = "GOPROXY" - value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" + value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" } output "access_token" { From 7f9a6bc043405fe9255b2429fc45ef2981188b50 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:19:43 +0300 Subject: [PATCH 14/52] Update main.tf --- jfrog-token/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index 37e7629d..a740cdf2 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -105,7 +105,7 @@ resource "coder_script" "jfrog" { icon = "/icon/jfrog.svg" script = templatefile("${path.module}/run.sh", { JFROG_URL : var.jfrog_url, - JFROG_HOST : var.jfrog_host, + JFROG_HOST : local.jfrog_host, ARTIFACTORY_USERNAME : local.username, ARTIFACTORY_EMAIL : data.coder_workspace.me.owner_email, ARTIFACTORY_ACCESS_TOKEN : artifactory_scoped_token.me.access_token, @@ -156,7 +156,7 @@ resource "coder_env" "go_proxy" { count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 agent_id = var.agent_id name = "GOPROXY" - value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${var.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" + value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" } output "access_token" { From f6217774b0b0d82dbaf7e69e26bbf189fb855dd2 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:23:05 +0300 Subject: [PATCH 15/52] Update main.tf --- jfrog-oauth/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 92c4d499..9a07bd77 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -123,7 +123,7 @@ resource "coder_env" "go_proxy" { count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 agent_id = var.agent_id name = "GOPROXY" - value = "https://${local.username}:${artifactory_scoped_token.me.access_token}@${local.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" + value = "https://${local.username}:${data.coder_external_auth.jfrog.access_token}@${local.jfrog_host}/artifactory/api/go/${lookup(var.package_managers, "go", "")}" } output "access_token" { From ee43370dfd8a0a0cb4cc25171f02a5c698a320f4 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:41:29 +0300 Subject: [PATCH 16/52] Update JFrog extension installation message --- jfrog-oauth/run.sh | 3 +-- jfrog-token/run.sh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index f6fb36ce..9840e506 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -57,7 +57,6 @@ fi echo "🥳 Configuration complete!" # Install the JFrog vscode extension for code-server. -Check if CONFIGURE_CODE_SERVER is set to true if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then if command -v code-server > /dev/null 2>&1; then echo "📦 Installing JFrog extension..." @@ -71,5 +70,5 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then echo "🤔 code-server is not installed, skipping JFrog extension installation." fi else - echo "🤔 CONFIGURE_CODE_SERVER is not set to true, skipping JFrog extension installation." + echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index f6fb36ce..9840e506 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -57,7 +57,6 @@ fi echo "🥳 Configuration complete!" # Install the JFrog vscode extension for code-server. -Check if CONFIGURE_CODE_SERVER is set to true if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then if command -v code-server > /dev/null 2>&1; then echo "📦 Installing JFrog extension..." @@ -71,5 +70,5 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then echo "🤔 code-server is not installed, skipping JFrog extension installation." fi else - echo "🤔 CONFIGURE_CODE_SERVER is not set to true, skipping JFrog extension installation." + echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." fi From 955eadb9b1f2f23c9e57f5b43aa39a5ff4c0ab6f Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:42:42 +0300 Subject: [PATCH 17/52] Update code-server installation path --- jfrog-oauth/run.sh | 4 ++-- jfrog-token/run.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 9840e506..a27032e0 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -62,9 +62,9 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then echo "📦 Installing JFrog extension..." code-server --install-extension jfrog.jfrog-vscode-extension echo "🥳 JFrog extension installed!" - elif command /tmp/coder-server/bin/code-server > /dev/null 2>&1; then + elif command /tmp/code-server/bin/code-server > /dev/null 2>&1; then echo "📦 Installing JFrog extension..." - /tmp/coder-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension + /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension echo "🥳 JFrog extension installed!" else echo "🤔 code-server is not installed, skipping JFrog extension installation." diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 9840e506..a27032e0 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -62,9 +62,9 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then echo "📦 Installing JFrog extension..." code-server --install-extension jfrog.jfrog-vscode-extension echo "🥳 JFrog extension installed!" - elif command /tmp/coder-server/bin/code-server > /dev/null 2>&1; then + elif command /tmp/code-server/bin/code-server > /dev/null 2>&1; then echo "📦 Installing JFrog extension..." - /tmp/coder-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension + /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension echo "🥳 JFrog extension installed!" else echo "🤔 code-server is not installed, skipping JFrog extension installation." From 9cc2a37940953ee7e1ffbb59cbed19da265b604b Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 16:58:13 +0300 Subject: [PATCH 18/52] Update coder_env resource names for Go proxy --- jfrog-oauth/main.tf | 2 +- jfrog-token/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 9a07bd77..41a66d11 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -119,7 +119,7 @@ resource "coder_env" "jfrog_ide_store_connection" { value = true } -resource "coder_env" "go_proxy" { +resource "coder_env" "goproxy" { count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 agent_id = var.agent_id name = "GOPROXY" diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index a740cdf2..2f6edd9f 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -152,7 +152,7 @@ resource "coder_env" "jfrog_ide_store_connection" { value = true } -resource "coder_env" "go_proxy" { +resource "coder_env" "goproxy" { count = lookup(var.package_managers, "go", "") == "" ? 0 : 1 agent_id = var.agent_id name = "GOPROXY" From c0c8ac5c0f6e12b066bcfdae4bcc6f47ccfb3612 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 21:43:40 +0300 Subject: [PATCH 19/52] add wait --- jfrog-oauth/run.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index a27032e0..ecb0a5c2 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -47,7 +47,7 @@ index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_ EOF fi -# Set GOPROXY to use the Artifactory "go" repository. +# Configure Artifactory "go" repository. if [ -z "${REPOSITORY_GO}" ]; then echo "🤔 REPOSITORY_GO is not set, skipping go configuration." else @@ -58,17 +58,18 @@ echo "🥳 Configuration complete!" # Install the JFrog vscode extension for code-server. if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then - if command -v code-server > /dev/null 2>&1; then - echo "📦 Installing JFrog extension..." - code-server --install-extension jfrog.jfrog-vscode-extension - echo "🥳 JFrog extension installed!" - elif command /tmp/code-server/bin/code-server > /dev/null 2>&1; then - echo "📦 Installing JFrog extension..." - /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension - echo "🥳 JFrog extension installed!" - else - echo "🤔 code-server is not installed, skipping JFrog extension installation." - fi + while ! [ -x /tmp/code-server/bin/code-server ]; do + if [ $counter -eq 30 ]; then + echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." + exit 1 + fi + echo "Waiting for /tmp/code-server/bin/code-server to be installed..." + sleep 1 + ((counter++)) + done + echo "📦 Installing JFrog extension..." + /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension + echo "🥳 JFrog extension installed!" else echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." fi From 7b9302ec3599fb37693d66e4fb7a5cdcaba46c22 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 21:47:30 +0300 Subject: [PATCH 20/52] wait for code-server to be insatlled. --- jfrog-token/run.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index a27032e0..ecb0a5c2 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -47,7 +47,7 @@ index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_ EOF fi -# Set GOPROXY to use the Artifactory "go" repository. +# Configure Artifactory "go" repository. if [ -z "${REPOSITORY_GO}" ]; then echo "🤔 REPOSITORY_GO is not set, skipping go configuration." else @@ -58,17 +58,18 @@ echo "🥳 Configuration complete!" # Install the JFrog vscode extension for code-server. if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then - if command -v code-server > /dev/null 2>&1; then - echo "📦 Installing JFrog extension..." - code-server --install-extension jfrog.jfrog-vscode-extension - echo "🥳 JFrog extension installed!" - elif command /tmp/code-server/bin/code-server > /dev/null 2>&1; then - echo "📦 Installing JFrog extension..." - /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension - echo "🥳 JFrog extension installed!" - else - echo "🤔 code-server is not installed, skipping JFrog extension installation." - fi + while ! [ -x /tmp/code-server/bin/code-server ]; do + if [ $counter -eq 30 ]; then + echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." + exit 1 + fi + echo "Waiting for /tmp/code-server/bin/code-server to be installed..." + sleep 1 + ((counter++)) + done + echo "📦 Installing JFrog extension..." + /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension + echo "🥳 JFrog extension installed!" else echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." fi From cbd294d8484c814da1e6c4eea1f2b932c9a58c3f Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 21:52:52 +0300 Subject: [PATCH 21/52] fixup! --- jfrog-oauth/run.sh | 5 +++++ jfrog-token/run.sh | 1 + 2 files changed, 6 insertions(+) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index ecb0a5c2..ce5509f4 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -32,6 +32,10 @@ email = ${ARTIFACTORY_EMAIL} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF jf rt curl /api/npm/auth >> ~/.npmrc + # if npm version is greater than or equal to 9.0.0, use the new npmrc format + if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then + npm config fix + fi fi # Configure the `pip` to use the Artifactory "python" repository. @@ -59,6 +63,7 @@ echo "🥳 Configuration complete!" # Install the JFrog vscode extension for code-server. if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then while ! [ -x /tmp/code-server/bin/code-server ]; do + counter=0 if [ $counter -eq 30 ]; then echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." exit 1 diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index ecb0a5c2..178cbdcf 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -59,6 +59,7 @@ echo "🥳 Configuration complete!" # Install the JFrog vscode extension for code-server. if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then while ! [ -x /tmp/code-server/bin/code-server ]; do + counter=0 if [ $counter -eq 30 ]; then echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." exit 1 From 5694858959d9f89fb5ddfab5bf4f5a7abb5ca06d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Dec 2023 22:17:32 +0300 Subject: [PATCH 22/52] Update npm config fix command to use global flag --- jfrog-oauth/run.sh | 6 +++--- jfrog-token/run.sh | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index ce5509f4..cd08efc8 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -28,13 +28,13 @@ else jf npmc --global --repo-resolve "${REPOSITORY_NPM}" fi cat << EOF > ~/.npmrc -email = ${ARTIFACTORY_EMAIL} -registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} +email=${ARTIFACTORY_EMAIL} +registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF jf rt curl /api/npm/auth >> ~/.npmrc # if npm version is greater than or equal to 9.0.0, use the new npmrc format if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - npm config fix + npm config fix --global fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 178cbdcf..cd08efc8 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -28,10 +28,14 @@ else jf npmc --global --repo-resolve "${REPOSITORY_NPM}" fi cat << EOF > ~/.npmrc -email = ${ARTIFACTORY_EMAIL} -registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} +email=${ARTIFACTORY_EMAIL} +registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF jf rt curl /api/npm/auth >> ~/.npmrc + # if npm version is greater than or equal to 9.0.0, use the new npmrc format + if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then + npm config fix --global + fi fi # Configure the `pip` to use the Artifactory "python" repository. From b1f2cc74fa43d6b6038ac91f815a4e56e3d5e8ed Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 15:03:36 +0300 Subject: [PATCH 23/52] Update JFrog instance URL and package manager configurations --- jfrog-oauth/main.tf | 13 +++++++++---- jfrog-oauth/run.sh | 22 +++++++++++++--------- jfrog-token/main.tf | 14 ++++++++++---- jfrog-token/run.sh | 22 +++++++++++++--------- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 41a66d11..a6b6e561 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -11,7 +11,12 @@ terraform { variable "jfrog_url" { type = string - description = "JFrog instance URL. e.g. https://jfrog.example.com" + description = "JFrog instance URL. e.g. https://myartifactory.jfrog.io" + # ensue the URL is HTTPS or HTTP + validation { + condition = can(regex("^(https|http)://", var.jfrog_url)) + error_message = "jfrog_url must be a valid URL starting with either 'https://' or 'http://'" + } } variable "username_field" { @@ -47,9 +52,9 @@ variable "package_managers" { A map of package manager names to their respective artifactory repositories. For example: { - "npm": "npm-local", - "go": "go-local", - "pypi": "pypi-local" + "npm": "YOUR_NPM_REPO_KEY", + "go": "YOUR_GO_REPO_KEY", + "pypi": "YOUR_PYPI_REPO_KEY" } EOF } diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index cd08efc8..0e7459a5 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -7,7 +7,6 @@ if command -v jf > /dev/null 2>&1; then echo "✅ JFrog CLI is already installed, skipping installation." else echo "📦 Installing JFrog CLI..." - # Install the JFrog CLI. curl -fL https://install-cli.jfrog.io | sudo sh sudo chmod 755 /usr/local/bin/jf fi @@ -20,27 +19,31 @@ jf c rm 0 || true echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 if [ -z "${REPOSITORY_NPM}" ]; then - echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." + echo "🤔 no npm repository is set, skipping npm configuration." + echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." else # check if npm is installed and configure it to use the Artifactory "npm" repository. if command -v npm > /dev/null 2>&1; then echo "📦 Configuring npm..." jf npmc --global --repo-resolve "${REPOSITORY_NPM}" fi + # if npm version is greater than or equal to 9.0.0, use the new npmrc format cat << EOF > ~/.npmrc -email=${ARTIFACTORY_EMAIL} -registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} + email=${ARTIFACTORY_EMAIL} + registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF - jf rt curl /api/npm/auth >> ~/.npmrc - # if npm version is greater than or equal to 9.0.0, use the new npmrc format if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - npm config fix --global + echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + else + echo "_auth=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "always-auth=true" >> ~/.npmrc fi fi # Configure the `pip` to use the Artifactory "python" repository. if [ -z "${REPOSITORY_PYPI}" ]; then - echo "🤔 REPOSITORY_PYPI is not set, skipping pip configuration." + echo "🤔 no pypi repository is set, skipping pip configuration." + echo "You can configure a pypi repository by providing the a key for 'pypi' in the 'package_managers' input." else echo "🐍 Configuring pip..." jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" @@ -53,7 +56,8 @@ fi # Configure Artifactory "go" repository. if [ -z "${REPOSITORY_GO}" ]; then - echo "🤔 REPOSITORY_GO is not set, skipping go configuration." + echo "🤔 no go repository is set, skipping go configuration." + echo "You can configure a go repository by providing the a key for 'go' in the 'package_managers' input." else echo "🐹 Configuring go..." jf go-config --global --repo-resolve "${REPOSITORY_GO}" diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index 2f6edd9f..269bdca7 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -15,9 +15,15 @@ terraform { variable "jfrog_url" { type = string - description = "JFrog instance URL. e.g. https://YYY.jfrog.io" + description = "JFrog instance URL. e.g. https://myartifactory.jfrog.io" + # ensue the URL is HTTPS or HTTP + validation { + condition = can(regex("^(https|http)://", var.jfrog_url)) + error_message = "jfrog_url must be a valid URL starting with either 'https://' or 'http://'" + } } + variable "artifactory_access_token" { type = string description = "The admin-level access token to use for JFrog." @@ -68,9 +74,9 @@ variable "package_managers" { A map of package manager names to their respective artifactory repositories. For example: { - "npm": "npm-local", - "go": "go-local", - "pypi": "pypi-local" + "npm": "YOUR_NPM_REPO_KEY", + "go": "YOUR_GO_REPO_KEY", + "pypi": "YOUR_PYPI_REPO_KEY" } EOF } diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index cd08efc8..0e7459a5 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -7,7 +7,6 @@ if command -v jf > /dev/null 2>&1; then echo "✅ JFrog CLI is already installed, skipping installation." else echo "📦 Installing JFrog CLI..." - # Install the JFrog CLI. curl -fL https://install-cli.jfrog.io | sudo sh sudo chmod 755 /usr/local/bin/jf fi @@ -20,27 +19,31 @@ jf c rm 0 || true echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 if [ -z "${REPOSITORY_NPM}" ]; then - echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." + echo "🤔 no npm repository is set, skipping npm configuration." + echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." else # check if npm is installed and configure it to use the Artifactory "npm" repository. if command -v npm > /dev/null 2>&1; then echo "📦 Configuring npm..." jf npmc --global --repo-resolve "${REPOSITORY_NPM}" fi + # if npm version is greater than or equal to 9.0.0, use the new npmrc format cat << EOF > ~/.npmrc -email=${ARTIFACTORY_EMAIL} -registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} + email=${ARTIFACTORY_EMAIL} + registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF - jf rt curl /api/npm/auth >> ~/.npmrc - # if npm version is greater than or equal to 9.0.0, use the new npmrc format if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - npm config fix --global + echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + else + echo "_auth=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "always-auth=true" >> ~/.npmrc fi fi # Configure the `pip` to use the Artifactory "python" repository. if [ -z "${REPOSITORY_PYPI}" ]; then - echo "🤔 REPOSITORY_PYPI is not set, skipping pip configuration." + echo "🤔 no pypi repository is set, skipping pip configuration." + echo "You can configure a pypi repository by providing the a key for 'pypi' in the 'package_managers' input." else echo "🐍 Configuring pip..." jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" @@ -53,7 +56,8 @@ fi # Configure Artifactory "go" repository. if [ -z "${REPOSITORY_GO}" ]; then - echo "🤔 REPOSITORY_GO is not set, skipping go configuration." + echo "🤔 no go repository is set, skipping go configuration." + echo "You can configure a go repository by providing the a key for 'go' in the 'package_managers' input." else echo "🐹 Configuring go..." jf go-config --global --repo-resolve "${REPOSITORY_GO}" From 489fcd12e7d053719888d10fd7df80631ff24804 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 15:27:24 +0300 Subject: [PATCH 24/52] fix formatting of .npmrc --- jfrog-oauth/run.sh | 4 ++-- jfrog-token/run.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 0e7459a5..4bd5139c 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -29,8 +29,8 @@ else fi # if npm version is greater than or equal to 9.0.0, use the new npmrc format cat << EOF > ~/.npmrc - email=${ARTIFACTORY_EMAIL} - registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} +email=${ARTIFACTORY_EMAIL} +registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 0e7459a5..4bd5139c 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -29,8 +29,8 @@ else fi # if npm version is greater than or equal to 9.0.0, use the new npmrc format cat << EOF > ~/.npmrc - email=${ARTIFACTORY_EMAIL} - registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} +email=${ARTIFACTORY_EMAIL} +registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc From 5b1337e96eb909070092f7307f1a2bfb31872d46 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 15:29:58 +0300 Subject: [PATCH 25/52] fixup! --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 4bd5139c..f550474e 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -33,7 +33,7 @@ email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc else echo "_auth=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc echo "always-auth=true" >> ~/.npmrc diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 4bd5139c..e2c37784 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -30,7 +30,7 @@ else # if npm version is greater than or equal to 9.0.0, use the new npmrc format cat << EOF > ~/.npmrc email=${ARTIFACTORY_EMAIL} -registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} +registry=${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc From 963d4d6a3e5089cc8b06e7e0260e23c36135147d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 15:30:29 +0300 Subject: [PATCH 26/52] fixup! --- jfrog-token/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index e2c37784..f550474e 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -30,10 +30,10 @@ else # if npm version is greater than or equal to 9.0.0, use the new npmrc format cat << EOF > ~/.npmrc email=${ARTIFACTORY_EMAIL} -registry=${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM} +registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc else echo "_auth=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc echo "always-auth=true" >> ~/.npmrc From c289810c784acc9976f13b6f4f1e030032c2e3c4 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 16:51:11 +0300 Subject: [PATCH 27/52] use token from `jf rt curl /api/npm/auth` --- jfrog-oauth/run.sh | 4 ++-- jfrog-token/run.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index f550474e..fe4b9b42 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -33,9 +33,9 @@ email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc else - echo "_auth=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "_auth=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc echo "always-auth=true" >> ~/.npmrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index f550474e..fe4b9b42 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -33,9 +33,9 @@ email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc else - echo "_auth=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc + echo "_auth=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc echo "always-auth=true" >> ~/.npmrc fi fi From 7d857838c2d80a334a5b06e22eec0b732e0b5ee1 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 17:03:49 +0300 Subject: [PATCH 28/52] Update 'jf go-config' command to 'jf goc' --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index fe4b9b42..4307373f 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -60,7 +60,7 @@ if [ -z "${REPOSITORY_GO}" ]; then echo "You can configure a go repository by providing the a key for 'go' in the 'package_managers' input." else echo "🐹 Configuring go..." - jf go-config --global --repo-resolve "${REPOSITORY_GO}" + jf goc --global --repo-resolve "${REPOSITORY_GO}" fi echo "🥳 Configuration complete!" diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index fe4b9b42..4307373f 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -60,7 +60,7 @@ if [ -z "${REPOSITORY_GO}" ]; then echo "You can configure a go repository by providing the a key for 'go' in the 'package_managers' input." else echo "🐹 Configuring go..." - jf go-config --global --repo-resolve "${REPOSITORY_GO}" + jf goc --global --repo-resolve "${REPOSITORY_GO}" fi echo "🥳 Configuration complete!" From 168e20d5dc8a6a853a9c4721bb849ebf28dd7a3d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 28 Dec 2023 17:26:41 +0300 Subject: [PATCH 29/52] Update authentication in run.sh scripts --- jfrog-oauth/run.sh | 4 ++-- jfrog-token/run.sh | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 4307373f..7fdd6f4a 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -33,9 +33,9 @@ email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc else - echo "_auth=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc + echo "_auth=$(echo -n '${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}' | base64)" >> ~/.npmrc echo "always-auth=true" >> ~/.npmrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 4307373f..3dd57d19 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -33,13 +33,12 @@ email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc else - echo "_auth=$(jf rt curl /api/npm/auth | awk -F'= ' '/_auth =/{print $2}')" >> ~/.npmrc + echo "_auth=$(echo -n '${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}' | base64)" >> ~/.npmrc echo "always-auth=true" >> ~/.npmrc fi fi - # Configure the `pip` to use the Artifactory "python" repository. if [ -z "${REPOSITORY_PYPI}" ]; then echo "🤔 no pypi repository is set, skipping pip configuration." From 66891144c5f5e53dc9c20be29779c6cb86a72d9f Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 12:32:24 +0300 Subject: [PATCH 30/52] Add Docker repository configuration --- jfrog-oauth/main.tf | 18 +++--------------- jfrog-oauth/run.sh | 29 ++++++++++++++++++++++------- jfrog-token/main.tf | 18 +++--------------- jfrog-token/run.sh | 28 ++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index a6b6e561..044fc8fb 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -54,7 +54,8 @@ For example: { "npm": "YOUR_NPM_REPO_KEY", "go": "YOUR_GO_REPO_KEY", - "pypi": "YOUR_PYPI_REPO_KEY" + "pypi": "YOUR_PYPI_REPO_KEY", + "docker": "YOUR_DOCKER_REPO_KEY" } EOF } @@ -85,6 +86,7 @@ resource "coder_script" "jfrog" { REPOSITORY_NPM : lookup(var.package_managers, "npm", ""), REPOSITORY_GO : lookup(var.package_managers, "go", ""), REPOSITORY_PYPI : lookup(var.package_managers, "pypi", ""), + REPOSITORY_DOCKER : lookup(var.package_managers, "docker", ""), }) run_on_start = true } @@ -96,20 +98,6 @@ resource "coder_env" "jfrog_ide_url" { value = var.jfrog_url } -resource "coder_env" "jfrog_ide_username" { - count = var.configure_code_server ? 1 : 0 - agent_id = var.agent_id - name = "JFROG_IDE_USERNAME" - value = local.username -} - -resource "coder_env" "jfrog_ide_password" { - count = var.configure_code_server ? 1 : 0 - agent_id = var.agent_id - name = "JFROG_IDE_PASSWORD" - value = data.coder_external_auth.jfrog.access_token -} - resource "coder_env" "jfrog_ide_access_token" { count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 7fdd6f4a..dbd9cdc4 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -22,16 +22,13 @@ if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 no npm repository is set, skipping npm configuration." echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." else - # check if npm is installed and configure it to use the Artifactory "npm" repository. - if command -v npm > /dev/null 2>&1; then - echo "📦 Configuring npm..." - jf npmc --global --repo-resolve "${REPOSITORY_NPM}" - fi - # if npm version is greater than or equal to 9.0.0, use the new npmrc format + echo "📦 Configuring npm..." + jf npmc --global --repo-resolve "${REPOSITORY_NPM}" cat << EOF > ~/.npmrc email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF + # if npm version is greater than or equal to 9.0.0, use the new .npmrc format if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc else @@ -45,7 +42,7 @@ if [ -z "${REPOSITORY_PYPI}" ]; then echo "🤔 no pypi repository is set, skipping pip configuration." echo "You can configure a pypi repository by providing the a key for 'pypi' in the 'package_managers' input." else - echo "🐍 Configuring pip..." + echo "📦 Configuring pip..." jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" mkdir -p ~/.pip cat << EOF > ~/.pip/pip.conf @@ -64,6 +61,24 @@ else fi echo "🥳 Configuration complete!" +# Configure the JFrog CLI to use the Artifactory "docker" repository. +if [ -z "${REPOSITORY_DOCKER}" ]; then + echo "🤔 no docker repository is set, skipping docker configuration." + echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." +else + echo "🐳 Configuring docker..." + mkdir -p ~/.docker + cat << EOF > ~/.docker/config.json +{ + "auths": { + "${JFROG_HOST}": { + "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)" + } + } +} +EOF +fi + # Install the JFrog vscode extension for code-server. if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then while ! [ -x /tmp/code-server/bin/code-server ]; do diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index 269bdca7..c0183529 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -76,7 +76,8 @@ For example: { "npm": "YOUR_NPM_REPO_KEY", "go": "YOUR_GO_REPO_KEY", - "pypi": "YOUR_PYPI_REPO_KEY" + "pypi": "YOUR_PYPI_REPO_KEY", + "docker": "YOUR_DOCKER_REPO_KEY" } EOF } @@ -119,6 +120,7 @@ resource "coder_script" "jfrog" { REPOSITORY_NPM : lookup(var.package_managers, "npm", ""), REPOSITORY_GO : lookup(var.package_managers, "go", ""), REPOSITORY_PYPI : lookup(var.package_managers, "pypi", ""), + REPOSITORY_DOCKER : lookup(var.package_managers, "docker", ""), }) run_on_start = true } @@ -130,20 +132,6 @@ resource "coder_env" "jfrog_ide_url" { value = var.jfrog_url } -resource "coder_env" "jfrog_ide_username" { - count = var.configure_code_server ? 1 : 0 - agent_id = var.agent_id - name = "JFROG_IDE_USERNAME" - value = local.username -} - -resource "coder_env" "jfrog_ide_password" { - count = var.configure_code_server ? 1 : 0 - agent_id = var.agent_id - name = "JFROG_IDE_PASSWORD" - value = artifactory_scoped_token.me.access_token -} - resource "coder_env" "jfrog_ide_access_token" { count = var.configure_code_server ? 1 : 0 agent_id = var.agent_id diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 3dd57d19..bac8a7d8 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -22,16 +22,13 @@ if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 no npm repository is set, skipping npm configuration." echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." else - # check if npm is installed and configure it to use the Artifactory "npm" repository. - if command -v npm > /dev/null 2>&1; then - echo "📦 Configuring npm..." - jf npmc --global --repo-resolve "${REPOSITORY_NPM}" - fi - # if npm version is greater than or equal to 9.0.0, use the new npmrc format + echo "📦 Configuring npm..." + jf npmc --global --repo-resolve "${REPOSITORY_NPM}" cat << EOF > ~/.npmrc email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF + # if npm version is greater than or equal to 9.0.0, use the new npmrc format if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc else @@ -39,6 +36,7 @@ EOF echo "always-auth=true" >> ~/.npmrc fi fi + # Configure the `pip` to use the Artifactory "python" repository. if [ -z "${REPOSITORY_PYPI}" ]; then echo "🤔 no pypi repository is set, skipping pip configuration." @@ -63,6 +61,24 @@ else fi echo "🥳 Configuration complete!" +# Configure the JFrog CLI to use the Artifactory "docker" repository. +if [ -z "${REPOSITORY_DOCKER}" ]; then + echo "🤔 no docker repository is set, skipping docker configuration." + echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." +else + echo "🐳 Configuring docker..." + mkdir -p ~/.docker + cat << EOF > ~/.docker/config.json +{ + "auths": { + "${JFROG_HOST}": { + "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)" + } + } +} +EOF +fi + # Install the JFrog vscode extension for code-server. if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then while ! [ -x /tmp/code-server/bin/code-server ]; do From 04c2bcbfd59d56f6c3598aecefd1db463d866c08 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 12:59:09 +0300 Subject: [PATCH 31/52] Add JFrog CLI completion to shell profile --- jfrog-oauth/run.sh | 11 +++++++++++ jfrog-token/run.sh | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index dbd9cdc4..cf3473bc 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -97,3 +97,14 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then else echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." fi + +# Configure the JFrog CLI completion +echo "📦 Configuring JFrog CLI completion..." +jf completion $SHELL --install +# Append the completion script to the shell profile if its bash or zsh if it isn't already there. +if [ "$SHELL" = "/bin/bash" ] || [ "$SHELL" = "/bin/zsh" ]; then + if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELL}_completion" ~/.$${SHELL}rc; then + echo "📦 Adding JFrog CLI completion to shell profile..." + echo "source $HOME/.jfrog/jfrog_$${SHELL}_completion" >> ~/.$${SHELL}rc + fi +fi \ No newline at end of file diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index bac8a7d8..ba11550d 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -97,3 +97,15 @@ if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then else echo "🤔 Skipping JFrog extension installation. Set configure_code_server to true to install the JFrog extension." fi + +# Configure the JFrog CLI completion +echo "📦 Configuring JFrog CLI completion..." +jf completion $SHELL --install +# Append the completion script to the shell profile if its bash or zsh if it isn't already there. +if [ "$SHELL" = "/bin/bash" ] || [ "$SHELL" = "/bin/zsh" ]; then + if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELL}_completion" ~/.$${SHELL}rc; then + echo "📦 Adding JFrog CLI completion to shell profile..." + echo "source $HOME/.jfrog/jfrog_$${SHELL}_completion" >> ~/.$${SHELL}rc + fi +fi + From f5a73109ca50125685fdf7ac09d099c5b274502b Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 13:07:33 +0300 Subject: [PATCH 32/52] Refactor JFrog CLI completion configuration --- jfrog-oauth/run.sh | 9 ++++----- jfrog-token/run.sh | 9 +++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index cf3473bc..a2c5255b 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -101,10 +101,9 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." jf completion $SHELL --install -# Append the completion script to the shell profile if its bash or zsh if it isn't already there. -if [ "$SHELL" = "/bin/bash" ] || [ "$SHELL" = "/bin/zsh" ]; then - if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELL}_completion" ~/.$${SHELL}rc; then - echo "📦 Adding JFrog CLI completion to shell profile..." - echo "source $HOME/.jfrog/jfrog_$${SHELL}_completion" >> ~/.$${SHELL}rc +SHELLNAME=$(basename $SHELL) +if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then + if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then + echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc fi fi \ No newline at end of file diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index ba11550d..40658d0c 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -101,11 +101,8 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." jf completion $SHELL --install -# Append the completion script to the shell profile if its bash or zsh if it isn't already there. -if [ "$SHELL" = "/bin/bash" ] || [ "$SHELL" = "/bin/zsh" ]; then - if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELL}_completion" ~/.$${SHELL}rc; then - echo "📦 Adding JFrog CLI completion to shell profile..." - echo "source $HOME/.jfrog/jfrog_$${SHELL}_completion" >> ~/.$${SHELL}rc +if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then + if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then + echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc fi fi - From 268bfe4fb11c29948baebcc650b9597241d01d7d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 13:19:29 +0300 Subject: [PATCH 33/52] fixup!: JFrog CLI completion installation --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index a2c5255b..9366df37 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -100,8 +100,8 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -jf completion $SHELL --install SHELLNAME=$(basename $SHELL) +jf completion $SHELLNAME --install if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 40658d0c..2e43bd5a 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -100,7 +100,8 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -jf completion $SHELL --install +SHELLNAME=$(basename $SHELL) +jf completion $SHELLNAME --install if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc From ac9afb29bee1ced84ed2b9d075a5fb1797673109 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 13:20:15 +0300 Subject: [PATCH 34/52] Fix shell completion in run.sh --- jfrog-oauth/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 9366df37..ea8d0392 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -106,4 +106,4 @@ if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc fi -fi \ No newline at end of file +fi From cd278835ae8999dce8c0511f855053501570a6cd Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 13:24:31 +0300 Subject: [PATCH 35/52] Update JFrog cli configuration to include --overwrite --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index ea8d0392..2b24d9e1 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -16,7 +16,7 @@ fi export CI=true # Authenticate with the JFrog CLI. jf c rm 0 || true -echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 +echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" --overwrite 0 if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 no npm repository is set, skipping npm configuration." diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 2e43bd5a..77be1e83 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -16,7 +16,7 @@ fi export CI=true # Authenticate with the JFrog CLI. jf c rm 0 || true -echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 +echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" --overwrite 0 if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 no npm repository is set, skipping npm configuration." From 740b3fe9cd96fb3f313ba8a2368a388f5f1ec146 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 13:28:27 +0300 Subject: [PATCH 36/52] Update JFrog CLI authentication and npm configuration --- jfrog-oauth/run.sh | 6 ++++-- jfrog-token/run.sh | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 2b24d9e1..ff0e1e0d 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -14,10 +14,12 @@ fi # The jf CLI checks $CI when determining whether to use interactive # flows. export CI=true -# Authenticate with the JFrog CLI. -jf c rm 0 || true +# Authenticate JFrog CLI with Artifactory. echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" --overwrite 0 +# Set the configured server as the default. +jf c use 0 +# Configure npm to use the Artifactory "npm" repository. if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 no npm repository is set, skipping npm configuration." echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 77be1e83..439430c6 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -14,10 +14,12 @@ fi # The jf CLI checks $CI when determining whether to use interactive # flows. export CI=true -# Authenticate with the JFrog CLI. -jf c rm 0 || true +# Authenticate JFrog CLI with Artifactory. echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" --overwrite 0 +# Set the configured server as the default. +jf c use 0 +# Configure npm to use the Artifactory "npm" repository. if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 no npm repository is set, skipping npm configuration." echo "You can configure an npm repository by providing the a key for 'npm' in the 'package_managers' input." From e85607f18cf1a11b9d0c546f22049fcd343b9f79 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 13:37:04 +0300 Subject: [PATCH 37/52] Update JFrog CLI completion configuration to get the default shell --- jfrog-oauth/run.sh | 5 ++++- jfrog-token/run.sh | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index ff0e1e0d..678665b0 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -102,8 +102,11 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -SHELLNAME=$(basename $SHELL) +## Get the user's shell +SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') +## Generate the completion script jf completion $SHELLNAME --install +## Add the completion script to the user's shell profile if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 439430c6..ed3eb9c0 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -102,8 +102,11 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -SHELLNAME=$(basename $SHELL) +## Get the user's shell +SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') +## Generate the completion script jf completion $SHELLNAME --install +## Add the completion script to the user's shell profile if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc From d9a25fa66bded2b2a99bf08ed5471434489fb092 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 1 Jan 2024 14:25:56 +0300 Subject: [PATCH 38/52] Remove unnecessary blank line in main.tf --- jfrog-token/main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index c0183529..ead609a1 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -23,7 +23,6 @@ variable "jfrog_url" { } } - variable "artifactory_access_token" { type = string description = "The admin-level access token to use for JFrog." From 5d544924b3bbd8c463267c941af91a9f0d006511 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 04:47:06 +0300 Subject: [PATCH 39/52] Add email field to JFrog OAuth and JFrog Token run scripts --- jfrog-oauth/run.sh | 3 ++- jfrog-token/run.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 678665b0..85e8f61c 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -74,7 +74,8 @@ else { "auths": { "${JFROG_HOST}": { - "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)" + "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)", + "email": "${ARTIFACTORY_EMAIL}" } } } diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index ed3eb9c0..9dd71bfd 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -74,7 +74,8 @@ else { "auths": { "${JFROG_HOST}": { - "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)" + "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)", + "email": "${ARTIFACTORY_EMAIL}" } } } From a9baa1f4688aad95b4b8eeea9f2e9ef51326df4e Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 05:38:00 +0300 Subject: [PATCH 40/52] Add shell completion support for jf CLI --- jfrog-oauth/run.sh | 16 +++++++++++++--- jfrog-token/run.sh | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 85e8f61c..e18b303a 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -108,8 +108,18 @@ SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{pri ## Generate the completion script jf completion $SHELLNAME --install ## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then - if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then - echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc +if [ "$SHELLNAME" == "bash" ]; then + if ! grep -q "# jf CLI shell completion" ~/.bashrc; then + echo "# jf CLI shell completion" >> ~/.bashrc + echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc + echo "# end jf CLI shell completion" >> ~/.bashrc + fi +elif [ "$SHELLNAME" == "zsh" ]; then + if ! grep -q "# jf CLI shell completion" ~/.zshrc; then + echo "# jf CLI shell completion" >> ~/.zshrc + echo "autoload -Uz compinit" >> ~/.zshrc + echo "compinit" >> ~/.zshrc + echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc + echo "# end jf CLI shell completion" >> ~/.zshrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 9dd71bfd..bf9c4360 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -108,8 +108,18 @@ SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{pri ## Generate the completion script jf completion $SHELLNAME --install ## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then - if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then - echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc +if [ "$SHELLNAME" == "bash" ]; then + if ! grep -q "# jf CLI shell completion" ~/.bashrc; then + echo "# jf CLI shell completion" >> ~/.bashrc + echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc + echo "# end jf CLI shell completion" >> ~/.bashrc + fi +elif [ "$SHELLNAME" == "zsh" ]; then + if ! grep -q "# jf CLI shell completion" ~/.zshrc; then + echo "# jf CLI shell completion" >> ~/.zshrc + echo "autoload -Uz compinit" >> ~/.zshrc + echo "compinit" >> ~/.zshrc + echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc + echo "# end jf CLI shell completion" >> ~/.zshrc fi fi From 3308bf1c6b203d9582de6dcca1adb5b68ddeb72b Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 05:44:29 +0300 Subject: [PATCH 41/52] refactor --- jfrog-oauth/run.sh | 6 ++++-- jfrog-token/run.sh | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index e18b303a..976d07b2 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -110,16 +110,18 @@ jf completion $SHELLNAME --install ## Add the completion script to the user's shell profile if [ "$SHELLNAME" == "bash" ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then + echo "" >> ~/.bashrc echo "# jf CLI shell completion" >> ~/.bashrc echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc - echo "# end jf CLI shell completion" >> ~/.bashrc + echo "# End jf CLI shell completion" >> ~/.bashrc fi elif [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then + echo "" >> ~/.zshrc echo "# jf CLI shell completion" >> ~/.zshrc echo "autoload -Uz compinit" >> ~/.zshrc echo "compinit" >> ~/.zshrc echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc - echo "# end jf CLI shell completion" >> ~/.zshrc + echo "# End jf CLI shell completion" >> ~/.zshrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index bf9c4360..ba516d13 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -110,16 +110,18 @@ jf completion $SHELLNAME --install ## Add the completion script to the user's shell profile if [ "$SHELLNAME" == "bash" ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then + echo "" >> ~/.bashrc echo "# jf CLI shell completion" >> ~/.bashrc echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc - echo "# end jf CLI shell completion" >> ~/.bashrc + echo "# End jf CLI shell completion" >> ~/.bashrc fi elif [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then + echo "" >> ~/.zshrc echo "# jf CLI shell completion" >> ~/.zshrc echo "autoload -Uz compinit" >> ~/.zshrc echo "compinit" >> ~/.zshrc echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc - echo "# end jf CLI shell completion" >> ~/.zshrc + echo "# End jf CLI shell completion" >> ~/.zshrc fi fi From b1e182f1521cdc5f8818a28414fef4f9a5c59662 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 13:04:09 +0300 Subject: [PATCH 42/52] suggestions from review --- jfrog-oauth/README.md | 4 ++-- jfrog-oauth/main.tf | 2 +- jfrog-token/README.md | 4 ++-- jfrog-token/main.tf | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jfrog-oauth/README.md b/jfrog-oauth/README.md index d9d285fd..663c8ff8 100644 --- a/jfrog-oauth/README.md +++ b/jfrog-oauth/README.md @@ -115,9 +115,9 @@ module "jfrog" { agent_id = coder_agent.example.id jfrog_url = "https://jfrog.example.com" username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" - configure_code_server = true + configure_code_server = true # Add JFrog extension configuration for code-server package_managers = { - "npm": "npm",Add JFrog extension configuration for code-server + "npm": "npm", "go": "go", "pypi": "pypi" } diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index 044fc8fb..ea9f59b8 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -42,7 +42,7 @@ variable "agent_id" { variable "configure_code_server" { type = bool - description = "Whether to configure code-server to use JFrog." + description = "Set to true to configure code-server to use JFrog." default = false } diff --git a/jfrog-token/README.md b/jfrog-token/README.md index 5c989e58..94a7ff9c 100644 --- a/jfrog-token/README.md +++ b/jfrog-token/README.md @@ -82,9 +82,9 @@ module "jfrog" { agent_id = coder_agent.example.id jfrog_url = "https://XXXX.jfrog.io" artifactory_access_token = var.artifactory_access_token - configure_code_server = true + configure_code_server = true # Add JFrog extension configuration for code-server package_managers = { - "npm": "npm",Add JFrog extension configuration for code-server + "npm": "npm", "go": "go", "pypi": "pypi" } diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index ead609a1..67fb9a88 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -63,7 +63,7 @@ variable "agent_id" { variable "configure_code_server" { type = bool - description = "Whether to configure code-server to use JFrog." + description = "Set to true to configure code-server to use JFrog." default = false } From f2ebcf02c523ef327e7e10e710101da332b97e1f Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 13:26:08 +0300 Subject: [PATCH 43/52] `fmt` --- jfrog-oauth/main.tf | 2 +- jfrog-token/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/main.tf b/jfrog-oauth/main.tf index ea9f59b8..9f05e56a 100644 --- a/jfrog-oauth/main.tf +++ b/jfrog-oauth/main.tf @@ -42,7 +42,7 @@ variable "agent_id" { variable "configure_code_server" { type = bool - description = "Set to true to configure code-server to use JFrog." + description = "Set to true to configure code-server to use JFrog." default = false } diff --git a/jfrog-token/main.tf b/jfrog-token/main.tf index 67fb9a88..7e63649d 100644 --- a/jfrog-token/main.tf +++ b/jfrog-token/main.tf @@ -63,7 +63,7 @@ variable "agent_id" { variable "configure_code_server" { type = bool - description = "Set to true to configure code-server to use JFrog." + description = "Set to true to configure code-server to use JFrog." default = false } From b53e2d870f2d44557d696c14cb92c3d3c4d0b458 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 13:36:10 +0300 Subject: [PATCH 44/52] more suggestions --- jfrog-oauth/run.sh | 12 ++++++------ jfrog-token/run.sh | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 976d07b2..3456d72a 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -111,17 +111,17 @@ jf completion $SHELLNAME --install if [ "$SHELLNAME" == "bash" ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then echo "" >> ~/.bashrc - echo "# jf CLI shell completion" >> ~/.bashrc - echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc - echo "# End jf CLI shell completion" >> ~/.bashrc + echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.bashrc + echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc + echo "# END: jf CLI shell completion" >> ~/.bashrc fi elif [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then echo "" >> ~/.zshrc - echo "# jf CLI shell completion" >> ~/.zshrc + echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.zshrc echo "autoload -Uz compinit" >> ~/.zshrc echo "compinit" >> ~/.zshrc - echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc - echo "# End jf CLI shell completion" >> ~/.zshrc + echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.zshrc + echo "# END: jf CLI shell completion" >> ~/.zshrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index ba516d13..88968c29 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -111,17 +111,17 @@ jf completion $SHELLNAME --install if [ "$SHELLNAME" == "bash" ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then echo "" >> ~/.bashrc - echo "# jf CLI shell completion" >> ~/.bashrc - echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc - echo "# End jf CLI shell completion" >> ~/.bashrc + echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.bashrc + echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc + echo "# END: jf CLI shell completion" >> ~/.bashrc fi elif [ "$SHELLNAME" == "zsh" ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then echo "" >> ~/.zshrc - echo "# jf CLI shell completion" >> ~/.zshrc + echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.zshrc echo "autoload -Uz compinit" >> ~/.zshrc echo "compinit" >> ~/.zshrc - echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc - echo "# End jf CLI shell completion" >> ~/.zshrc + echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.zshrc + echo "# END: jf CLI shell completion" >> ~/.zshrc fi fi From 171fb357cb8140698b38637c5cfb42d2d445ab5d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 13:44:33 +0300 Subject: [PATCH 45/52] simplify npm authentication --- jfrog-oauth/run.sh | 8 +------- jfrog-token/run.sh | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 3456d72a..376e27be 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -30,13 +30,7 @@ else email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF - # if npm version is greater than or equal to 9.0.0, use the new .npmrc format - if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc - else - echo "_auth=$(echo -n '${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}' | base64)" >> ~/.npmrc - echo "always-auth=true" >> ~/.npmrc - fi + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc fi # Configure the `pip` to use the Artifactory "python" repository. diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 88968c29..627d8569 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -30,13 +30,7 @@ else email=${ARTIFACTORY_EMAIL} registry=${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} EOF - # if npm version is greater than or equal to 9.0.0, use the new npmrc format - if [ "$(npm --version | cut -d. -f1)" -ge 9 ]; then - echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc - else - echo "_auth=$(echo -n '${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}' | base64)" >> ~/.npmrc - echo "always-auth=true" >> ~/.npmrc - fi + echo "//${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.npmrc fi # Configure the `pip` to use the Artifactory "python" repository. From fee0d4e15499723c30dcb500a7cff37cb4c9b247 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 13:56:32 +0300 Subject: [PATCH 46/52] fixup! --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 376e27be..b70ce14f 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -115,7 +115,7 @@ elif [ "$SHELLNAME" == "zsh" ]; then echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.zshrc echo "autoload -Uz compinit" >> ~/.zshrc echo "compinit" >> ~/.zshrc - echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.zshrc + echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 627d8569..eb2c30af 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -115,7 +115,7 @@ elif [ "$SHELLNAME" == "zsh" ]; then echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.zshrc echo "autoload -Uz compinit" >> ~/.zshrc echo "compinit" >> ~/.zshrc - echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.zshrc + echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc fi fi From 236e4acda53b600303797cc918bd55c844212d54 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 15:42:10 +0300 Subject: [PATCH 47/52] Fix base64 encoding for `~/.docker/config.json` --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index b70ce14f..148307a8 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -68,7 +68,7 @@ else { "auths": { "${JFROG_HOST}": { - "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)", + "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64 -w0)", "email": "${ARTIFACTORY_EMAIL}" } } diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index eb2c30af..60373951 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -68,7 +68,7 @@ else { "auths": { "${JFROG_HOST}": { - "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64)", + "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64 -w0)", "email": "${ARTIFACTORY_EMAIL}" } } From 736299350028476db4d263a530ec48454c1b8b1f Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 15:54:07 +0300 Subject: [PATCH 48/52] Update docker credentials configuration to use `docker login` --- jfrog-oauth/run.sh | 15 ++++----------- jfrog-token/run.sh | 15 ++++----------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 148307a8..70ac377b 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -62,18 +62,11 @@ if [ -z "${REPOSITORY_DOCKER}" ]; then echo "🤔 no docker repository is set, skipping docker configuration." echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." else - echo "🐳 Configuring docker..." + echo "🔑 Configuring 🐳 docker credentials..." mkdir -p ~/.docker - cat << EOF > ~/.docker/config.json -{ - "auths": { - "${JFROG_HOST}": { - "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64 -w0)", - "email": "${ARTIFACTORY_EMAIL}" - } - } -} -EOF + echo -n "${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.docker/token + cat ~/.docker/token | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin + rm ~/.docker/token fi # Install the JFrog vscode extension for code-server. diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 60373951..d2359b6a 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -62,18 +62,11 @@ if [ -z "${REPOSITORY_DOCKER}" ]; then echo "🤔 no docker repository is set, skipping docker configuration." echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." else - echo "🐳 Configuring docker..." + echo "🔑 Configuring 🐳 docker credentials..." mkdir -p ~/.docker - cat << EOF > ~/.docker/config.json -{ - "auths": { - "${JFROG_HOST}": { - "auth": "$(echo -n "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" | base64 -w0)", - "email": "${ARTIFACTORY_EMAIL}" - } - } -} -EOF + echo -n "${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.docker/token + cat ~/.docker/token | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin + rm ~/.docker/token fi # Install the JFrog vscode extension for code-server. From 1738ff10f3b76687d627d24c90cf6f6fce925414 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 16:13:47 +0300 Subject: [PATCH 49/52] simlified --- jfrog-oauth/run.sh | 4 +--- jfrog-token/run.sh | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 70ac377b..8ef1c6b1 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -64,9 +64,7 @@ if [ -z "${REPOSITORY_DOCKER}" ]; then else echo "🔑 Configuring 🐳 docker credentials..." mkdir -p ~/.docker - echo -n "${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.docker/token - cat ~/.docker/token | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin - rm ~/.docker/token + echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin fi # Install the JFrog vscode extension for code-server. diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index d2359b6a..c13b8452 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -64,9 +64,7 @@ if [ -z "${REPOSITORY_DOCKER}" ]; then else echo "🔑 Configuring 🐳 docker credentials..." mkdir -p ~/.docker - echo -n "${ARTIFACTORY_ACCESS_TOKEN}" >> ~/.docker/token - cat ~/.docker/token | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin - rm ~/.docker/token + echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin fi # Install the JFrog vscode extension for code-server. From 3b96d210c596ce611960719d201392e5d07b70bb Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 5 Jan 2024 17:23:11 +0300 Subject: [PATCH 50/52] added check to see if docker binary is installed --- jfrog-oauth/run.sh | 10 +++++++--- jfrog-token/run.sh | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 8ef1c6b1..3a657936 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -62,9 +62,13 @@ if [ -z "${REPOSITORY_DOCKER}" ]; then echo "🤔 no docker repository is set, skipping docker configuration." echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." else - echo "🔑 Configuring 🐳 docker credentials..." - mkdir -p ~/.docker - echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin + if command -v docker > /dev/null 2>&1; then + echo "🔑 Configuring 🐳 docker credentials..." + mkdir -p ~/.docker + echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin + else + echo "🤔 no docker is installed, skipping docker configuration." + fi fi # Install the JFrog vscode extension for code-server. diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index c13b8452..0b662935 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -62,9 +62,13 @@ if [ -z "${REPOSITORY_DOCKER}" ]; then echo "🤔 no docker repository is set, skipping docker configuration." echo "You can configure a docker repository by providing the a key for 'docker' in the 'package_managers' input." else - echo "🔑 Configuring 🐳 docker credentials..." - mkdir -p ~/.docker - echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin + if command -v docker > /dev/null 2>&1; then + echo "🔑 Configuring 🐳 docker credentials..." + mkdir -p ~/.docker + echo -n "${ARTIFACTORY_ACCESS_TOKEN}" | docker login ${JFROG_HOST} --username ${ARTIFACTORY_USERNAME} --password-stdin + else + echo "🤔 no docker is installed, skipping docker configuration." + fi fi # Install the JFrog vscode extension for code-server. From 1cfefb8d506d1ad7fdcadd08b063b241e17616a1 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 5 Jan 2024 17:23:41 +0300 Subject: [PATCH 51/52] Update timeout value in run.sh script --- jfrog-oauth/run.sh | 2 +- jfrog-token/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 3a657936..939c86e5 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -75,7 +75,7 @@ fi if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then while ! [ -x /tmp/code-server/bin/code-server ]; do counter=0 - if [ $counter -eq 30 ]; then + if [ $counter -eq 60 ]; then echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." exit 1 fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 0b662935..55f48009 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -75,7 +75,7 @@ fi if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then while ! [ -x /tmp/code-server/bin/code-server ]; do counter=0 - if [ $counter -eq 30 ]; then + if [ $counter -eq 60 ]; then echo "Timed out waiting for /tmp/code-server/bin/code-server to be installed." exit 1 fi From 22ecc7903d2982b612a9647723f79d511bf68ab8 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 5 Jan 2024 17:32:57 +0300 Subject: [PATCH 52/52] skip if shellrc files do not exist. --- jfrog-oauth/run.sh | 16 +++++++++++----- jfrog-token/run.sh | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 939c86e5..c0fa5890 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -92,19 +92,21 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -## Get the user's shell +# Get the user's shell SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') -## Generate the completion script +# Generate the completion script jf completion $SHELLNAME --install -## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ]; then +# Add the completion script to the user's shell profile +if [ "$SHELLNAME" == "bash" ] && [ -f ~/.bashrc ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then echo "" >> ~/.bashrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.bashrc echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc echo "# END: jf CLI shell completion" >> ~/.bashrc + else + echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping." fi -elif [ "$SHELLNAME" == "zsh" ]; then +elif [ "$SHELLNAME" == "zsh" ] && [ -f ~/.zshrc ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then echo "" >> ~/.zshrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.zshrc @@ -112,5 +114,9 @@ elif [ "$SHELLNAME" == "zsh" ]; then echo "compinit" >> ~/.zshrc echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc + else + echo "🥳 ~/.zshrc already contains jf CLI shell completion configuration, skipping." fi +else + echo "🤔 ~/.bashrc or ~/.zshrc does not exist, skipping jf CLI shell completion configuration." fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 55f48009..629a65db 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -92,19 +92,21 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -## Get the user's shell +# Get the user's shell SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') -## Generate the completion script +# Generate the completion script jf completion $SHELLNAME --install -## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ]; then +# Add the completion script to the user's shell profile +if [ "$SHELLNAME" == "bash" ] && [ -f ~/.bashrc ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then echo "" >> ~/.bashrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.bashrc echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc echo "# END: jf CLI shell completion" >> ~/.bashrc + else + echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping." fi -elif [ "$SHELLNAME" == "zsh" ]; then +elif [ "$SHELLNAME" == "zsh" ] && [ -f ~/.zshrc ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then echo "" >> ~/.zshrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.zshrc @@ -112,5 +114,9 @@ elif [ "$SHELLNAME" == "zsh" ]; then echo "compinit" >> ~/.zshrc echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc + else + echo "🥳 ~/.zshrc already contains jf CLI shell completion configuration, skipping." fi +else + echo "🤔 ~/.bashrc or ~/.zshrc does not exist, skipping jf CLI shell completion configuration." fi