Skip to content

Commit

Permalink
Add support for using a HTTPS catalog URL for arbitrary catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Dec 17, 2024
1 parent 85a1630 commit b3f88d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions gitlab/commodore-compile.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ local cpu_requests = to_array('cpu_requests');

local gitInsteadOf(cluster) =
local cluster_access_token = '${ACCESS_TOKEN_%s}' % std.strReplace(cluster, '-', '_');
local cluster_access_user = '${ACCESS_USER_%s:-token}' % std.strReplace(cluster, '-', '_');
local cluster_repo = cluster_catalog_urls[cluster];
local ssh_gitlab = 'ssh://git@%s/' % gitlab_ssh_host;
local catalog_path = if std.startsWith(cluster_repo, ssh_gitlab) then
// prefix ssh://git@<host> 0 == ssh, 1 == '', 2 == <host>
std.join('/', std.split(cluster_repo, '/')[3:]);

local https_catalog = if std.startsWith(cluster_repo, 'https://') then
std.substr(cluster_repo, std.length('https://'), std.length(cluster_repo));

local catalogInsteadOf =
if catalog_path != null then
[
Expand All @@ -36,6 +40,14 @@ local gitInsteadOf(cluster) =
gitlab_fqdn: gitlab_fqdn,
},
]
else if https_catalog != null then
[
'git config --global url."https://%(catalog_user)s:%(access_token)s@%(https_catalog)s".insteadOf https://%(https_catalog)s' % {
catalog_user: cluster_access_user,
access_token: cluster_access_token,
https_catalog: https_catalog,
},
]
else
[];

Expand Down
2 changes: 1 addition & 1 deletion gitlab/tests/external-catalog.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CLUSTERS="c-cluster-id-1234 c-cluster-id-5678 c-cluster-id-1111"
CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git c-cluster-id-5678=ssh://git@git.example.com/cluster-catalogs/c-cluster-id-5678.git c-cluster-id-1111=https://user:pass@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5"
CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git c-cluster-id-5678=ssh://git@git.example.com/cluster-catalogs/c-cluster-id-5678.git c-cluster-id-1111=https://git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5"
2 changes: 2 additions & 0 deletions gitlab/tests/golden/external-catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
"script": [
"git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}",
"git config --global url.\"https://${ACCESS_USER_c_cluster_id_1111:-token}:${ACCESS_TOKEN_c_cluster_id_1111}@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5\".insteadOf https://git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5",
"/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-1111",
"(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)"
],
Expand All @@ -47,6 +48,7 @@
],
"script": [
"git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}",
"git config --global url.\"https://${ACCESS_USER_c_cluster_id_1111:-token}:${ACCESS_TOKEN_c_cluster_id_1111}@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5\".insteadOf https://git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5",
"/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-1111"
],
"stage": "deploy",
Expand Down

0 comments on commit b3f88d5

Please sign in to comment.