Skip to content

Commit d97bd50

Browse files
author
Daniel Mikusa
committed
Migration of CI (#1102)
* Add support for claim/unclaim environments and using them with integration tests * Install jq into the test container for extraction of credentials * Updates domain name used in integration tests * Change range of ports used for TCP route tests * Update claim script to patch the environment and enable TCP routes
1 parent 242be67 commit d97bd50

File tree

9 files changed

+194
-28
lines changed

9 files changed

+194
-28
lines changed

ci/claim-environment.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/../..)
6+
7+
if [[ -d "${ROOT}"/om ]]; then
8+
printf "➜ Expanding om\n"
9+
tar xzf "${ROOT}"/om/om-linux-*.tar.gz -C "${ROOT}"/om
10+
export PATH="${ROOT}"/om:${PATH}
11+
fi
12+
13+
printf "Claiming environment from %s\n" "${POOL}"
14+
15+
CLAIM=$(curl \
16+
--fail \
17+
--location \
18+
--show-error \
19+
--silent \
20+
--header 'Accept: application/json' \
21+
--request "POST" \
22+
"https://environments.toolsmiths.cf-app.com/pooled_gcp_engineering_environments/claim?api_token=${API_TOKEN}&pool_name=${POOL}&notes=Claimed%20by%20Java%20Buildpack%20CI")
23+
24+
printf "Claimed %s\n" "$(jq -n -r --argjson claim "${CLAIM}" '$claim.name')"
25+
26+
CREDENTIALS=$(om \
27+
--target "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.url')" \
28+
--username "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.username')" \
29+
--password "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.password')" \
30+
credentials \
31+
--product-name cf \
32+
--credential-reference .uaa.admin_credentials \
33+
--format json)
34+
35+
jq \
36+
-n -r \
37+
--argjson claim "${CLAIM}" \
38+
--argjson credentials "${CREDENTIALS}" \
39+
'{ name: $claim.name, username: $credentials.identity, password: $credentials.password }' \
40+
> "${ROOT}"/environment/cf-creds.json
41+
42+
43+
CREDENTIALS=$(om \
44+
--target "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.url')" \
45+
--username "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.username')" \
46+
--password "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.password')" \
47+
credentials \
48+
--product-name cf \
49+
--credential-reference .uaa.admin_client_credentials \
50+
--format json)
51+
52+
jq \
53+
-n -r \
54+
--argjson claim "${CLAIM}" \
55+
--argjson credentials "${CREDENTIALS}" \
56+
'{ client: $credentials.identity, secret: $credentials.password }' \
57+
> "${ROOT}"/environment/uaa-creds.json
58+
59+
printf "Patching for TCP Routing Support\n"
60+
61+
om \
62+
--target "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.url')" \
63+
--username "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.username')" \
64+
--password "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.password')" \
65+
staged-config \
66+
--product-name cf > /tmp/cf.yml
67+
68+
TCP_ROUTES_LB="$(jq -n -r --argjson claim "${CLAIM}" '$claim.tcp_router_pool')"
69+
70+
om \
71+
--target "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.url')" \
72+
--username "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.username')" \
73+
--password "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.password')" \
74+
configure-product \
75+
--config /tmp/cf.yml \
76+
--ops-file cf-java-client/ci/tcp-routes.yml \
77+
--var TCP_ROUTES_LB="tcp:${TCP_ROUTES_LB}"
78+
79+
om \
80+
--target "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.url')" \
81+
--username "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.username')" \
82+
--password "$(jq -n -r --argjson claim "${CLAIM}" '$claim.ops_manager.password')" \
83+
apply-changes \
84+
-n cf
85+
86+
printf "Environment updated with TCP Routes\n"

ci/claim-environment.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
platform: linux
3+
4+
image_resource:
5+
type: registry-image
6+
source:
7+
repository: cfje/cf-java-client
8+
9+
inputs:
10+
- name: cf-java-client
11+
- name: om
12+
13+
outputs:
14+
- name: environment
15+
16+
run:
17+
path: cf-java-client/ci/claim-environment.sh
18+
19+
params:
20+
API_TOKEN:
21+
POOL:

ci/integration-test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,37 @@
22

33
set -euo pipefail
44

5+
# update & install jq
6+
apt-get update && apt-get -y install jq
7+
58
[[ -d $PWD/maven && ! -d $HOME/.m2 ]] && ln -s $PWD/maven $HOME/.m2
69

10+
ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/../..)
11+
12+
if [[ -d "${ROOT}"/om ]]; then
13+
printf "➜ Expanding om\n"
14+
tar xzf "${ROOT}"/om/om-linux-*.tar.gz -C "${ROOT}"/om
15+
export PATH="${ROOT}"/om:${PATH}
16+
fi
17+
18+
CF_CREDS=$(cat "${ROOT}"/environment/cf-creds.json)
19+
20+
TEST_APIHOST=$(jq -n -r --argjson credentials "${CF_CREDS}" '"api.sys.\($credentials.name).cf-app.com"')
21+
export TEST_APIHOST
22+
23+
TEST_ADMIN_USERNAME=$(jq -n -r --argjson credentials "${CF_CREDS}" '$credentials.username')
24+
export TEST_ADMIN_USERNAME
25+
26+
TEST_ADMIN_PASSWORD=$(jq -n -r --argjson credentials "${CF_CREDS}" '$credentials.password')
27+
export TEST_ADMIN_PASSWORD
28+
29+
UAA_CREDS=$(cat "${ROOT}"/environment/uaa-creds.json)
30+
31+
TEST_ADMIN_CLIENTID=$(jq -n -r --argjson credentials "${UAA_CREDS}" '$credentials.client')
32+
export TEST_ADMIN_CLIENTID
33+
34+
TEST_ADMIN_CLIENTSECRET=$(jq -n -r --argjson credentials "${UAA_CREDS}" '$credentials.secret')
35+
export TEST_ADMIN_CLIENTSECRET
36+
737
cd cf-java-client
838
./mvnw -q -P integration-test test

ci/integration-test.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

ci/tcp-routes.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- type: replace
3+
path: /product-properties/.properties.tcp_routing
4+
value:
5+
selected_option: enable
6+
value: enable
7+
- type: replace
8+
path: /product-properties/.properties.tcp_routing.enable.request_timeout_in_seconds?
9+
value:
10+
value: 300
11+
- type: replace
12+
path: /product-properties/.properties.tcp_routing.enable.reservable_ports?
13+
value:
14+
value: 1024-1123
15+
- type: replace
16+
path: /resource-config/tcp_router/elb_names/-
17+
value: "((TCP_ROUTES_LB))"
18+
- type: replace
19+
path: /resource-config/tcp_router/instances
20+
value: automatic

ci/unclaim-environment.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/../..)
6+
7+
CREDENTIALS=$(cat "${ROOT}"/environment/cf-creds.json)
8+
9+
printf "Unclaiming %s\n" "$(jq -n -r --argjson credentials "${CREDENTIALS}" '$credentials.name')"
10+
11+
curl \
12+
--fail \
13+
--location \
14+
--show-error \
15+
--silent \
16+
--request "POST" \
17+
"https://environments.toolsmiths.cf-app.com/pooled_gcp_engineering_environments/unclaim?api_token=${API_TOKEN}&name=$(jq -n -r --argjson credentials "${CREDENTIALS}" '$credentials.name')"

ci/unclaim-environment.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
platform: linux
3+
4+
image_resource:
5+
type: registry-image
6+
source:
7+
repository: cfje/cf-java-client
8+
9+
inputs:
10+
- name: environment
11+
- name: cf-java-client
12+
13+
run:
14+
path: cf-java-client/ci/unclaim-environment.sh
15+
16+
params:
17+
API_TOKEN:

integration-test/src/test/java/org/cloudfoundry/RandomNameFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
final class RandomNameFactory implements NameFactory {
2828

29-
private static final int PORT_MAXIMUM = 61_099;
29+
private static final int PORT_MAXIMUM = 1122;
3030

31-
private static final int PORT_MINIMUM = 61_001;
31+
private static final int PORT_MINIMUM = 1025;
3232

3333
private final Random random;
3434

integration-test/src/test/java/org/cloudfoundry/client/v3/OrganizationsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void getDefaultDomain() {
152152
.build()))
153153
.map(GetOrganizationDefaultDomainResponse::getName)
154154
.as(StepVerifier::create)
155-
.consumeNextWith(name -> assertThat(name).contains("apps.", ".springapps.io"))
155+
.consumeNextWith(name -> assertThat(name).contains("apps.", ".cf-app.com"))
156156
.expectComplete()
157157
.verify(Duration.ofMinutes(5));
158158
}

0 commit comments

Comments
 (0)