diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 8ede598..1746d4b 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -13,7 +13,8 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + IMAGE_NAME: scilifelabdatacentre/serve-load-testing + #IMAGE_NAME: ${{ github.repository }} jobs: @@ -55,7 +56,7 @@ jobs: uses: docker/build-push-action@v3 with: file: ./source/Dockerfile - context: . + context: ./source push: true build-args: version=${{ github.ref_name }} tags: | diff --git a/.gitignore b/.gitignore index 90ae6d7..536e017 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,9 @@ dmypy.json # Cython debug symbols cython_debug/ +# Locust deployment +locust-auth + # Locust output files source/reports/* !source/reports/.gitkeep diff --git a/README.md b/README.md index accb6a0..d78f4a6 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,6 @@ $ chmod +x run_test_plan.sh $ ./run_test_plan.sh ``` - ## Use a custom built docker image cd ./source @@ -158,3 +157,26 @@ $ ./run_test_plan.sh docker build -t serve-load-testing . docker run -p 8089:8089 serve-load-testing + +## Deploy to kubernetes + +### Using ArgoCD + +Create a new ArgoCD app using the application manifest ./argocd/application.yaml + +### Using CLI kubectl + +Create a deployment named locust-deployment in a new namespace locust: + + kubectl apply -f ./manifests --force + +### Create a secret for the Locust web UI + +Create a secret named locust-ui-secret. +Required apache2-utils + + sudo apt install apache2-utils + + htpasswd -bc locust-auth locust + + kubectl -n locust create secret generic locust-ui-secret --from-file=locust-auth diff --git a/argocd/application.yaml b/argocd/application.yaml new file mode 100644 index 0000000..d1d4f21 --- /dev/null +++ b/argocd/application.yaml @@ -0,0 +1,16 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: serve-locust +spec: + destination: + namespace: locust + server: 'https://kubernetes.default.svc' + project: default + source: + repoURL: https://github.com/ScilifelabDataCentre/serve-load-testing + path: manifests + targetRevision: develop + syncPolicy: + syncOptions: + - CreateNamespace=true diff --git a/manifests/deployment.yaml b/manifests/deployment.yaml new file mode 100644 index 0000000..dbdc5bd --- /dev/null +++ b/manifests/deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: locust-deployment + namespace: locust +spec: + replicas: 1 + selector: + matchLabels: + app: locust + template: + metadata: + labels: + app: locust + annotations: + statefulset.kubernetes.io/pod-name: locust + spec: + containers: + - name: locust + image: ghcr.io/scilifelabdatacentre/serve-load-testing:main-20240419-1108 + ports: + - containerPort: 8089 diff --git a/manifests/ingress.yaml b/manifests/ingress.yaml new file mode 100644 index 0000000..a75fcf0 --- /dev/null +++ b/manifests/ingress.yaml @@ -0,0 +1,28 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: locust-ingress + namespace: locust + annotations: + kubernetes.io/ingress.class: "nginx" + cert-manager.io/cluster-issuer: "letsencrypt-issuer" + nginx.ingress.kubernetes.io/auth-type: basic + nginx.ingress.kubernetes.io/auth-secret: locust-ui-secret + nginx.ingress.kubernetes.io/auth-realm: "Protected area" +spec: + rules: + - host: locust.serve-dev.scilifelab.se #localhost + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: locust-service + port: + number: 80 #8089 + #ingressClassName: nginx + tls: + - hosts: + - locust.serve-dev.scilifelab.se + secretName: locust-tls diff --git a/manifests/namespace.yaml b/manifests/namespace.yaml new file mode 100644 index 0000000..c523ff4 --- /dev/null +++ b/manifests/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: locust diff --git a/manifests/service.yaml b/manifests/service.yaml new file mode 100644 index 0000000..1319340 --- /dev/null +++ b/manifests/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: locust-service + namespace: locust +spec: + selector: + app: locust + ports: + - protocol: TCP + port: 80 #8089 + targetPort: 8089 + type: ClusterIP #NodePort diff --git a/source/Dockerfile b/source/Dockerfile index 9ab6cb5..5eb1dce 100644 --- a/source/Dockerfile +++ b/source/Dockerfile @@ -6,9 +6,10 @@ WORKDIR /home/locust # TODO: pip install requirements without locust # Copy the Locust files into the container -COPY locust-ui.conf locust.conf -COPY tests/ tests -COPY start-script.sh start-script.sh +COPY --chown=locust:locust locust-ui.conf locust.conf +COPY --chown=locust:locust tests/ tests +COPY --chown=locust:locust start-script.sh start-script.sh -# Expose the Locust web UI port -EXPOSE 8089 +RUN chmod ug+x start-script.sh + +EXPOSE 8089 5557 diff --git a/source/start-script.sh b/source/start-script.sh index ead7f07..cd3787d 100644 --- a/source/start-script.sh +++ b/source/start-script.sh @@ -1,3 +1,3 @@ #!/bin/bash -/home/locust/locust +locust