Skip to content

Commit 125cebe

Browse files
wip
1 parent 986a398 commit 125cebe

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,26 @@ jobs:
1111
default: ""
1212
docker:
1313
- image: << parameters.maven-image >>
14+
- image: influxdb:3-core
15+
environment:
16+
- INFLUXDB3_NODE_IDENTIFIER_PREFIX=node01
17+
- INFLUXDB3_OBJECT_STORE=file
18+
- INFLUXDB3_DB_DIR=/var/lib/influxdb3/data
1419
steps:
1520
- checkout
1621
- restore_cache:
1722
name: Restoring Maven Cache
1823
keys:
1924
- &cache-key maven-cache_v1-<< parameters.maven-image >>-{{ checksum "pom.xml" }}
2025
- maven-cache_v3-<< parameters.maven-image >>-
26+
- run:
27+
name: Setup InfluxDB service
28+
command: |
29+
chmod +x ./scripts/influxdb-setup.sh
30+
./scripts/influxdb-setup.sh \
31+
--export-url-as TESTING_INFLUXDB_URL \
32+
--export-db-as TESTING_INFLUXDB_DATABASE \
33+
--export-token-as TESTING_INFLUXDB_TOKEN
2134
- run:
2235
name: "Running tests"
2336
command: |

scripts/influxdb-setup.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env bash
2+
#
3+
# The MIT License
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
#
23+
24+
set -e
25+
26+
DEFAULT_INFLUXDB_DATABASE=my-db
27+
INFLUXDB_DATABASE="${INFLUXDB_DATABASE:-$DEFAULT_INFLUXDB_DATABASE}"
28+
29+
#
30+
# Parse command line arguments
31+
#
32+
EXPORT_URL_ENV_VAR=""
33+
EXPORT_DB_ENV_VAR=""
34+
EXPORT_TOKEN_ENV_VAR=""
35+
while [[ $# -gt 0 ]]; do
36+
case $1 in
37+
--export-url-as)
38+
EXPORT_URL_ENV_VAR="$2"
39+
shift 2
40+
;;
41+
--export-db-as)
42+
EXPORT_DB_ENV_VAR="$2"
43+
shift 2
44+
;;
45+
--export-token-as)
46+
EXPORT_TOKEN_ENV_VAR="$2"
47+
shift 2
48+
;;
49+
*)
50+
echo "Unknown option $1"
51+
exit 1
52+
;;
53+
esac
54+
done
55+
56+
#
57+
# Check prerequisites
58+
#
59+
for cmd in curl jq; do
60+
command -v ${cmd} &>/dev/null || { echo "'${cmd}' is not installed"; exit 1; }
61+
done
62+
63+
echo
64+
echo "Wait to start InfluxDB 3.0"
65+
echo
66+
for i in {1..30}; do
67+
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8181/ping | grep -q "401"; then
68+
break
69+
fi
70+
echo "Attempt $i/30: Waiting for InfluxDB to respond with 401..."
71+
sleep 1
72+
done
73+
echo "Done"
74+
75+
echo
76+
echo "Create admin token"
77+
echo
78+
ADMIN_TOKEN=$(curl -s -X POST http://localhost:8181/api/v3/configure/token/admin | jq -r '.token')
79+
if [[ -z "$ADMIN_TOKEN" || "$ADMIN_TOKEN" == "null" ]]; then
80+
echo "Failed to create admin token"
81+
exit 1
82+
fi
83+
echo "ADMIN_TOKEN=$ADMIN_TOKEN"
84+
85+
echo
86+
echo "Test the token"
87+
echo
88+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${ADMIN_TOKEN}" http://localhost:8181/ping)
89+
if [[ "$HTTP_CODE" != "200" ]]; then
90+
echo "Token test failed with HTTP $HTTP_CODE"
91+
exit 1
92+
fi
93+
echo "Done"
94+
95+
echo
96+
echo "Create database"
97+
echo
98+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "http://localhost:8181/api/v3/configure/database" \
99+
-H "Authorization: Bearer ${ADMIN_TOKEN}" \
100+
-H "Content-Type: application/json" \
101+
-d "{\"db\":\"${INFLUXDB_DATABASE}\"}")
102+
if [[ "$HTTP_CODE" != "200" ]]; then
103+
echo "Database creation failed with HTTP $HTTP_CODE"
104+
exit 1
105+
fi
106+
echo "Done"
107+
108+
#
109+
# Export results
110+
#
111+
112+
export_var() {
113+
local var_name="$1" var_value="$2"
114+
[[ -n "$var_name" ]] || return
115+
[[ -n "$BASH_ENV" ]] || { echo "\$BASH_ENV not available (not in CircleCI), cannot export variables."; exit 1; }
116+
echo "Exporting $var_name=$var_value"
117+
echo "export $var_name=$var_value" >> "$BASH_ENV"
118+
}
119+
120+
echo
121+
export_var "$EXPORT_URL_ENV_VAR" "http://localhost:8181"
122+
export_var "$EXPORT_DB_ENV_VAR" "$INFLUXDB_DATABASE"
123+
export_var "$EXPORT_TOKEN_ENV_VAR" "$ADMIN_TOKEN"
124+

0 commit comments

Comments
 (0)