Skip to content

Commit b302665

Browse files
saw-jannirajacharya2
authored andcommitted
ci: run with keycloak ingress
Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
1 parent 1e59007 commit b302665

File tree

6 files changed

+283
-150
lines changed

6 files changed

+283
-150
lines changed

.drone.star

Lines changed: 89 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ def main(ctx):
518518

519519
pipelines = test_pipelines + build_release_pipelines
520520

521+
# nightly Trivy security scan (non-blocking)
522+
pipelines.append(trivyScan(ctx))
523+
521524
if ctx.build.event == "cron":
522525
pipelines = \
523526
pipelines + \
@@ -598,7 +601,7 @@ def testPipelines(ctx):
598601
pipelines += localApiTestPipeline(ctx)
599602
pipelines += coreApiTestPipeline(ctx)
600603

601-
# pipelines += e2eTestPipeline(ctx) + multiServiceE2ePipeline(ctx)
604+
pipelines += e2eTestPipeline(ctx) + multiServiceE2ePipeline(ctx)
602605

603606
if ("skip" not in config["k6LoadTests"] or not config["k6LoadTests"]["skip"]) and ("k6-test" in ctx.build.title.lower() or ctx.build.event == "cron"):
604607
pipelines += k6LoadTests(ctx)
@@ -1082,6 +1085,11 @@ def localApiTestPipeline(ctx):
10821085
params[item] = matrix[item] if item in matrix else defaults[item]
10831086
for storage in params["storages"]:
10841087
for run_with_remote_php in params["withRemotePhp"]:
1088+
run_on_k3d = params["k3d"] and ctx.build.event == "cron"
1089+
ocis_url = OCIS_URL
1090+
if run_on_k3d:
1091+
ocis_url = "https://%s" % OCIS_SERVER_NAME
1092+
10851093
pipeline = {
10861094
"kind": "pipeline",
10871095
"type": "docker",
@@ -1091,41 +1099,22 @@ def localApiTestPipeline(ctx):
10911099
"arch": "amd64",
10921100
},
10931101
"steps": skipIfUnchanged(ctx, "acceptance-tests") +
1094-
(restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") if not params["k3d"] else []) +
1102+
restoreBuildArtifactCache(ctx, "ocis-binary-amd64", "ocis/bin") +
10951103
(tikaService() if params["tikaNeeded"] else []) +
10961104
(waitForServices("online-offices", ["collabora:9980", "onlyoffice:443", "fakeoffice:8080"]) if params["collaborationServiceNeeded"] else []) +
1097-
(waitk3() + install() + showPodsAfterInstall() if params["k3d"] else ocisServer(storage, extra_server_environment = params["extraServerEnvironment"], with_wrapper = True, tika_enabled = params["tikaNeeded"], volumes = ([stepVolumeOcisStorage])) if not name.startswith("cli") else []) +
1105+
(waitK3sCluster() + deployOcis() + waitForOcis(ocis_url = ocis_url) + ocisServicePods() if run_on_k3d else ocisServer(storage, extra_server_environment = params["extraServerEnvironment"], with_wrapper = True, tika_enabled = params["tikaNeeded"], volumes = ([stepVolumeOcisStorage]))) +
10981106
(waitForClamavService() if params["antivirusNeeded"] else []) +
10991107
(waitForEmailService() if params["emailNeeded"] else []) +
11001108
(ocisServer(storage, deploy_type = "federation", extra_server_environment = params["extraServerEnvironment"]) if params["federationServer"] else []) +
11011109
((wopiCollaborationService("fakeoffice") + wopiCollaborationService("collabora") + wopiCollaborationService("onlyoffice")) if params["collaborationServiceNeeded"] else []) +
11021110
(ocisHealthCheck("wopi", ["wopi-collabora:9304", "wopi-onlyoffice:9304", "wopi-fakeoffice:9304"]) if params["collaborationServiceNeeded"] else []) +
1103-
localApiTests(ctx, name, params["suites"], storage, params["extraEnvironment"], run_with_remote_php, params["k3d"]) +
1111+
localApiTests(ctx, name, params["suites"], storage, params["extraEnvironment"], run_with_remote_php, ocis_url = ocis_url) +
11041112
apiTestFailureLog() +
1105-
(generateCoverageFromAPITest(ctx, name) if not params["k3d"] else []),
1113+
(generateCoverageFromAPITest(ctx, name) if not run_on_k3d else []),
11061114
"services": (emailService() if params["emailNeeded"] else []) +
11071115
(clamavService() if params["antivirusNeeded"] else []) +
11081116
((fakeOffice() + collaboraService() + onlyofficeService()) if params["collaborationServiceNeeded"] else []) +
1109-
([
1110-
{
1111-
"name": "k3d",
1112-
"image": "ghcr.io/k3d-io/k3d:5-dind",
1113-
"user": "root",
1114-
"privileged": True,
1115-
"commands": [
1116-
"git clone https://github.com/nirajacharya2/ocis-charts.git",
1117-
"nohup dockerd-entrypoint.sh &",
1118-
"until docker ps 2>&1 > /dev/null; do sleep 1s; done",
1119-
"k3d cluster create --config ./ocis-charts/ci/k3d-drone.yaml --api-port k3d:443",
1120-
"until kubectl get deployment coredns -n kube-system -o go-template='{{.status.availableReplicas}}' | grep -v -e '<no value>'; do sleep 1s; done",
1121-
"k3d cluster list",
1122-
"k3d kubeconfig get drone > kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
1123-
"chmod 0600 kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
1124-
"printf '@@@@@@@@@@@@@@@@@@@@@@@\n@@@@ k3d is ready @@@@\n@@@@@@@@@@@@@@@@@@@@@@@\n'",
1125-
"kubectl get events -Aw",
1126-
],
1127-
},
1128-
] if params["k3d"] else []),
1117+
(k3sCluster() if run_on_k3d else []),
11291118
"depends_on": getPipelineNames(buildOcisBinaryForTesting(ctx)),
11301119
"trigger": {
11311120
"ref": [
@@ -1179,12 +1168,12 @@ def generateCoverageFromAPITest(ctx, name):
11791168
},
11801169
]
11811170

1182-
def localApiTests(ctx, name, suites, storage = "ocis", extra_environment = {}, with_remote_php = False, run_with_k3 = False):
1171+
def localApiTests(ctx, name, suites, storage = "ocis", extra_environment = {}, with_remote_php = False, ocis_url = OCIS_URL):
11831172
test_dir = "%s/tests/acceptance" % dirs["base"]
11841173
expected_failures_file = "%s/expected-failures-localAPI-on-%s-storage.md" % (test_dir, storage.upper())
11851174

11861175
environment = {
1187-
"TEST_SERVER_URL": OCIS_URL if not run_with_k3 else "https://ocis:9200",
1176+
"TEST_SERVER_URL": ocis_url,
11881177
"TEST_SERVER_FED_URL": OCIS_FED_URL,
11891178
"OCIS_REVA_DATA_ROOT": "%s" % (dirs["ocisRevaDataRoot"] if storage == "owncloud" else ""),
11901179
"STORAGE_DRIVER": storage,
@@ -2641,19 +2630,9 @@ def ocisServer(storage = "ocis", volumes = [], depends_on = [], deploy_type = ""
26412630
"%s/bin/ociswrapper serve --bin %s --url %s --admin-username admin --admin-password admin" % (dirs["ocisWrapper"], ocis_bin, environment["OCIS_URL"]),
26422631
]
26432632

2644-
wait_for_ocis = waitForServices("ocis", [OCIS_DOMAIN])[0]
2645-
if not external_idp:
2646-
wait_for_ocis = {
2647-
"name": "wait-for-%s" % (container_name),
2648-
"image": OC_CI_ALPINE,
2649-
"commands": [
2650-
# wait for ocis-server to be ready (5 minutes)
2651-
"timeout 300 bash -c 'while [ $(curl -sk -uadmin:admin " +
2652-
"%s/graph/v1.0/users/admin " % environment["OCIS_URL"] +
2653-
"-w %{http_code} -o /dev/null) != 200 ]; do sleep 1; done'",
2654-
],
2655-
"depends_on": depends_on,
2656-
}
2633+
wait_for_ocis = waitForOcis(container_name, environment["OCIS_URL"], depends_on)
2634+
if external_idp:
2635+
wait_for_ocis = waitForServices("ocis", [OCIS_DOMAIN])
26572636

26582637
commands = [
26592638
"mkdir -p $GOCOVERDIR",
@@ -2662,19 +2641,16 @@ def ocisServer(storage = "ocis", volumes = [], depends_on = [], deploy_type = ""
26622641
"cp tests/config/drone/app-registry.yaml /root/.ocis/config/app-registry.yaml",
26632642
] + (build_and_run_commands)
26642643

2665-
return [
2666-
{
2667-
"name": container_name,
2668-
"image": OC_CI_GOLANG,
2669-
"detach": True,
2670-
"environment": environment,
2671-
"user": user,
2672-
"commands": commands,
2673-
"volumes": volumes,
2674-
"depends_on": depends_on,
2675-
},
2676-
wait_for_ocis,
2677-
]
2644+
return [{
2645+
"name": container_name,
2646+
"image": OC_CI_GOLANG,
2647+
"detach": True,
2648+
"environment": environment,
2649+
"user": user,
2650+
"commands": commands,
2651+
"volumes": volumes,
2652+
"depends_on": depends_on,
2653+
}] + wait_for_ocis
26782654

26792655
def startOcisService(service = None, name = None, environment = {}, volumes = []):
26802656
"""
@@ -3600,6 +3576,19 @@ def k6LoadTests(ctx):
36003576
},
36013577
}]
36023578

3579+
def waitForOcis(name = "ocis", ocis_url = OCIS_URL, depends_on = []):
3580+
return [{
3581+
"name": "wait-for-%s" % name,
3582+
"image": OC_CI_ALPINE,
3583+
"commands": [
3584+
# wait for ocis-server to be ready (5 minutes)
3585+
"timeout 300 bash -c 'while [ $(curl -sk -uadmin:admin " +
3586+
"%s/graph/v1.0/users/admin " % ocis_url +
3587+
"-w %{http_code} -o /dev/null) != 200 ]; do sleep 1; done'",
3588+
],
3589+
"depends_on": depends_on,
3590+
}]
3591+
36033592
def waitForServices(name, services = []):
36043593
services = ",".join(services)
36053594
return [{
@@ -3745,7 +3734,7 @@ def deleteStaleBranches(ctx):
37453734
},
37463735
}]
37473736

3748-
def trivyScan():
3737+
def trivyScan(ctx):
37493738
steps = [
37503739
{
37513740
"name": "trivy-security-scan",
@@ -3779,111 +3768,62 @@ def trivyScan():
37793768
},
37803769
}
37813770

3782-
def deployments():
3783-
result = {
3784-
"kind": "pipeline",
3785-
"type": "docker",
3786-
"name": "k3d",
3787-
"steps": waitk3() + install() + showPodsAfterInstall() + aftr(),
3788-
"services": [
3789-
{
3790-
"name": "k3d",
3791-
"image": "ghcr.io/k3d-io/k3d:5-dind",
3792-
"user": "root",
3793-
"privileged": True,
3794-
"commands": [
3795-
"git clone https://github.com/owncloud/ocis-charts.git",
3796-
"nohup dockerd-entrypoint.sh &",
3797-
"until docker ps 2>&1 > /dev/null; do sleep 1s; done",
3798-
"k3d cluster create --config ./ocis-charts/ci/k3d-drone.yaml --api-port k3d:443",
3799-
"until kubectl get deployment coredns -n kube-system -o go-template='{{.status.availableReplicas}}' | grep -v -e '<no value>'; do sleep 1s; done",
3800-
"k3d cluster list",
3801-
"k3d kubeconfig get drone > kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3802-
"chmod 0600 kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3803-
"kubectl cluster-info",
3804-
"printf '@@@@@@@@@@@@@@@@@@@@@@@\n@@@@ k3d is ready @@@@\n@@@@@@@@@@@@@@@@@@@@@@@\n'",
3805-
"kubectl get events -Aw",
3806-
],
3807-
},
3808-
],
3809-
"depends_on": [],
3810-
"volumes": [
3811-
{
3812-
"name": "gopath",
3813-
"temp": {},
3814-
},
3815-
],
3816-
"trigger": {
3817-
"ref": [
3818-
"refs/heads/master",
3819-
"refs/tags/**",
3820-
"refs/pull/**",
3821-
],
3822-
},
3823-
}
3824-
3825-
return [result]
3826-
3827-
def waitk3():
3771+
def k3sCluster():
38283772
return [{
3829-
"name": "wait",
3830-
"image": "docker.io/bitnami/kubectl:1.31",
3773+
"name": OCIS_SERVER_NAME,
3774+
"image": "ghcr.io/k3d-io/k3d:5-dind",
38313775
"user": "root",
3776+
"privileged": True,
38323777
"commands": [
3833-
"export KUBECONFIG=kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3834-
"until test -f $${KUBECONFIG}; do sleep 1s; done",
3835-
"kubectl config view",
3836-
"kubectl get pods -A",
3837-
],
3838-
"volumes": [
3839-
{
3840-
"name": "gopath",
3841-
"path": "/go",
3842-
},
3778+
"git clone --single-branch --branch main --depth 1 https://github.com/owncloud/ocis-charts.git",
3779+
"nohup dockerd-entrypoint.sh &",
3780+
"until docker ps 2>&1 > /dev/null; do sleep 1s; done",
3781+
# create cluster
3782+
"k3d cluster create drone --api-port %s:33199 " % OCIS_SERVER_NAME +
3783+
"-p '80:80@loadbalancer' -p '443:443@loadbalancer' " +
3784+
"--k3s-arg '--tls-san=k3d@server:*' --k3s-arg '--disable=metrics-server@server:*'",
3785+
# wait for services to be ready
3786+
"until kubectl get deployment coredns -n kube-system -o go-template='{{.status.availableReplicas}}' | grep -v -e '<no value>'; do sleep 1s; done",
3787+
"until kubectl get deployment traefik -n kube-system -o go-template='{{.status.availableReplicas}}' | grep -v -e '<no value>'; do sleep 1s; done",
3788+
"k3d kubeconfig get drone > kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3789+
"chmod 0600 kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3790+
"printf '@@@@@@@@@@@@@@@@@@@@@@@\n@@@@ k3d is ready @@@@\n@@@@@@@@@@@@@@@@@@@@@@@\n'",
3791+
# add dns rewrite rule
3792+
"kubectl create configmap coredns-custom --namespace kube-system " +
3793+
"--from-literal='rewritehost.override=rewrite name exact %s host.k3d.internal'" % OCIS_SERVER_NAME,
3794+
"kubectl -n kube-system rollout restart deployment coredns",
3795+
# watch events
3796+
"kubectl get events -Aw",
38433797
],
38443798
}]
38453799

3846-
def showPodsAfterInstall():
3800+
def waitK3sCluster():
38473801
return [{
3848-
"name": "testPodsAfterInstall",
3802+
"name": "wait-cluster",
38493803
"image": "docker.io/bitnami/kubectl:1.31",
38503804
"user": "root",
38513805
"commands": [
38523806
"export KUBECONFIG=kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
38533807
"until test -f $${KUBECONFIG}; do sleep 1s; done",
3854-
"kubectl get pods -n ocis",
3855-
"if [ \"$(kubectl get pods -n ocis --field-selector status.phase=Running | wc -l)\" -le \"33\" ]; then exit 1; fi", # there are 32 pods + 1 header line
3856-
"kubectl get ingress -n ocis",
3857-
"if [ \"$(kubectl get ingress -n ocis | wc -l)\" -le \"1\" ]; then exit 1; fi",
3858-
"kubectl get services",
3859-
"kubectl get ingress -n ocis",
3860-
"kubectl get ingress -n ocis -o jsonpath='{.items[*].spec.rules[*].host}'",
3861-
# "kubectl port-forward -n ocis svc/proxy 9200:9200 &",
3862-
# "sleep 5",
3863-
"kubectl get svc --namespace default ocis -o jsonpath='{.status.loadBalancer.ingress[0].ip}'",
3864-
"kubectl get --namespace default -o jsonpath='{.spec.ports[0].port}' services ocis",
3865-
"kubectl describe ingress -n ocis",
3866-
"kubectl get all",
3867-
"kubectl -n ocis get secrets/admin-user --template='{{.data.password | base64decode | printf \"%s\" }}'",
3868-
],
3869-
"volumes": [
3870-
{
3871-
"name": "gopath",
3872-
"path": "/go",
3873-
},
3808+
"kubectl config view",
3809+
"kubectl get pods -A",
38743810
],
38753811
}]
38763812

3877-
def install():
3813+
def deployOcis():
38783814
return [{
3879-
"name": "ocis",
3815+
"name": "deploy-ocis",
38803816
"image": "owncloudci/golang:latest",
38813817
"commands": [
3882-
"cd /drone/src/ocis-charts",
3883-
"export KUBECONFIG=/drone/src/kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3818+
"mv %s/tests/config/drone/k3s/values.yaml %s/ocis-charts/charts/ocis/ci/deployment-values.yaml" % (dirs["base"], dirs["base"]),
3819+
"cp -r %s/tests/config/drone/k3s/authbasic %s/ocis-charts/charts/ocis/templates/" % (dirs["base"], dirs["base"]),
3820+
"cd %s/ocis-charts" % dirs["base"],
3821+
"sed -i '/{{- define \"ocis.basicServiceTemplates\" -}}/a\\\\ {{- $_ := set .scope \"appNameAuthBasic\" \"authbasic\" -}}' ./charts/ocis/templates/_common/_tplvalues.tpl",
3822+
"sed -i '/- name: IDM_ADMIN_PASSWORD/{n;N;N;N;d;}' ./charts/ocis/templates/idm/deployment.yaml",
3823+
"sed -i '/- name: IDM_ADMIN_PASSWORD/a\\\\\\n value: \"admin\"' ./charts/ocis/templates/idm/deployment.yaml",
3824+
"sed -i '/- name: PROXY_HTTP_ADDR/i\\\\ - name: PROXY_ENABLE_BASIC_AUTH\\\n value: \"true\"' ./charts/ocis/templates/proxy/deployment.yaml",
3825+
"export KUBECONFIG=%s/kubeconfig-$${DRONE_BUILD_NUMBER}.yaml" % dirs["base"],
38843826
"make helm-install-atomic",
3885-
# "curl -kv https://k3d:6445/graph/v1.0/me -uadmin:admin",
3886-
# "curl -kv https://ocis/graph/v1.0/me -uadmin:admin",
38873827
],
38883828
"volumes": [
38893829
{
@@ -3893,17 +3833,16 @@ def install():
38933833
],
38943834
}]
38953835

3896-
def aftr():
3836+
def ocisServicePods():
38973837
return [{
3898-
"name": "aftr",
3899-
"image": "owncloudci/golang:latest",
3838+
"name": "ocis-pods",
3839+
"image": "ghcr.io/k3d-io/k3d:5-dind",
3840+
"user": "root",
39003841
"commands": [
3901-
"curl -kv https://ocis/graph/v1.0/me -uadmin:admin",
3902-
],
3903-
"volumes": [
3904-
{
3905-
"name": "gopath",
3906-
"path": "/go",
3907-
},
3842+
"export KUBECONFIG=kubeconfig-$${DRONE_BUILD_NUMBER}.yaml",
3843+
"until test -f $${KUBECONFIG}; do sleep 1s; done",
3844+
"kubectl get pods -A",
3845+
"kubectl get ingress -A",
3846+
"kubectl get svc -A",
39083847
],
39093848
}]

0 commit comments

Comments
 (0)