From ea9b786b83c05dde5da33a5422e7cad70b28a995 Mon Sep 17 00:00:00 2001 From: Jason Stirnaman Date: Wed, 26 Jun 2024 10:26:52 -0500 Subject: [PATCH] fix(ci): test content: - Add python replacement for get-started database/bucket name - Fixes race condition when deleting previous content: - Assign each product it's own test content volume instead of sharing a volume. - Delete existing content in the volume before copying test files. - Pros and cons, but I suspect a similar approach will be better when ported to Circle CI. --- .lintstagedrc.mjs | 19 +++++++++++++++++-- .../cloud-dedicated/get-started/query.md | 2 +- .../cloud-serverless/get-started/query.md | 2 +- .../influxdb/clustered/get-started/query.md | 2 +- test/src/prepare-content.sh | 3 +-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.lintstagedrc.mjs b/.lintstagedrc.mjs index 272981b9c..d07d962d6 100644 --- a/.lintstagedrc.mjs +++ b/.lintstagedrc.mjs @@ -6,14 +6,26 @@ function testStagedContent(paths, productPath) { const TEST = `pytest-${productName}`; return [ - // Remove any existing test container and volume + // Remove existing containers `sh -c "docker rm -f ${CONTENT} || true"`, `sh -c "docker rm -f ${TEST} || true"`, `docker build . -f Dockerfile.tests -t influxdata-docs/tests:latest`, + // Remove any existing Docker volume for staged content + `sh -c "docker volume rm -f ${CONTENT} || true"`, + + // Create a Docker volume for product staged content + `sh -c "docker volume create \ + --label tag=influxdata-docs \ + --label stage=test \ + --name ${CONTENT} || true"`, + // Copy staged content to a volume and run the prepare script + // to remove the existing `docker run --name ${CONTENT} + --label tag=influxdata-docs + --label stage=test --mount type=volume,source=staged-content,target=/app/content --mount type=bind,src=./content,dst=/src/content --mount type=bind,src=./static/downloads,dst=/app/data @@ -38,7 +50,10 @@ function testStagedContent(paths, productPath) { echo 'No tests to run.'; \ exit 0; \ else \ - docker run --rm --name ${TEST} \ + docker run --rm \ + --label tag=influxdata-docs \ + --label stage=test \ + --name ${TEST} \ --env-file ${productPath}/.env.test \ --volumes-from ${CONTENT} \ influxdata-docs/pytest --codeblocks --exitfirst ${productPath}/; diff --git a/content/influxdb/cloud-dedicated/get-started/query.md b/content/influxdb/cloud-dedicated/get-started/query.md index b1f8dde0b..522dced59 100644 --- a/content/influxdb/cloud-dedicated/get-started/query.md +++ b/content/influxdb/cloud-dedicated/get-started/query.md @@ -1014,7 +1014,7 @@ _This tutorial assumes using Maven version 3.9, Java version >= 15, and an `infl - The `App`, `Write`, and `Query` classes belong to the `com.influxdbv3` package (your project **groupId**). - `App` defines a `main()` function that calls `Write.writeLineProtocol()` and `Query.querySQL()`. -4. In your terminal or editor, use Maven to to install dependencies and compile the project code--for example: +4. In your terminal or editor, use Maven to install dependencies and compile the project code--for example: diff --git a/content/influxdb/cloud-serverless/get-started/query.md b/content/influxdb/cloud-serverless/get-started/query.md index 97495746e..bbd5a56df 100644 --- a/content/influxdb/cloud-serverless/get-started/query.md +++ b/content/influxdb/cloud-serverless/get-started/query.md @@ -1008,7 +1008,7 @@ _This tutorial assumes using Maven version 3.9, Java version >= 15, and an `infl - The `App`, `Write`, and `Query` classes belong to the `com.influxdbv3` package (your project **groupId**). - `App` defines a `main()` function that calls `Write.writeLineProtocol()` and `Query.querySQL()`. -4. In your terminal or editor, use Maven to to install dependencies and compile the project code--for example: +4. In your terminal or editor, use Maven to install dependencies and compile the project code--for example: diff --git a/content/influxdb/clustered/get-started/query.md b/content/influxdb/clustered/get-started/query.md index dc5210227..0f704a444 100644 --- a/content/influxdb/clustered/get-started/query.md +++ b/content/influxdb/clustered/get-started/query.md @@ -1010,7 +1010,7 @@ _This tutorial assumes using Maven version 3.9, Java version >= 15, and an `infl - The `App`, `Write`, and `Query` classes belong to the `com.influxdbv3` package (your project **groupId**). - `App` defines a `main()` function that calls `Write.writeLineProtocol()` and `Query.querySQL()`. -4. In your terminal or editor, use Maven to to install dependencies and compile the project code--for example: +4. In your terminal or editor, use Maven to install dependencies and compile the project code--for example: diff --git a/test/src/prepare-content.sh b/test/src/prepare-content.sh index 42ba51e33..6620c5a16 100644 --- a/test/src/prepare-content.sh +++ b/test/src/prepare-content.sh @@ -24,6 +24,7 @@ function substitute_placeholders { s/f"API_TOKEN"/os.getenv("INFLUX_TOKEN")/g; s/f"BUCKET_NAME"/os.getenv("INFLUX_DATABASE")/g; s/f"DATABASE_NAME"/os.getenv("INFLUX_DATABASE")/g; + s/f"get-started"/os.getenv("INFLUX_DATABASE")/g; s|f"{{< influxdb/host >}}"|os.getenv("INFLUX_HOSTNAME")|g; s|f"RETENTION_POLICY_NAME\|RETENTION_POLICY"|"autogen"|g; ' $file @@ -76,8 +77,6 @@ setup() { prepare_tests() { TEST_FILES="$*" - # Remove files from the previous run. - rm -rf "$TEST_CONTENT"/* # Copy the test files to the target directory while preserving the directory structure. for FILE in $TEST_FILES; do # Create the parent directories of the destination file