Skip to content

Commit 59061d2

Browse files
authored
chore: switch to build by Docker instead dedicated VM (#138)
1 parent 503a9ec commit 59061d2

File tree

4 files changed

+112
-77
lines changed

4 files changed

+112
-77
lines changed

.circleci/config.yml

+47-70
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,36 @@
2323
version: 2.1
2424

2525
commands:
26-
influxdb-restart:
26+
influxdb-onboarding:
2727
steps:
2828
- run:
29-
name: "Start InfluxDB service"
30-
command: ./scripts/influxdb-restart.sh
29+
name: "Post onBoarding request to InfluxDB 2"
30+
command: ./scripts/influxdb-onboarding.sh
3131
prepare:
3232
description: "Prepare environment to tests"
3333
steps:
3434
- checkout
35-
- influxdb-restart
35+
- influxdb-onboarding
3636
client-test:
3737
description: "Run tests"
3838
parameters:
39-
maven-container:
39+
maven-image:
4040
type: string
41-
default: &default-maven-container "3-jdk-8-slim"
4241
steps:
4342
- restore_cache:
4443
name: Restoring Maven Cache
4544
keys:
46-
- &cache-key maven-cache-<< parameters.maven-container >>-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}
47-
- maven-cache-<< parameters.maven-container >>-
45+
- &cache-key maven-cache_v3-<< parameters.maven-image >>-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}
46+
- maven-cache_v3-<< parameters.maven-image >>-
4847
- run:
4948
name: "Running tests"
5049
command: |
51-
docker run -it --rm \
52-
--volume ${PWD}:/usr/src/mymaven \
53-
--volume ~/.m2:/root/.m2 \
54-
--workdir /usr/src/mymaven \
55-
--network influx_network \
56-
--env INFLUXDB_IP=192.168.0.2 \
57-
--env INFLUXDB_2_IP=192.168.0.3 \
58-
--env INFLUXDB_2_ONBOARDING_IP=192.168.0.4 \
59-
--env INFLUXDB_2_ONBOARDING_PORT=9999 \
60-
maven:<< parameters.maven-container >> mvn -B -U clean install -Dmaven.javadoc.skip=true -Dmaven.dokka.skip=true -Dbuild.env=CI
50+
mvn -B -U clean install -Dmaven.javadoc.skip=true -Dmaven.dokka.skip=true -Dbuild.env=CI
6151
- save_cache:
6252
name: Saving Maven Cache
6353
key: *cache-key
6454
paths:
6555
- ~/.m2
66-
when: always
6756
storing-test-results:
6857
steps:
6958
- run:
@@ -107,39 +96,39 @@ commands:
10796
path: artifacts
10897

10998
jobs:
110-
tests-jdk-8:
111-
machine: true
112-
steps:
113-
- prepare
114-
- client-test:
115-
maven-container: *default-maven-container
116-
- storing-test-results
117-
- storing-artifacts
118-
- run:
119-
name: "Collecting coverage reports"
120-
command: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
12199

122-
tests-jdk-11:
123-
machine: true
100+
tests-java:
124101
parameters:
125-
influxdb-repository:
102+
maven-image:
126103
type: string
127-
default: "influxdb"
128-
influxdb-version:
104+
default: &default-maven-image "circleci/openjdk:8"
105+
influxdb-image:
129106
type: string
130-
default: "2.0.0-beta"
107+
default: &default-influxdb-image "influxdb:2.0.0-beta"
108+
docker:
109+
- image: << parameters.maven-image >>
110+
- image: &influx-image quay.io/influxdb/<< parameters.influxdb-image >>
111+
- image: &influx-image quay.io/influxdb/<< parameters.influxdb-image >>
112+
name: influxdb_v2_onboarding
113+
- image: influxdb:1.8-alpine
114+
environment:
115+
INFLUXDB_HTTP_FLUX_ENABLED: true
131116
environment:
132-
INFLUXDB_V2_REPOSITORY: << parameters.influxdb-repository >>
133-
INFLUXDB_V2_VERSION: << parameters.influxdb-version >>
117+
INFLUXDB_2_ONBOARDING_IP: influxdb_v2_onboarding
118+
INFLUXDB_2_ONBOARDING_PORT: 9999
134119
steps:
135120
- prepare
136121
- client-test:
137-
maven-container: "3-jdk-11-slim"
122+
maven-image: << parameters.maven-image >>
138123
- storing-test-results
139124
- storing-artifacts
125+
- run:
126+
name: "Collecting coverage reports"
127+
command: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
140128

141129
deploy-snapshot:
142-
machine: true
130+
docker:
131+
- image: *default-maven-image
143132
steps:
144133
- run:
145134
name: Early return if this build is from a forked repository
@@ -160,52 +149,38 @@ jobs:
160149
echo "Nothing to do for this build, so marking this step successful"
161150
circleci step halt
162151
fi
163-
- influxdb-restart
164152
- restore_cache:
165153
name: Restoring Maven Cache
166154
keys:
167-
- &cache-key-deploy maven-cache-deploy-3-jdk-8-slim-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}
168-
- maven-cache-deploy-3-jdk-8-slim-
169-
- maven-cache-3-jdk-8-slim-
155+
- &cache-key-deploy maven-cache-deploy_v2-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}
156+
- maven-cache-deploy_v2-
170157
- run:
171158
name: Deploying Snapshot
172159
command: |
173-
docker run -it --rm \
174-
--volume ${PWD}:/usr/src/mymaven \
175-
--volume ~/.m2:/root/.m2 \
176-
--workdir /usr/src/mymaven \
177-
--network influx_network \
178-
--env INFLUXDB_IP=192.168.0.2 \
179-
--env INFLUXDB_2_IP=192.168.0.3 \
180-
--env INFLUXDB_2_ONBOARDING_IP=192.168.0.4 \
181-
--env INFLUXDB_2_ONBOARDING_PORT=9999 \
182-
--env SONATYPE_USERNAME=${SONATYPE_USERNAME} \
183-
--env SONATYPE_PASSWORD=${SONATYPE_PASSWORD} \
184-
maven:3-jdk-8-slim mvn -s scripts/deploy-settings.xml -DskipTests=true clean package deploy
160+
mvn -s scripts/deploy-settings.xml -DskipTests=true clean package deploy
185161
- save_cache:
186162
name: Saving Maven Cache
187163
key: *cache-key-deploy
188164
paths:
189165
- ~/.m2
190-
when: always
191166

192167
workflows:
193168
version: 2
194169
build:
195170
jobs:
196-
- tests-jdk-8:
197-
name: jdk-8-beta
198-
- tests-jdk-11:
199-
name: jdk-11-beta
200-
- tests-jdk-11:
201-
name: jdk-11-nightly
202-
influxdb-repository: "influx"
203-
influxdb-version: "nightly"
171+
- tests-java:
172+
name: jdk-8
173+
- tests-java:
174+
name: jdk-11
175+
maven-image: "circleci/openjdk:11"
176+
- tests-java:
177+
name: jdk-8-nightly
178+
influxdb-image: "influx:nightly"
204179
- deploy-snapshot:
205180
requires:
206-
- jdk-8-beta
207-
- jdk-11-beta
208-
- jdk-11-nightly
181+
- jdk-8
182+
- jdk-11
183+
- jdk-8-nightly
209184
filters:
210185
branches:
211186
only: master
@@ -219,5 +194,7 @@ workflows:
219194
only:
220195
- master
221196
jobs:
222-
- tests-jdk-8
223-
- tests-jdk-11
197+
- tests-java
198+
- tests-java:
199+
name: jdk-11-beta
200+
maven-image: "circleci/openjdk:11"

client-legacy/src/test/java/com/influxdb/client/flux/AbstractITFluxClient.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class AbstractITFluxClient extends AbstractTest {
4444
protected void setUp() {
4545

4646
String influxURL = getInfluxDbUrl();
47-
47+
4848
LOG.log(Level.FINEST, "Influx URL: {0}", influxURL);
4949

5050
FluxConnectionOptions options = FluxConnectionOptions.builder()
@@ -54,6 +54,7 @@ protected void setUp() {
5454
fluxClient = FluxClientFactory.create(options);
5555

5656
influxDBQuery("CREATE DATABASE " + DATABASE_NAME, DATABASE_NAME);
57+
waitToInflux();
5758
}
5859

5960
@AfterEach
@@ -62,5 +63,15 @@ protected void after() {
6263
fluxClient.close();
6364

6465
influxDBQuery("DROP DATABASE " + DATABASE_NAME, DATABASE_NAME);
66+
waitToInflux();
67+
}
68+
69+
private void waitToInflux() {
70+
// Get Rest to InfluxDB
71+
try {
72+
Thread.sleep(1_000);
73+
} catch (InterruptedException e) {
74+
throw new IllegalStateException(e);
75+
}
6576
}
6677
}

client/src/test/java/com/influxdb/client/AbstractITClientTest.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ abstract class AbstractITClientTest extends AbstractTest {
4545
InfluxDBClient influxDBClient;
4646
String influxDB_IP;
4747
String influxDB_URL;
48+
private static Organization myOrg;
4849

4950
@BeforeEach
50-
void initInfluxDBClientClient(TestInfo testInfo) throws Exception {
51+
void initInfluxDBClientClient(TestInfo testInfo) {
5152

5253
influxDB_IP = getInfluxDb2Ip();
5354
influxDB_URL = getInfluxDb2Url();
@@ -75,10 +76,14 @@ BucketRetentionRules retentionRule() {
7576

7677
@Nonnull
7778
Organization findMyOrg() {
78-
return influxDBClient.getOrganizationsApi()
79-
.findOrganizations().stream()
80-
.filter(organization -> organization.getName().equals("my-org"))
81-
.findFirst()
82-
.orElseThrow(IllegalStateException::new);
79+
if (myOrg == null) {
80+
myOrg = influxDBClient.getOrganizationsApi()
81+
.findOrganizations().stream()
82+
.filter(organization -> organization.getName().equals("my-org"))
83+
.findFirst()
84+
.orElseThrow(IllegalStateException::new);
85+
}
86+
87+
return myOrg;
8388
}
8489
}

scripts/influxdb-onboarding.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
echo "Wait to start InfluxDB"
27+
wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:8086/ping
28+
29+
echo "Wait to start InfluxDB 2.0"
30+
wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:9999/metrics
31+
32+
echo
33+
echo "Post onBoarding request, to setup initial user (my-user@my-password), org (my-org) and bucketSetup (my-bucket)"
34+
echo
35+
curl -i -X POST http://localhost:9999/api/v2/setup -H 'accept: application/json' \
36+
-d '{
37+
"username": "my-user",
38+
"password": "my-password",
39+
"org": "my-org",
40+
"bucket": "my-bucket",
41+
"token": "my-token"
42+
}'

0 commit comments

Comments
 (0)