Skip to content

Add conda package manager support to JFrog modules #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions registry/coder/modules/jfrog-oauth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module "jfrog" {
go = ["go", "another-go-repo"]
pypi = ["pypi", "extra-index-pypi"]
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
conda = ["conda", "another-conda-repo"]
}
}
```
Expand Down Expand Up @@ -68,6 +69,31 @@ jf pip install requests
pip install requests
```

### Configure conda package manager

Configure the conda package manager to fetch packages from Artifactory.

```tf
module "jfrog" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jfrog-oauth/coder"
version = "1.0.19"
agent_id = coder_agent.example.id
jfrog_url = "https://example.jfrog.io"
username_field = "email"

package_managers = {
conda = ["conda"]
}
}
```

You should now be able to install packages from Artifactory using conda.

```shell
conda install numpy
```

### 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.
Expand All @@ -82,9 +108,10 @@ 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 # Add JFrog extension configuration for code-server
package_managers = {
npm = ["npm"]
go = ["go"]
pypi = ["pypi"]
npm = ["npm"]
go = ["go"]
pypi = ["pypi"]
conda = ["conda"]
}
}
```
Expand Down
5 changes: 5 additions & 0 deletions registry/coder/modules/jfrog-oauth/condarc.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
channels:
%{ for REPO in REPOS ~}
- https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/conda/${REPO}
%{ endfor ~}
ssl_verify: true
21 changes: 21 additions & 0 deletions registry/coder/modules/jfrog-oauth/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,25 @@ EOF`;
'if [ -z "YES" ]; then\n not_configured go',
);
});

it("generates a conda config with multiple repos", async () => {
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
package_managers: JSON.stringify({
conda: ["conda-main", "conda-forge"],
}),
});
const coderScript = findResourceInstance(state, "coder_script");
const condaStanza = `cat << EOF > ~/.condarc
channels:
- https://${user}:@${fakeFrogApi}/conda/conda-main
- https://${user}:@${fakeFrogApi}/conda/conda-forge
ssl_verify: true
EOF`;
expect(coderScript.script).toContain(condaStanza);
expect(coderScript.script).toContain(
'if [ -z "YES" ]; then\n not_configured conda',
);
});
});
10 changes: 9 additions & 1 deletion registry/coder/modules/jfrog-oauth/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ variable "package_managers" {
go = optional(list(string), [])
pypi = optional(list(string), [])
docker = optional(list(string), [])
conda = optional(list(string), [])
})
description = <<-EOF
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
Expand All @@ -67,6 +68,7 @@ variable "package_managers" {
go = ["YOUR_GO_REPO_KEY", "ANOTHER_GO_REPO_KEY"]
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
}
EOF
}
Expand All @@ -90,14 +92,17 @@ locals {
{
REPOS = [
for r in var.package_managers.npm :
strcontains(r, ":") ? zipmap(["SCOPE", "NAME"], ["${split(":", r)[0]}:", split(":", r)[1]]) : { SCOPE = "", NAME = r }
length(split(":", r)) > 1 ? zipmap(["SCOPE", "NAME"], ["${split(":", r)[0]}:", split(":", r)[1]]) : { SCOPE = "", NAME = r }
]
}
)
)
pip_conf = templatefile(
"${path.module}/pip.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.pypi })
)
condarc = templatefile(
"${path.module}/condarc.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
)
}

data "coder_workspace" "me" {}
Expand Down Expand Up @@ -125,6 +130,9 @@ resource "coder_script" "jfrog" {
REPOSITORY_PYPI = try(element(var.package_managers.pypi, 0), "")
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
REGISTER_DOCKER = join("\n", formatlist("register_docker \"%s\"", var.package_managers.docker))
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
CONDARC = local.condarc
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
}
))
run_on_start = true
Expand Down
17 changes: 17 additions & 0 deletions registry/coder/modules/jfrog-oauth/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ else
fi
fi

# Configure conda to use the Artifactory "conda" repository.
if [ -z "${HAS_CONDA}" ]; then
not_configured conda
else
echo "🐍 Configuring conda..."
if command -v conda > /dev/null 2>&1; then
cat << EOF > ~/.condarc
${CONDARC}
EOF
# Clear conda package cache to ensure fresh resolution
conda clean -a -y
else
echo "🤔 no conda is installed, skipping conda configuration."
fi
config_complete
fi

# Install the JFrog vscode extension for code-server.
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
while ! [ -x /tmp/code-server/bin/code-server ]; do
Expand Down
38 changes: 32 additions & 6 deletions registry/coder/modules/jfrog-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "jfrog" {
go = ["go", "another-go-repo"]
pypi = ["pypi", "extra-index-pypi"]
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
conda = ["conda", "another-conda-repo"]
}
}
```
Expand All @@ -47,9 +48,10 @@ module "jfrog" {
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"]
npm = ["npm-local"]
go = ["go-local"]
pypi = ["pypi-local"]
conda = ["conda-local"]
}
}
```
Expand All @@ -68,6 +70,29 @@ go get github.com/golang/example/hello
pip install requests
```

### Configure conda package manager

Configure the conda package manager to fetch packages from Artifactory.

```tf
module "jfrog" {
source = "registry.coder.com/coder/jfrog-token/coder"
version = "1.0.30"
agent_id = coder_agent.example.id
jfrog_url = "https://YYYY.jfrog.io"
artifactory_access_token = var.artifactory_access_token
package_managers = {
conda = ["conda-local"]
}
}
```

You should now be able to install packages from Artifactory using conda.

```shell
conda install numpy
```

### 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.
Expand All @@ -81,9 +106,10 @@ module "jfrog" {
artifactory_access_token = var.artifactory_access_token
configure_code_server = true # Add JFrog extension configuration for code-server
package_managers = {
npm = ["npm"]
go = ["go"]
pypi = ["pypi"]
npm = ["npm"]
go = ["go"]
pypi = ["pypi"]
conda = ["conda"]
}
}
```
Expand Down
5 changes: 5 additions & 0 deletions registry/coder/modules/jfrog-token/condarc.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
channels:
%{ for REPO in REPOS ~}
- https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/conda/${REPO}
%{ endfor ~}
ssl_verify: true
22 changes: 22 additions & 0 deletions registry/coder/modules/jfrog-token/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,26 @@ EOF`;
'if [ -z "YES" ]; then\n not_configured go',
);
});

it("generates a conda config with multiple repos", async () => {
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
artifactory_access_token: "XXXX",
package_managers: JSON.stringify({
conda: ["conda-main", "conda-forge"],
}),
});
const coderScript = findResourceInstance(state, "coder_script");
const condaStanza = `cat << EOF > ~/.condarc
channels:
- https://${user}:${token}@${fakeFrogApi}/conda/conda-main
- https://${user}:${token}@${fakeFrogApi}/conda/conda-forge
ssl_verify: true
EOF`;
expect(coderScript.script).toContain(condaStanza);
expect(coderScript.script).toContain(
'if [ -z "YES" ]; then\n not_configured conda',
);
});
});
10 changes: 9 additions & 1 deletion registry/coder/modules/jfrog-token/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ variable "package_managers" {
go = optional(list(string), [])
pypi = optional(list(string), [])
docker = optional(list(string), [])
conda = optional(list(string), [])
})
description = <<-EOF
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
Expand All @@ -100,6 +101,7 @@ variable "package_managers" {
go = ["YOUR_GO_REPO_KEY", "ANOTHER_GO_REPO_KEY"]
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
}
EOF
}
Expand All @@ -123,14 +125,17 @@ locals {
{
REPOS = [
for r in var.package_managers.npm :
strcontains(r, ":") ? zipmap(["SCOPE", "NAME"], ["${split(":", r)[0]}:", split(":", r)[1]]) : { SCOPE = "", NAME = r }
length(split(":", r)) > 1 ? zipmap(["SCOPE", "NAME"], ["${split(":", r)[0]}:", split(":", r)[1]]) : { SCOPE = "", NAME = r }
]
}
)
)
pip_conf = templatefile(
"${path.module}/pip.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.pypi })
)
condarc = templatefile(
"${path.module}/condarc.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
)
}

# Configure the Artifactory provider
Expand Down Expand Up @@ -171,6 +176,9 @@ resource "coder_script" "jfrog" {
REPOSITORY_PYPI = try(element(var.package_managers.pypi, 0), "")
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
REGISTER_DOCKER = join("\n", formatlist("register_docker \"%s\"", var.package_managers.docker))
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
CONDARC = local.condarc
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
}
))
run_on_start = true
Expand Down
17 changes: 17 additions & 0 deletions registry/coder/modules/jfrog-token/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ else
fi
fi

# Configure conda to use the Artifactory "conda" repository.
if [ -z "${HAS_CONDA}" ]; then
not_configured conda
else
echo "🐍 Configuring conda..."
if command -v conda > /dev/null 2>&1; then
cat << EOF > ~/.condarc
${CONDARC}
EOF
# Clear conda package cache to ensure fresh resolution
conda clean -a -y
else
echo "🤔 no conda is installed, skipping conda configuration."
fi
config_complete
fi

# Install the JFrog vscode extension for code-server.
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
while ! [ -x /tmp/code-server/bin/code-server ]; do
Expand Down