Skip to content

Commit 7152b85

Browse files
authored
feat: add conda support to JFrog modules (#375)
1 parent 41c6bec commit 7152b85

File tree

10 files changed

+112
-4
lines changed

10 files changed

+112
-4
lines changed

registry/coder/modules/jfrog-oauth/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module "jfrog" {
2626
go = ["go", "another-go-repo"]
2727
pypi = ["pypi", "extra-index-pypi"]
2828
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
29+
conda = ["conda", "conda-local"]
2930
}
3031
}
3132
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
channels:
2+
%{ for REPO in REPOS ~}
3+
- https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/conda/${REPO}
4+
%{ endfor ~}
5+
- defaults
6+
ssl_verify: true

registry/coder/modules/jfrog-oauth/main.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,28 @@ EOF`;
126126
'if [ -z "YES" ]; then\n not_configured go',
127127
);
128128
});
129+
130+
it("generates a conda config with multiple repos", async () => {
131+
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
132+
agent_id: "some-agent-id",
133+
jfrog_url: fakeFrogUrl,
134+
package_managers: JSON.stringify({
135+
conda: ["conda-main", "conda-secondary", "conda-local"],
136+
}),
137+
});
138+
const coderScript = findResourceInstance(state, "coder_script");
139+
const condaStanza = `cat << EOF > ~/.condarc
140+
channels:
141+
- https://${user}:@${fakeFrogApi}/conda/conda-main
142+
- https://${user}:@${fakeFrogApi}/conda/conda-secondary
143+
- https://${user}:@${fakeFrogApi}/conda/conda-local
144+
- defaults
145+
ssl_verify: true
146+
147+
EOF`;
148+
expect(coderScript.script).toContain(condaStanza);
149+
expect(coderScript.script).toContain(
150+
'if [ -z "YES" ]; then\n not_configured conda',
151+
);
152+
});
129153
});

registry/coder/modules/jfrog-oauth/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ variable "package_managers" {
5858
go = optional(list(string), [])
5959
pypi = optional(list(string), [])
6060
docker = optional(list(string), [])
61+
conda = optional(list(string), [])
6162
})
6263
description = <<-EOF
6364
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
@@ -67,6 +68,7 @@ variable "package_managers" {
6768
go = ["YOUR_GO_REPO_KEY", "ANOTHER_GO_REPO_KEY"]
6869
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
6970
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
71+
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
7072
}
7173
EOF
7274
}
@@ -98,6 +100,9 @@ locals {
98100
pip_conf = templatefile(
99101
"${path.module}/pip.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.pypi })
100102
)
103+
conda_conf = templatefile(
104+
"${path.module}/conda.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
105+
)
101106
}
102107

103108
data "coder_workspace" "me" {}
@@ -125,6 +130,9 @@ resource "coder_script" "jfrog" {
125130
REPOSITORY_PYPI = try(element(var.package_managers.pypi, 0), "")
126131
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
127132
REGISTER_DOCKER = join("\n", formatlist("register_docker \"%s\"", var.package_managers.docker))
133+
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
134+
CONDA_CONF = local.conda_conf
135+
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
128136
}
129137
))
130138
run_on_start = true

registry/coder/modules/jfrog-oauth/run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ else
8181
fi
8282
fi
8383

84+
# Configure conda to use the Artifactory "conda" repository.
85+
if [ -z "${HAS_CONDA}" ]; then
86+
not_configured conda
87+
else
88+
echo "🐍 Configuring conda..."
89+
# Create conda config directory if it doesn't exist
90+
mkdir -p ~/.conda
91+
cat << EOF > ~/.condarc
92+
${CONDA_CONF}
93+
EOF
94+
config_complete
95+
fi
96+
8497
# Install the JFrog vscode extension for code-server.
8598
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
8699
while ! [ -x /tmp/code-server/bin/code-server ]; do

registry/coder/modules/jfrog-token/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module "jfrog" {
2222
go = ["go", "another-go-repo"]
2323
pypi = ["pypi", "extra-index-pypi"]
2424
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
25+
conda = ["conda", "conda-local"]
2526
}
2627
}
2728
```
@@ -45,25 +46,28 @@ module "jfrog" {
4546
jfrog_url = "https://YYYY.jfrog.io"
4647
artifactory_access_token = var.artifactory_access_token # An admin access token
4748
package_managers = {
48-
npm = ["npm-local"]
49-
go = ["go-local"]
50-
pypi = ["pypi-local"]
49+
npm = ["npm-local"]
50+
go = ["go-local"]
51+
pypi = ["pypi-local"]
52+
conda = ["conda-local"]
5153
}
5254
}
5355
```
5456

55-
You should now be able to install packages from Artifactory using both the `jf npm`, `jf go`, `jf pip` and `npm`, `go`, `pip` commands.
57+
You should now be able to install packages from Artifactory using both the `jf npm`, `jf go`, `jf pip` and `npm`, `go`, `pip`, `conda` commands.
5658

5759
```shell
5860
jf npm install prettier
5961
jf go get github.com/golang/example/hello
6062
jf pip install requests
63+
conda install numpy
6164
```
6265

6366
```shell
6467
npm install prettier
6568
go get github.com/golang/example/hello
6669
pip install requests
70+
conda install numpy
6771
```
6872

6973
### Configure code-server with JFrog extension
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
channels:
2+
%{ for REPO in REPOS ~}
3+
- https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/conda/${REPO}
4+
%{ endfor ~}
5+
- defaults
6+
ssl_verify: true

registry/coder/modules/jfrog-token/main.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,29 @@ EOF`;
162162
'if [ -z "YES" ]; then\n not_configured go',
163163
);
164164
});
165+
166+
it("generates a conda config with multiple repos", async () => {
167+
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
168+
agent_id: "some-agent-id",
169+
jfrog_url: fakeFrogUrl,
170+
artifactory_access_token: "XXXX",
171+
package_managers: JSON.stringify({
172+
conda: ["conda-main", "conda-secondary", "conda-local"],
173+
}),
174+
});
175+
const coderScript = findResourceInstance(state, "coder_script");
176+
const condaStanza = `cat << EOF > ~/.condarc
177+
channels:
178+
- https://${user}:${token}@${fakeFrogApi}/conda/conda-main
179+
- https://${user}:${token}@${fakeFrogApi}/conda/conda-secondary
180+
- https://${user}:${token}@${fakeFrogApi}/conda/conda-local
181+
- defaults
182+
ssl_verify: true
183+
184+
EOF`;
185+
expect(coderScript.script).toContain(condaStanza);
186+
expect(coderScript.script).toContain(
187+
'if [ -z "YES" ]; then\n not_configured conda',
188+
);
189+
});
165190
});

registry/coder/modules/jfrog-token/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ variable "package_managers" {
9191
go = optional(list(string), [])
9292
pypi = optional(list(string), [])
9393
docker = optional(list(string), [])
94+
conda = optional(list(string), [])
9495
})
9596
description = <<-EOF
9697
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
@@ -100,6 +101,7 @@ variable "package_managers" {
100101
go = ["YOUR_GO_REPO_KEY", "ANOTHER_GO_REPO_KEY"]
101102
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
102103
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
104+
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
103105
}
104106
EOF
105107
}
@@ -131,6 +133,9 @@ locals {
131133
pip_conf = templatefile(
132134
"${path.module}/pip.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.pypi })
133135
)
136+
conda_conf = templatefile(
137+
"${path.module}/conda.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
138+
)
134139
}
135140

136141
# Configure the Artifactory provider
@@ -171,6 +176,9 @@ resource "coder_script" "jfrog" {
171176
REPOSITORY_PYPI = try(element(var.package_managers.pypi, 0), "")
172177
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
173178
REGISTER_DOCKER = join("\n", formatlist("register_docker \"%s\"", var.package_managers.docker))
179+
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
180+
CONDA_CONF = local.conda_conf
181+
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
174182
}
175183
))
176184
run_on_start = true

registry/coder/modules/jfrog-token/run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ else
8080
fi
8181
fi
8282

83+
# Configure conda to use the Artifactory "conda" repository.
84+
if [ -z "${HAS_CONDA}" ]; then
85+
not_configured conda
86+
else
87+
echo "🐍 Configuring conda..."
88+
# Create conda config directory if it doesn't exist
89+
mkdir -p ~/.conda
90+
cat << EOF > ~/.condarc
91+
${CONDA_CONF}
92+
EOF
93+
config_complete
94+
fi
95+
8396
# Install the JFrog vscode extension for code-server.
8497
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
8598
while ! [ -x /tmp/code-server/bin/code-server ]; do

0 commit comments

Comments
 (0)