Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1010ee

Browse files
authored
Add maven package manager support to JFrog modules (#414)
Closes #33 /claim #33 ## Description Jfrog Modules doesn't support conda package manager, This PR adds support of that ## Type of Change - [ ] New module - [ ] Bug fix - [x] Feature/enhancement - [ ] Documentation - [ ] Other ## Testing & Validation - [x] Tests pass (`bun test`) - [ ] Code formatted (`bun run fmt`) - [ ] Changes tested locally ## Related Issues #33 ## video https://github.com/user-attachments/assets/61c33963-e1a7-43e2-b1cc-fdb747405cf5
1 parent 17734c0 commit f1010ee

File tree

10 files changed

+236
-8
lines changed

10 files changed

+236
-8
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Install the JF CLI and authenticate package managers with Artifactory using OAut
1616
module "jfrog" {
1717
count = data.coder_workspace.me.start_count
1818
source = "registry.coder.com/coder/jfrog-oauth/coder"
19-
version = "1.1.0"
19+
version = "1.2.0"
2020
agent_id = coder_agent.example.id
2121
jfrog_url = "https://example.jfrog.io"
2222
username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username"
@@ -27,6 +27,7 @@ module "jfrog" {
2727
pypi = ["pypi", "extra-index-pypi"]
2828
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
2929
conda = ["conda", "conda-local"]
30+
maven = ["maven", "maven-local"]
3031
}
3132
}
3233
```
@@ -46,7 +47,7 @@ Configure the Python pip package manager to fetch packages from Artifactory whil
4647
module "jfrog" {
4748
count = data.coder_workspace.me.start_count
4849
source = "registry.coder.com/coder/jfrog-oauth/coder"
49-
version = "1.1.0"
50+
version = "1.2.0"
5051
agent_id = coder_agent.example.id
5152
jfrog_url = "https://example.jfrog.io"
5253
username_field = "email"
@@ -75,7 +76,7 @@ The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extensio
7576
module "jfrog" {
7677
count = data.coder_workspace.me.start_count
7778
source = "registry.coder.com/coder/jfrog-oauth/coder"
78-
version = "1.1.0"
79+
version = "1.2.0"
7980
agent_id = coder_agent.example.id
8081
jfrog_url = "https://example.jfrog.io"
8182
username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username"

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,38 @@ EOF`;
150150
'if [ -z "YES" ]; then\n not_configured conda',
151151
);
152152
});
153+
it("generates a maven settings.xml with multiple repos", async () => {
154+
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
155+
agent_id: "some-agent-id",
156+
jfrog_url: fakeFrogUrl,
157+
package_managers: JSON.stringify({
158+
maven: ["central", "snapshots", "local"],
159+
}),
160+
});
161+
162+
const coderScript = findResourceInstance(state, "coder_script");
163+
164+
expect(coderScript.script).toContain(
165+
'jf mvnc --global --repo-resolve "central"',
166+
);
167+
168+
expect(coderScript.script).toContain("<servers>");
169+
expect(coderScript.script).toContain("<id>central</id>");
170+
expect(coderScript.script).toContain("<id>snapshots</id>");
171+
expect(coderScript.script).toContain("<id>local</id>");
172+
173+
expect(coderScript.script).toContain(
174+
"<url>http://localhost:8081/artifactory/central</url>",
175+
);
176+
expect(coderScript.script).toContain(
177+
"<url>http://localhost:8081/artifactory/snapshots</url>",
178+
);
179+
expect(coderScript.script).toContain(
180+
"<url>http://localhost:8081/artifactory/local</url>",
181+
);
182+
183+
expect(coderScript.script).toContain(
184+
'if [ -z "YES" ]; then\n not_configured maven',
185+
);
186+
});
153187
});

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ variable "package_managers" {
5959
pypi = optional(list(string), [])
6060
docker = optional(list(string), [])
6161
conda = optional(list(string), [])
62+
maven = optional(list(string), [])
6263
})
6364
description = <<-EOF
6465
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
@@ -69,6 +70,7 @@ variable "package_managers" {
6970
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
7071
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
7172
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
73+
maven = ["YOUR_MAVEN_REPO_KEY", "ANOTHER_MAVEN_REPO_KEY"]
7274
}
7375
EOF
7476
}
@@ -103,6 +105,9 @@ locals {
103105
conda_conf = templatefile(
104106
"${path.module}/conda.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
105107
)
108+
maven_settings = templatefile(
109+
"${path.module}/settings.xml.tftpl", merge(local.common_values, { REPOS = var.package_managers.maven })
110+
)
106111
}
107112

108113
data "coder_workspace" "me" {}
@@ -133,6 +138,9 @@ resource "coder_script" "jfrog" {
133138
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
134139
CONDA_CONF = local.conda_conf
135140
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
141+
HAS_MAVEN = length(var.package_managers.maven) == 0 ? "" : "YES"
142+
MAVEN_SETTINGS = local.maven_settings
143+
REPOSITORY_MAVEN = try(element(var.package_managers.maven, 0), "")
136144
}
137145
))
138146
run_on_start = true

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ EOF
9494
config_complete
9595
fi
9696

97+
# Configure Maven to use the Artifactory "maven" repository.
98+
if [ -z "${HAS_MAVEN}" ]; then
99+
not_configured maven
100+
else
101+
echo "☕ Configuring maven..."
102+
jf mvnc --global --repo-resolve "${REPOSITORY_MAVEN}"
103+
# Create Maven config directory if it doesn't exist
104+
mkdir -p ~/.m2
105+
cat << EOF > ~/.m2/settings.xml
106+
${MAVEN_SETTINGS}
107+
EOF
108+
config_complete
109+
fi
110+
97111
# Install the JFrog vscode extension for code-server.
98112
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
99113
while ! [ -x /tmp/code-server/bin/code-server ]; do
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
5+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
6+
7+
<servers>
8+
%{ for REPO in REPOS ~}
9+
<server>
10+
<id>${REPO}</id>
11+
<username>${ARTIFACTORY_USERNAME}</username>
12+
<password>${ARTIFACTORY_ACCESS_TOKEN}</password>
13+
</server>
14+
%{ endfor ~}
15+
</servers>
16+
17+
<profiles>
18+
<profile>
19+
<id>artifactory</id>
20+
<repositories>
21+
%{ for REPO in REPOS ~}
22+
<repository>
23+
<id>${REPO}</id>
24+
<url>${JFROG_URL}/artifactory/${REPO}</url>
25+
<releases>
26+
<enabled>true</enabled>
27+
</releases>
28+
<snapshots>
29+
<enabled>true</enabled>
30+
</snapshots>
31+
</repository>
32+
%{ endfor ~}
33+
</repositories>
34+
<pluginRepositories>
35+
%{ for REPO in REPOS ~}
36+
<pluginRepository>
37+
<id>${REPO}</id>
38+
<url>${JFROG_URL}/artifactory/${REPO}</url>
39+
<releases>
40+
<enabled>true</enabled>
41+
</releases>
42+
<snapshots>
43+
<enabled>true</enabled>
44+
</snapshots>
45+
</pluginRepository>
46+
%{ endfor ~}
47+
</pluginRepositories>
48+
</profile>
49+
</profiles>
50+
51+
<activeProfiles>
52+
<activeProfile>artifactory</activeProfile>
53+
</activeProfiles>
54+
55+
</settings>

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Install the JF CLI and authenticate package managers with Artifactory using Arti
1313
```tf
1414
module "jfrog" {
1515
source = "registry.coder.com/coder/jfrog-token/coder"
16-
version = "1.1.0"
16+
version = "1.2.0"
1717
agent_id = coder_agent.example.id
1818
jfrog_url = "https://XXXX.jfrog.io"
1919
artifactory_access_token = var.artifactory_access_token
@@ -23,6 +23,7 @@ module "jfrog" {
2323
pypi = ["pypi", "extra-index-pypi"]
2424
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
2525
conda = ["conda", "conda-local"]
26+
maven = ["maven", "maven-local"]
2627
}
2728
}
2829
```
@@ -41,7 +42,7 @@ For detailed instructions, please see this [guide](https://coder.com/docs/v2/lat
4142
```tf
4243
module "jfrog" {
4344
source = "registry.coder.com/coder/jfrog-token/coder"
44-
version = "1.1.0"
45+
version = "1.2.0"
4546
agent_id = coder_agent.example.id
4647
jfrog_url = "https://YYYY.jfrog.io"
4748
artifactory_access_token = var.artifactory_access_token # An admin access token
@@ -50,24 +51,27 @@ module "jfrog" {
5051
go = ["go-local"]
5152
pypi = ["pypi-local"]
5253
conda = ["conda-local"]
54+
maven = ["maven-local"]
5355
}
5456
}
5557
```
5658

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.
59+
You should now be able to install packages from Artifactory using both the `jf npm`, `jf go`, `jf pip` and `npm`, `go`, `pip`, `conda`, `maven` commands.
5860

5961
```shell
6062
jf npm install prettier
6163
jf go get github.com/golang/example/hello
6264
jf pip install requests
6365
conda install numpy
66+
mvn clean install
6467
```
6568

6669
```shell
6770
npm install prettier
6871
go get github.com/golang/example/hello
6972
pip install requests
7073
conda install numpy
74+
mvn clean install
7175
```
7276

7377
### Configure code-server with JFrog extension
@@ -77,7 +81,7 @@ The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extensio
7781
```tf
7882
module "jfrog" {
7983
source = "registry.coder.com/coder/jfrog-token/coder"
80-
version = "1.1.0"
84+
version = "1.2.0"
8185
agent_id = coder_agent.example.id
8286
jfrog_url = "https://XXXX.jfrog.io"
8387
artifactory_access_token = var.artifactory_access_token
@@ -97,7 +101,7 @@ data "coder_workspace" "me" {}
97101
98102
module "jfrog" {
99103
source = "registry.coder.com/coder/jfrog-token/coder"
100-
version = "1.1.0"
104+
version = "1.2.0"
101105
agent_id = coder_agent.example.id
102106
jfrog_url = "https://XXXX.jfrog.io"
103107
artifactory_access_token = var.artifactory_access_token

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,39 @@ EOF`;
187187
'if [ -z "YES" ]; then\n not_configured conda',
188188
);
189189
});
190+
it("generates a maven settings.xml with multiple repos", async () => {
191+
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
192+
agent_id: "some-agent-id",
193+
jfrog_url: fakeFrogUrl,
194+
artifactory_access_token: "XXXX",
195+
package_managers: JSON.stringify({
196+
maven: ["central", "snapshots", "local"],
197+
}),
198+
});
199+
200+
const coderScript = findResourceInstance(state, "coder_script");
201+
202+
expect(coderScript.script).toContain(
203+
'jf mvnc --global --repo-resolve "central"',
204+
);
205+
206+
expect(coderScript.script).toContain("<servers>");
207+
expect(coderScript.script).toContain("<id>central</id>");
208+
expect(coderScript.script).toContain("<id>snapshots</id>");
209+
expect(coderScript.script).toContain("<id>local</id>");
210+
211+
expect(coderScript.script).toContain(
212+
`<url>${fakeFrogUrl}/artifactory/central</url>`,
213+
);
214+
expect(coderScript.script).toContain(
215+
`<url>${fakeFrogUrl}/artifactory/snapshots</url>`,
216+
);
217+
expect(coderScript.script).toContain(
218+
`<url>${fakeFrogUrl}/artifactory/local</url>`,
219+
);
220+
221+
expect(coderScript.script).toContain(
222+
'if [ -z "YES" ]; then\n not_configured maven',
223+
);
224+
});
190225
});

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ variable "package_managers" {
9292
pypi = optional(list(string), [])
9393
docker = optional(list(string), [])
9494
conda = optional(list(string), [])
95+
maven = optional(list(string), [])
9596
})
9697
description = <<-EOF
9798
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
@@ -102,6 +103,7 @@ variable "package_managers" {
102103
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
103104
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
104105
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
106+
maven = ["YOUR_MAVEN_REPO_KEY", "ANOTHER_MAVEN_REPO_KEY"]
105107
}
106108
EOF
107109
}
@@ -136,6 +138,9 @@ locals {
136138
conda_conf = templatefile(
137139
"${path.module}/conda.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
138140
)
141+
maven_settings = templatefile(
142+
"${path.module}/settings.xml.tftpl", merge(local.common_values, { REPOS = var.package_managers.maven })
143+
)
139144
}
140145

141146
# Configure the Artifactory provider
@@ -179,6 +184,9 @@ resource "coder_script" "jfrog" {
179184
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
180185
CONDA_CONF = local.conda_conf
181186
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
187+
HAS_MAVEN = length(var.package_managers.maven) == 0 ? "" : "YES"
188+
MAVEN_SETTINGS = local.maven_settings
189+
REPOSITORY_MAVEN = try(element(var.package_managers.maven, 0), "")
182190
}
183191
))
184192
run_on_start = true

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ EOF
9393
config_complete
9494
fi
9595

96+
# Configure Maven to use the Artifactory "maven" repository.
97+
if [ -z "${HAS_MAVEN}" ]; then
98+
not_configured maven
99+
else
100+
echo "☕ Configuring maven..."
101+
jf mvnc --global --repo-resolve "${REPOSITORY_MAVEN}"
102+
# Create Maven config directory if it doesn't exist
103+
mkdir -p ~/.m2
104+
cat << EOF > ~/.m2/settings.xml
105+
${MAVEN_SETTINGS}
106+
EOF
107+
config_complete
108+
fi
109+
96110
# Install the JFrog vscode extension for code-server.
97111
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
98112
while ! [ -x /tmp/code-server/bin/code-server ]; do

0 commit comments

Comments
 (0)