Skip to content

Commit da09fbd

Browse files
committed
dcs: update jfrog package management docs
1 parent 594b979 commit da09fbd

File tree

3 files changed

+83
-23
lines changed

3 files changed

+83
-23
lines changed

docs/platforms/jfrog.md

+57-13
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ The full example template can be found [here](https://github.com/coder/coder/tre
1111

1212
- A JFrog Artifactory instance
1313
- An admin-level access token for Artifactory
14-
- 1:1 mapping of users in Coder to users in Artifactory by email address
15-
- An npm repository in Artifactory named "npm"
14+
- 1:1 mapping of users in Coder to users in Artifactory by email address and username
15+
- Repositories configured in Artifactory for each package manager you want to use
16+
1617

1718
<blockquote class="info">
1819
The admin-level access token is used to provision user tokens and is never exposed to
@@ -40,7 +41,7 @@ terraform {
4041
}
4142
artifactory = {
4243
source = "registry.terraform.io/jfrog/artifactory"
43-
version = "6.22.3"
44+
version = "~> 8.4.0"
4445
}
4546
}
4647
}
@@ -57,15 +58,15 @@ variable "artifactory_access_token" {
5758
5859
# Configure the Artifactory provider
5960
provider "artifactory" {
60-
url = "${var.jfrog_url}/artifactory"
61+
url = "https://${var.jfrog_url}/artifactory"
6162
access_token = "${var.artifactory_access_token}"
6263
}
6364
```
6465

65-
When pushing the template, you can pass in the variables using the `-V` flag:
66+
When pushing the template, you can pass in the variables using the `--var` flag:
6667

6768
```sh
68-
coder templates push --var 'jfrog_url=https://YYY.jfrog.io' --var 'artifactory_access_token=XXX'
69+
coder templates push --var 'jfrog_url=YYY.jfrog.io' --var 'artifactory_access_token=XXX'
6970
```
7071

7172
## Installing JFrog CLI
@@ -107,9 +108,27 @@ resource "coder_agent" "main" {
107108
export CI=true
108109
109110
jf c rm 0 || true
110-
echo ${artifactory_access_token.me.access_token} | \
111-
jf c add --access-token-stdin --url ${var.jfrog_url} 0
111+
echo ${artifactory_scoped_token.me.access_token} | \
112+
jf c add --access-token-stdin --url https://${var.jfrog_url} 0
113+
114+
# Configure the `npm` CLI to use the Artifactory "npm" registry.
115+
cat << EOF > ~/.npmrc
116+
email = ${data.coder_workspace.me.owner_email}
117+
registry = https://${var.jfrog_url}/artifactory/api/npm/${local.artifactory_registry_keys["npm"]}
118+
EOF
119+
jf rt curl /api/npm/auth >> .npmrc
120+
121+
mkdir -p ~/.pip
122+
cat << EOF > ~/.pip/pip.conf
123+
[global]
124+
index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_url}/artifactory/api/pypi/${local.artifactory_registry_keys["pypi"]}/simple
125+
EOF
126+
112127
EOT
128+
# Set GOPROXY to use the Artifactory "go" registry.
129+
env = {
130+
GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_url}/artifactory/api/go/${local.artifactory_registry_keys["go"]}"
131+
}
113132
}
114133
```
115134

@@ -125,7 +144,7 @@ Distribution URL: https://cdr.jfrog.io/distribution/
125144
Xray URL: https://cdr.jfrog.io/xray/
126145
Mission Control URL: https://cdr.jfrog.io/mc/
127146
Pipelines URL: https://cdr.jfrog.io/pipelines/
128-
User: ammar@....com
147+
User: ammar
129148
Access token: ...
130149
Default: true
131150
```
@@ -151,11 +170,11 @@ Note that this method will only work if your developers use code-server.
151170
Add the following line to your `startup_script` to configure `npm` to use
152171
Artifactory:
153172

154-
```sh
173+
```shell
155174
# Configure the `npm` CLI to use the Artifactory "npm" registry.
156175
cat << EOF > ~/.npmrc
157176
email = ${data.coder_workspace.me.owner_email}
158-
registry=${var.jfrog_url}/artifactory/api/npm/npm/
177+
registry = https://${var.jfrog_url}/artifactory/api/npm/npm/
159178
EOF
160179
jf rt curl /api/npm/auth >> .npmrc
161180
```
@@ -165,8 +184,33 @@ use Artifactory as the package registry. You can verify that `npm` is configured
165184
correctly by running `npm install --loglevel=http react` and checking that
166185
npm is only hitting your Artifactory URL.
167186
168-
You can apply the same concepts to Docker, Go, Maven, and other package managers
169-
supported by Artifactory.
187+
## Configuring pip
188+
189+
Add the following lines to your `startup_script` to configure `pip` to use
190+
Artifactory:
191+
192+
```shell
193+
mkdir -p ~/.pip
194+
cat << EOF > ~/.pip/pip.conf
195+
[global]
196+
index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_url}/artifactory/api/pypi/pypi/simple
197+
EOF
198+
```
199+
200+
Now, your developers can run `pip install` and transparently use Artifactory as the package registry. You can verify that `pip` is configured correctly by running `pip install --verbose requests` and checking that pip is only hitting your Artifactory URL.
201+
202+
## Configuring Go
203+
204+
Add the following environment variable to your `coder_agent` block to configure `go` to use Artifactory:
205+
206+
```hcl
207+
env = {
208+
GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_url}/artifactory/api/go/go"
209+
}
210+
```
211+
212+
You can apply the same concepts to Docker, Maven, and other package managers
213+
supported by Artifactory. See the [JFrog documentation](https://jfrog.com/help/r/jfrog-artifactory-documentation/package-management) for more information.
170214
171215
## More reading
172216

examples/templates/jfrog-docker/build/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN apt-get update \
55
curl \
66
git \
77
golang \
8+
python3-pip \
89
sudo \
910
vim \
1011
wget \

examples/templates/jfrog-docker/main.tf

+25-10
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ terraform {
1010
}
1111
artifactory = {
1212
source = "registry.terraform.io/jfrog/artifactory"
13-
version = "6.22.3"
13+
version = "~> 8.4.0"
1414
}
1515
}
1616
}
1717

1818
locals {
1919
username = data.coder_workspace.me.owner
20+
artifactory_registry_keys = {
21+
"npm" = "npm"
22+
"pypi" = "pypi"
23+
"go" = "go"
24+
}
2025
}
2126

2227
data "coder_provisioner" "me" {
2328
}
2429

2530
provider "docker" {
31+
host = "tcp://100.117.102.81:2375"
2632
}
2733

2834
data "coder_workspace" "me" {
@@ -38,17 +44,14 @@ variable "artifactory_access_token" {
3844
description = "The admin-level access token to use for JFrog."
3945
}
4046

41-
4247
# Configure the Artifactory provider
4348
provider "artifactory" {
44-
url = "${var.jfrog_url}/artifactory"
49+
url = "https://${var.jfrog_url}/artifactory"
4550
access_token = var.artifactory_access_token
4651
}
4752

48-
resource "artifactory_access_token" "me" {
49-
username = data.coder_workspace.me.owner_email
50-
# The token should live for the duration of the workspace.
51-
end_date_relative = "0s"
53+
resource "artifactory_scoped_token" "me" {
54+
username = data.coder_workspace.me.owner
5255
}
5356

5457
resource "coder_agent" "main" {
@@ -67,16 +70,28 @@ resource "coder_agent" "main" {
6770
export CI=true
6871
6972
jf c rm 0 || true
70-
echo ${artifactory_access_token.me.access_token} | \
71-
jf c add --access-token-stdin --url ${var.jfrog_url} 0
73+
echo ${artifactory_scoped_token.me.access_token} | \
74+
jf c add --access-token-stdin --url https://${var.jfrog_url} 0
7275
7376
# Configure the `npm` CLI to use the Artifactory "npm" registry.
7477
cat << EOF > ~/.npmrc
7578
email = ${data.coder_workspace.me.owner_email}
76-
registry=${var.jfrog_url}/artifactory/api/npm/npm/
79+
registry = https://${var.jfrog_url}/artifactory/api/npm/${local.artifactory_registry_keys["npm"]}
7780
EOF
7881
jf rt curl /api/npm/auth >> .npmrc
82+
83+
# Configure the `pip` to use the Artifactory "pypi" registry.
84+
mkdir -p ~/.pip
85+
cat << EOF > ~/.pip/pip.conf
86+
[global]
87+
index-url = https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_url}/artifactory/api/pypi/${local.artifactory_registry_keys["pypi"]}/simple
88+
EOF
89+
7990
EOT
91+
# Set GOPROXY to use the Artifactory "go" registry.
92+
env = {
93+
GOPROXY : "https://${data.coder_workspace.me.owner}:${artifactory_scoped_token.me.access_token}@${var.jfrog_url}/artifactory/api/go/${local.artifactory_registry_keys["go"]}"
94+
}
8095
}
8196

8297
resource "coder_app" "code-server" {

0 commit comments

Comments
 (0)