-
Notifications
You must be signed in to change notification settings - Fork 62
feat(jfrog): support multiple repositories #289
Changes from 7 commits
31c29fa
646adbc
0361847
b6c0d58
fd5ba0f
67c1d63
4b0ac2a
d06cd4a
149cb2f
70ec87f
fb409cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| email=${ARTIFACTORY_EMAIL} | ||
| %{ for REPO in REPOS ~} | ||
| ${REPO.SCOPE}registry=${JFROG_URL}/artifactory/api/npm/${REPO.NAME} | ||
| //${JFROG_HOST}/artifactory/api/npm/${REPO.NAME}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN} | ||
| %{ endfor ~} |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,19 +1,115 @@ | ||||||||||||||||||||
| import { serve } from "bun"; | ||||||||||||||||||||
| import { describe } from "bun:test"; | ||||||||||||||||||||
| import { describe, expect, it } from "bun:test"; | ||||||||||||||||||||
| import { | ||||||||||||||||||||
| createJSONResponse, | ||||||||||||||||||||
| findResourceInstance, | ||||||||||||||||||||
| runTerraformInit, | ||||||||||||||||||||
| runTerraformApply, | ||||||||||||||||||||
| testRequiredVariables, | ||||||||||||||||||||
| } from "../test"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| describe("jfrog-oauth", async () => { | ||||||||||||||||||||
| await runTerraformInit(import.meta.dir); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| testRequiredVariables(import.meta.dir, { | ||||||||||||||||||||
| agent_id: "some-agent-id", | ||||||||||||||||||||
| jfrog_url: "http://localhost:8081", | ||||||||||||||||||||
| package_managers: "{}", | ||||||||||||||||||||
| const fakeFrogHostAndPort = "localhost:8081"; | ||||||||||||||||||||
| const fakeFrogUrl = `http://${fakeFrogHostAndPort}`; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("can run apply with required variables", async () => { | ||||||||||||||||||||
| testRequiredVariables(import.meta.dir, { | ||||||||||||||||||||
|
||||||||||||||||||||
| agent_id: "some-agent-id", | ||||||||||||||||||||
| jfrog_url: fakeFrogUrl, | ||||||||||||||||||||
| package_managers: "{}", | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| //TODO add more tests | ||||||||||||||||||||
| it("generates an npmrc with scoped repos", async () => { | ||||||||||||||||||||
| const state = await runTerraformApply(import.meta.dir, { | ||||||||||||||||||||
| agent_id: "some-agent-id", | ||||||||||||||||||||
| jfrog_url: fakeFrogUrl, | ||||||||||||||||||||
| package_managers: JSON.stringify({ | ||||||||||||||||||||
| npm: ["global", "@foo:foo", "@bar:bar"], | ||||||||||||||||||||
| }), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| const coderScript = findResourceInstance(state, "coder_script"); | ||||||||||||||||||||
| const npmrcStanza = `cat << EOF > ~/.npmrc | ||||||||||||||||||||
| [email protected] | ||||||||||||||||||||
| registry=${fakeFrogUrl}/artifactory/api/npm/global | ||||||||||||||||||||
| //${fakeFrogHostAndPort}/artifactory/api/npm/global/:_authToken= | ||||||||||||||||||||
| @foo:registry=${fakeFrogUrl}/artifactory/api/npm/foo | ||||||||||||||||||||
| //${fakeFrogHostAndPort}/artifactory/api/npm/foo/:_authToken= | ||||||||||||||||||||
| @bar:registry=${fakeFrogUrl}/artifactory/api/npm/bar | ||||||||||||||||||||
| //${fakeFrogHostAndPort}/artifactory/api/npm/bar/:_authToken= | ||||||||||||||||||||
| EOF`; | ||||||||||||||||||||
| expect(coderScript.script).toContain(npmrcStanza); | ||||||||||||||||||||
| expect(coderScript.script).toContain( | ||||||||||||||||||||
| 'jf npmc --global --repo-resolve "global"', | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| expect(coderScript.script).toContain( | ||||||||||||||||||||
| 'if [ -z "YES" ]; then\n not_configured npm', | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("generates a pip config with extra-indexes", async () => { | ||||||||||||||||||||
| const state = await runTerraformApply(import.meta.dir, { | ||||||||||||||||||||
| agent_id: "some-agent-id", | ||||||||||||||||||||
| jfrog_url: fakeFrogUrl, | ||||||||||||||||||||
| package_managers: JSON.stringify({ | ||||||||||||||||||||
| pypi: ["global", "foo", "bar"], | ||||||||||||||||||||
| }), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| const coderScript = findResourceInstance(state, "coder_script"); | ||||||||||||||||||||
| const pipStanza = `cat << EOF > ~/.pip/pip.conf | ||||||||||||||||||||
| [global] | ||||||||||||||||||||
| index-url = https://default:@${fakeFrogHostAndPort}/artifactory/api/pypi/global/simple | ||||||||||||||||||||
| extra-index-url = | ||||||||||||||||||||
| https://default:@${fakeFrogHostAndPort}/artifactory/api/pypi/foo/simple | ||||||||||||||||||||
| https://default:@${fakeFrogHostAndPort}/artifactory/api/pypi/bar/simple | ||||||||||||||||||||
| EOF`; | ||||||||||||||||||||
| expect(coderScript.script).toContain(pipStanza); | ||||||||||||||||||||
| expect(coderScript.script).toContain( | ||||||||||||||||||||
| 'jf pipc --global --repo-resolve "global"', | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| expect(coderScript.script).toContain( | ||||||||||||||||||||
| 'if [ -z "YES" ]; then\n not_configured pypi', | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("registers multiple docker repos", async () => { | ||||||||||||||||||||
| const state = await runTerraformApply(import.meta.dir, { | ||||||||||||||||||||
| agent_id: "some-agent-id", | ||||||||||||||||||||
| jfrog_url: fakeFrogUrl, | ||||||||||||||||||||
| package_managers: JSON.stringify({ | ||||||||||||||||||||
| docker: ["foo.jfrog.io", "bar.jfrog.io", "baz.jfrog.io"], | ||||||||||||||||||||
| }), | ||||||||||||||||||||
|
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely isn't your fault, but I'm making a note so I don't forget: we should update our helper functions so that they support Terraform objects directly |
||||||||||||||||||||
| }); | ||||||||||||||||||||
| const coderScript = findResourceInstance(state, "coder_script"); | ||||||||||||||||||||
| const dockerStanza = `register_docker "foo.jfrog.io" | ||||||||||||||||||||
| register_docker "bar.jfrog.io" | ||||||||||||||||||||
| register_docker "baz.jfrog.io"`; | ||||||||||||||||||||
| expect(coderScript.script).toContain(dockerStanza); | ||||||||||||||||||||
| expect(coderScript.script).toContain( | ||||||||||||||||||||
| 'if [ -z "YES" ]; then\n not_configured docker', | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("sets goproxy with multiple repos", async () => { | ||||||||||||||||||||
| const state = await runTerraformApply(import.meta.dir, { | ||||||||||||||||||||
| agent_id: "some-agent-id", | ||||||||||||||||||||
| jfrog_url: fakeFrogUrl, | ||||||||||||||||||||
| package_managers: JSON.stringify({ | ||||||||||||||||||||
| go: ["foo", "bar", "baz"], | ||||||||||||||||||||
| }), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| const proxyEnv = findResourceInstance(state, "coder_env", "goproxy"); | ||||||||||||||||||||
| const proxies = `https://default:@${fakeFrogHostAndPort}/artifactory/api/go/foo,https://default:@${fakeFrogHostAndPort}/artifactory/api/go/bar,https://default:@${fakeFrogHostAndPort}/artifactory/api/go/baz`; | ||||||||||||||||||||
| expect(proxyEnv["value"]).toEqual(proxies); | ||||||||||||||||||||
|
||||||||||||||||||||
| const proxies = `https://default:@${fakeFrogHostAndPort}/artifactory/api/go/foo,https://default:@${fakeFrogHostAndPort}/artifactory/api/go/bar,https://default:@${fakeFrogHostAndPort}/artifactory/api/go/baz`; | |
| expect(proxyEnv["value"]).toEqual(proxies); | |
| const proxies = [ | |
| `https://default:@${fakeFrogHostAndPort}/artifactory/api/go/foo`, | |
| `https://default:@${fakeFrogHostAndPort}/artifactory/api/go/bar`, | |
| `https://default:@${fakeFrogHostAndPort}/artifactory/api/go/baz` | |
| ]; | |
| expect (proxyEnv.value).toBe(proxies.join(",")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this:
["foo","bar","baz"].map(r => `https://default:@${fakeFrogHostAndPort}/artifactory/api/go/${r}`).join(",");There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that works, too
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [global] | ||
| index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${try(element(REPOS, 0), "")}/simple | ||
| extra-index-url = | ||
| %{ for REPO in try(slice(REPOS, 1, length(REPOS)), []) ~} | ||
| https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPO}/simple | ||
| %{ endfor ~} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matifali I'm still not fully clear on how we're handling versioning, but we would want this to be version
1.0.19?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we will go with 1.0.19 for now until we resolve #157.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I was bumping the major version since the input variable format for the repos is a breaking change, but if there's an outside constraint, I'll update the readme to reflect the target version of 1.0.19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed a breaking change but we do not want to bump all future modules to 2.0.0 before we do #157.