From 11e26637314bc1d809fb900106e9114b16f14977 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 26 Sep 2023 17:54:13 +0300 Subject: [PATCH] add example to use --- jfrog/README.md | 19 +++++++++++++++++++ jfrog/main.tf | 7 +++++++ jfrog/run.sh | 29 ++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/jfrog/README.md b/jfrog/README.md index 7396fe1..9ba6bd8 100644 --- a/jfrog/README.md +++ b/jfrog/README.md @@ -14,6 +14,10 @@ Install the JF CLI and authenticate package managers with Artifactory. ![JFrog](../.images/jfrog.png)] +## Examples + +### Configure npm, go, and pypi to use Artifactory + ```hcl module "jfrog" { source = "https://registry.coder.com/modules/jfrog" @@ -28,6 +32,21 @@ module "jfrog" { } ``` +### Configure npm to use Artifactory with yarn + +```hcl +module "jfrog" { + source = "https://registry.coder.com/modules/jfrog" + agent_id = coder_agent.example.id + jfrog_host = "YYYY.jfrog.io" + artifactory_access_token = var.artifactory_access_token # An admin access token + package_managers = { + "npm": "npm-local", + } + npm_package_manager = "yarn" +} + + ## Authentication Get a JFrog access token from your Artifactory instance. The token must have admin permissions. It is recommended to store the token in a secret terraform variable. diff --git a/jfrog/main.tf b/jfrog/main.tf index fbbd267..8c9458a 100644 --- a/jfrog/main.tf +++ b/jfrog/main.tf @@ -52,6 +52,12 @@ For example: EOF } +variable "npm_package_manager" { + type = string + description = "The name of the npm repository in Artifactory." + default = "npm" +} + data "coder_workspace" "me" {} resource "coder_script" "jfrog" { @@ -65,6 +71,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", ""), + NPM_PACKAGE_MANAGER : var.npm_package_manager, }) run_on_start = true } diff --git a/jfrog/run.sh b/jfrog/run.sh index f5821b8..65587aa 100644 --- a/jfrog/run.sh +++ b/jfrog/run.sh @@ -18,13 +18,28 @@ echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "https: if [ -z "${REPOSITORY_NPM}" ]; then echo "๐Ÿค” REPOSITORY_NPM is not set, skipping npm configuration." else - echo "๐Ÿ“ฆ Configuring npm..." - jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}" - cat << EOF > ~/.npmrc -email = ${ARTIFACTORY_USERNAME} -registry = https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM} -EOF - jf rt curl /api/npm/auth >> ~/.npmrc + # check NPM_PACKAGE_MANAGER==npm value to set the package manager npm otherwise yarn + if [ "${NPM_PACKAGE_MANAGER}" = "npm" ]; then + echo "๐Ÿ“ฆ Configuring npm..." + jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}" +# cat << EOF > ~/.npmrc +# email = ${ARTIFACTORY_USERNAME} +# registry = https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM} +# EOF + jf rt curl /api/npm/auth >> ~/.npmrc + else + echo "๐Ÿงถ Configuring yarn..." + jf yarnc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}" +# cat << EOF > ~/.yarnrc + + +# echo "๐Ÿ“ฆ Configuring npm..." +# jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}" +# cat << EOF > ~/.npmrc +# email = ${ARTIFACTORY_USERNAME} +# registry = https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM} +# EOF +# jf rt curl /api/npm/auth >> ~/.npmrc fi # Configure the `pip` to use the Artifactory "python" repository.