Skip to content

Commit 8f079ed

Browse files
committed
add maven package
1 parent 9e47369 commit 8f079ed

File tree

8 files changed

+160
-1
lines changed

8 files changed

+160
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
```

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
```
@@ -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

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
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>

0 commit comments

Comments
 (0)