diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..71f775e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [ "develop" ] + paths-ignore: + - '**.md' + + pull_request: + branches: [ "develop" ] + paths-ignore: + - '**.md' + + # Adds ability to run this workflow manually + workflow_dispatch: + + +jobs: + + lint: + runs-on: ubuntu-latest + env: + HADOLINT_RECURSIVE: "true" + + steps: + - uses: actions/checkout@v3 + - uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: "Dockerfile*" + + + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build source --file source/Dockerfile --tag ci:$(date +%s) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..8ede598 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,64 @@ +name: Docker publish + +on: + push: + branches: [ "main" ] + paths-ignore: + - '**.md' + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + + # Adds ability to run this workflow manually + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value={{date 'YYYYMMDD-HHmm' tz='Europe/Stockholm'}},prefix=${{ github.ref_name }}- + + - name: Output docker image information + run: | + echo "Branch GITHUB_REF##*/: ${GITHUB_REF##*/}" + #echo "github.refname: $github.ref_name" + + - name: Login to GHCR + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + + - name: Publish image to GHCR + uses: docker/build-push-action@v3 + with: + file: ./source/Dockerfile + context: . + push: true + build-args: version=${{ github.ref_name }} + tags: | + ${{ steps.meta.outputs.tags }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index 536aa92..accb6a0 100644 --- a/README.md +++ b/README.md @@ -149,3 +149,12 @@ $ cd ./source $ chmod +x run_test_plan.sh $ ./run_test_plan.sh ``` + + +## Use a custom built docker image + + cd ./source + + docker build -t serve-load-testing . + + docker run -p 8089:8089 serve-load-testing diff --git a/source/Dockerfile b/source/Dockerfile new file mode 100644 index 0000000..9ab6cb5 --- /dev/null +++ b/source/Dockerfile @@ -0,0 +1,14 @@ +# Use the Locust image as the base image +FROM locustio/locust:2.25.0 + +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 + +# Expose the Locust web UI port +EXPOSE 8089 diff --git a/source/locust-ui.conf b/source/locust-ui.conf index 414747b..19f5725 100644 --- a/source/locust-ui.conf +++ b/source/locust-ui.conf @@ -1,5 +1,5 @@ -# locust.conf -locustfile = tests +# locust-ui.conf +locustfile = tests/test_verify_host.py headless = false #master = true #expect-workers = 5 diff --git a/source/start-script.sh b/source/start-script.sh new file mode 100644 index 0000000..ead7f07 --- /dev/null +++ b/source/start-script.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +/home/locust/locust diff --git a/source/tests/base_user_types.py b/source/tests/base_user_types.py index 58584d5..43b64f4 100644 --- a/source/tests/base_user_types.py +++ b/source/tests/base_user_types.py @@ -86,8 +86,8 @@ def register_user(self): last_name="Me", affiliation="other", department="Dept ABC", - password1="ac3ya89ni3wk", - password2="ac3ya89ni3wk", + password1="Ac3ya89ni3wk!", + password2="Ac3ya89ni3wk!", note="", csrfmiddlewaretoken=self.csrftoken, ) @@ -234,12 +234,12 @@ def create_project(self, project_name: str): logger.debug("create project response.status_code = %s, %s", response.status_code, response.reason) # If succeeds then url = // logger.debug("create project response.url = %s", response.url) - if self.username in response.url and project_name in response.url: + if project_name in response.url: logger.info("Successfully created project %s", project_name) self.project_url = response.url else: logger.warning(response.content) - response.failure("Create project failed. Response URL does not contain username and project name.") + response.failure("Create project failed. Response URL does not contain project name.") def delete_project(self): # Update the csrf token @@ -327,8 +327,8 @@ def open_user_app(self): # Staging # ex: https://loadtest-shinyproxy2.staging.serve-dev.scilifelab.se/app/loadtest-shinyproxy2 # from host: https://staging.serve-dev.scilifelab.se - APP_SHINYPROXY = self.host.replace("https://", "https://loadtest-shinyproxy2.") - APP_SHINYPROXY += "/app/loadtest-shinyproxy2" + APP_SHINYPROXY = self.host.replace("https://", "https://loadtest-shinyproxy3.") + APP_SHINYPROXY += "/app/loadtest-shinyproxy3" elif "serve.scilifelab.se" in self.host: # Production