diff --git a/infrastructure/c4k-website-build/image/resources/entrypoint.sh b/infrastructure/c4k-website-build/image/resources/entrypoint.sh index aa4dcf5..52eff16 100755 --- a/infrastructure/c4k-website-build/image/resources/entrypoint.sh +++ b/infrastructure/c4k-website-build/image/resources/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -# curl -s -H "Authorization: token d92668fff6e005582dcb09c6590982a39b2523fc" https://repo.prod.meissa.de/api/v1/repos/meissa-intern/meissa-io/git/commits/HEAD | jq '.' +# curl -s -H "Authorization: token xxxx" https://gitea.host/api/v1/repos/{owner}/{repo}/git/commits/HEAD | jq '.sha' mkdir $BUILDDIR mkdir $SOURCEDIR diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index b899770..e3cbcea 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -1,5 +1,5 @@ #!/bin/bash -# curl -s -H "Authorization: token xxxx" https://repo.prod.meissa.de/api/v1/repos/meissa-intern/meissa-io/git/commits/HEAD | jq '.sha' +# curl -s -H "Authorization: token xxxx" https://gitea.host/api/v1/repos/{owner}/{repo}/git/commits/HEAD | jq '.sha' function get-website-data() { curl -H "Authorization: token $AUTHTOKEN" -o $SOURCEDIR/$1 $GITREPOURL diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index bb1d09f..f9177f0 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -98,6 +98,13 @@ branch string?] (str "https://" host "/api/v1/repos/" user "/" repo "/archive/" branch ".zip")) +; https://your.gitea.host/api/v1/repos///git/commits/HEAD +(defn-spec generate-gitcommiturl string? + [host pred/fqdn-string? + repo string? + user string?] + (str "https://" host "/api/v1/repos/" user "/" repo "/git/" "commits/" "HEAD")) + (defn-spec replace-all-matching-substrings-beginning-with pred/map-or-seq? [col pred/map-or-seq? value-to-partly-match string? @@ -204,10 +211,15 @@ (-> (replace-common-data "website/website-build-secret.yaml" auth) (cm/replace-all-matching-values-by-new-value "TOKEN" (b64/encode authtoken)) - (cm/replace-all-matching-values-by-new-value "URL" (b64/encode - (generate-gitrepourl + (cm/replace-all-matching-values-by-new-value "REPOURL" (b64/encode + (generate-gitrepourl gitea-host gitea-repo username - branchname)))))) + branchname))) + (cm/replace-all-matching-values-by-new-value "COMMITURL" (b64/encode + (generate-gitcommiturl + gitea-host + gitea-repo + username)))))) diff --git a/src/main/resources/website/website-build-secret.yaml b/src/main/resources/website/website-build-secret.yaml index 405eaf8..770ce10 100644 --- a/src/main/resources/website/website-build-secret.yaml +++ b/src/main/resources/website/website-build-secret.yaml @@ -6,6 +6,7 @@ metadata: app.kubernetes.part-of: NAME-website data: AUTHTOKEN: TOKEN - GITREPOURL: URL + GITREPOURL: REPOURL + GITCOMMITURL: COMMITURL \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index 4989809..51facb0 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -214,30 +214,25 @@ :branchname "main", :unique-name "test.io"})))) + + (deftest should-generate-website-build-secret - (is (= {:name-c1 "test-io-secret", - :name-c2 "test-org-secret", - :AUTHTOKEN-c1 (b64/encode "token1"), - :AUTHTOKEN-c2 (b64/encode "token2"), - :GITREPOURL-c1 (b64/encode "https://gitlab.org/api/v1/repos/dumpty/websitebau/archive/testname.zip"), - :GITREPOURL-c2 (b64/encode "https://github.com/api/v1/repos/humpty/websitedachs/archive/testname.zip"), - :app.kubernetes.part-of-c1 "test-io-website", - :app.kubernetes.part-of-c2 "test-org-website"} - (th/map-diff (cut/generate-website-build-secret {:unique-name "test.io", - :authtoken "token1", - :gitea-host "gitlab.org", - :gitea-repo "websitebau", - :username "dumpty", - :branchname "testname", - :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]} - ) - (cut/generate-website-build-secret {:unique-name "test.org", - :authtoken "token2", - :gitea-host "github.com", - :gitea-repo "websitedachs", - :username "humpty", - :branchname "testname", - :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}))))) + (is (= {:apiVersion "v1", + :kind "Secret", + :metadata {:name "test-io-secret", :labels {:app.kubernetes.part-of "test-io-website"}}, + :data + {:AUTHTOKEN "YWJlZGpnYmFzZG9kag==", + :GITREPOURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vYXJjaGl2ZS9tYWluLnppcA==", + :GITCOMMITURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vZ2l0L2NvbW1pdHMvSEVBRA=="}} + (cut/generate-website-build-secret {:authtoken "abedjgbasdodj", + :gitea-host "gitlab.de", + :username "someuser", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :gitea-repo "repo", + :sha256sum-output "123456789ab123cd345de script-file-name.sh", + :issuer "staging", + :branchname "main", + :unique-name "test.io"})))) (deftest should-generate-website-content-volume (is (= {:name-c1 "test-io-content-volume",