add example to use

pull/50/head
Muhammad Atif Ali 2 years ago
parent 5f729962dc
commit 11e2663731
No known key found for this signature in database

@ -14,6 +14,10 @@ Install the JF CLI and authenticate package managers with Artifactory.
![JFrog](../.images/jfrog.png)] ![JFrog](../.images/jfrog.png)]
## Examples
### Configure npm, go, and pypi to use Artifactory
```hcl ```hcl
module "jfrog" { module "jfrog" {
source = "https://registry.coder.com/modules/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 ## 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. 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.

@ -52,6 +52,12 @@ For example:
EOF EOF
} }
variable "npm_package_manager" {
type = string
description = "The name of the npm repository in Artifactory."
default = "npm"
}
data "coder_workspace" "me" {} data "coder_workspace" "me" {}
resource "coder_script" "jfrog" { resource "coder_script" "jfrog" {
@ -65,6 +71,7 @@ resource "coder_script" "jfrog" {
REPOSITORY_NPM : lookup(var.package_managers, "npm", ""), REPOSITORY_NPM : lookup(var.package_managers, "npm", ""),
REPOSITORY_GO : lookup(var.package_managers, "go", ""), REPOSITORY_GO : lookup(var.package_managers, "go", ""),
REPOSITORY_PYPI : lookup(var.package_managers, "pypi", ""), REPOSITORY_PYPI : lookup(var.package_managers, "pypi", ""),
NPM_PACKAGE_MANAGER : var.npm_package_manager,
}) })
run_on_start = true run_on_start = true
} }

@ -18,13 +18,28 @@ echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "https:
if [ -z "${REPOSITORY_NPM}" ]; then if [ -z "${REPOSITORY_NPM}" ]; then
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
else else
echo "📦 Configuring npm..." # check NPM_PACKAGE_MANAGER==npm value to set the package manager npm otherwise yarn
jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}" if [ "${NPM_PACKAGE_MANAGER}" = "npm" ]; then
cat << EOF > ~/.npmrc echo "📦 Configuring npm..."
email = ${ARTIFACTORY_USERNAME} jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}"
registry = https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM} # cat << EOF > ~/.npmrc
EOF # email = ${ARTIFACTORY_USERNAME}
jf rt curl /api/npm/auth >> ~/.npmrc # 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 fi
# Configure the `pip` to use the Artifactory "python" repository. # Configure the `pip` to use the Artifactory "python" repository.

Loading…
Cancel
Save