-
Notifications
You must be signed in to change notification settings - Fork 39
231 lines (204 loc) · 9.2 KB
/
proxyTesting.yml
File metadata and controls
231 lines (204 loc) · 9.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Proxy Test with Dual Squid Proxies
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
proxy-test:
runs-on:
group: databricks-protected-runner-group
labels: linux-ubuntu-latest
steps:
################################################################
# 1) Check Out the Repo
################################################################
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
################################################################
# 2) Set Up Java
################################################################
- name: Set Up Java
uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4
with:
java-version: "21"
distribution: "adopt"
################################################################
# 3) Configure Maven
################################################################
- name: Get JFrog OIDC token
run: |
set -euo pipefail
# Get GitHub OIDC ID token
ID_TOKEN=$(curl -sLS \
-H "User-Agent: actions/oidc-client" \
-H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=jfrog-github" | jq .value | tr -d '"')
echo "::add-mask::${ID_TOKEN}"
# Exchange for JFrog access token
ACCESS_TOKEN=$(curl -sLS -XPOST -H "Content-Type: application/json" \
"https://databricks.jfrog.io/access/api/v1/oidc/token" \
-d "{\"grant_type\": \"urn:ietf:params:oauth:grant-type:token-exchange\", \"subject_token_type\":\"urn:ietf:params:oauth:token-type:id_token\", \"subject_token\": \"${ID_TOKEN}\", \"provider_name\": \"github-actions\"}" | jq .access_token | tr -d '"')
echo "::add-mask::${ACCESS_TOKEN}"
if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" = "null" ]; then
echo "FAIL: Could not extract JFrog access token"
exit 1
fi
echo "JFROG_ACCESS_TOKEN=${ACCESS_TOKEN}" >> "$GITHUB_ENV"
echo "JFrog OIDC token obtained successfully"
- name: Configure maven
run: |
set -euo pipefail
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << EOF
<settings>
<mirrors>
<mirror>
<id>jfrog-central</id>
<mirrorOf>*</mirrorOf>
<url>https://databricks.jfrog.io/artifactory/db-maven/</url>
</mirror>
</mirrors>
<servers>
<server>
<id>jfrog-central</id>
<username>gha-service-account</username>
<password>${JFROG_ACCESS_TOKEN}</password>
</server>
</servers>
</settings>
EOF
echo "Maven configured to use JFrog registry"
################################################################
# 4) Install Squid Proxy
################################################################
- name: Install Squid
run: |
sudo apt-get update
sudo apt-get install -y squid
################################################################
# 4) Configure the Squid for SDK proxy (Port 3128)
################################################################
- name: Configure Squid (Primary 3128)
run: |
echo "
http_port 3128
# Restrict to localhost for security
acl localnet src 127.0.0.1/32 ::1
http_access allow localnet
http_access deny all
access_log stdio:/var/log/squid/access.log squid
" | sudo tee /etc/squid/squid.conf
################################################################
# 5) Start the Squid for SDK proxy
################################################################
- name: Start the Squid for SDK proxy
run: |
sudo systemctl restart squid
sudo systemctl enable squid
################################################################
# 6) Wait for the Squid for SDK proxy to be Ready
################################################################
- name: Wait for Squid (3128)
run: |
for i in {1..5}; do
echo "Checking if Squid on 3128 is up (attempt $i)..."
if curl -x http://localhost:3128 http://example.com -sSf -o /dev/null; then
echo "Squid on 3128 is up."
break
fi
if [ $i -eq 5 ]; then
echo "Squid on 3128 did not respond after 5 attempts. Failing..."
exit 1
fi
sleep 5
done
################################################################
# 7) Configure Squid for CloudFetch Proxy (Port 8889)
# with Unique PID, Cache, and Logging
################################################################
- name: Configure Squid for CloudFetch Proxy (8889)
run: |
sudo cp /etc/squid/squid.conf /etc/squid/squid2.conf
# Update the port to 8889 in the new config
sudo sed -i 's/http_port 3128/http_port 8889/' /etc/squid/squid2.conf
# Set unique PID file and cache directory for the second instance
echo "pid_filename /var/run/squid2.pid" | sudo tee -a /etc/squid/squid2.conf
echo "cache_dir ufs /var/spool/squid2 100 16 256" | sudo tee -a /etc/squid/squid2.conf
# Configure logging for the second instance
echo "access_log stdio:/var/log/squid2/access.log squid" | sudo tee -a /etc/squid/squid2.conf
echo "cache_log /var/log/squid2/cache.log" | sudo tee -a /etc/squid/squid2.conf
# (Removed the problematic sed line that caused /var/log/squid22)
# Create necessary directories and set permissions
sudo mkdir -p /var/log/squid2 /var/spool/squid2
sudo chown -R proxy:proxy /var/log/squid2 /var/spool/squid2
################################################################
# 8) Initialize Cache Directory for CloudFetch Proxy
################################################################
- name: Initialize Cache for CloudFetch Proxy
run: |
sudo squid -f /etc/squid/squid2.conf -z
################################################################
# 9) Start the Squid for CloudFetch Proxy
################################################################
- name: Start the Squid for CloudFetch Proxy
run: |
sudo squid -f /etc/squid/squid2.conf -N &> /tmp/squid2.log &
sleep 3
################################################################
# 10) Wait for the Squid for CloudFetch Proxy (8889)
################################################################
- name: Verify Squid (8889)
run: |
for i in {1..5}; do
echo "Checking if Squid on 8889 is up (attempt $i)..."
if curl -x http://localhost:8889 http://example.com -sSf -o /dev/null; then
echo "Squid for CloudFetch proxy on 8889 is up."
break
fi
if [ $i -eq 5 ]; then
echo "Squid on 8889 did not respond after 5 attempts. Failing..."
cat /tmp/squid2.log
exit 1
fi
sleep 5
done
################################################################
# 11) Maven Build
################################################################
- name: Maven Build
run: mvn clean package -DskipTests
################################################################
# 12) Set Environment Variables for Tests
################################################################
- name: Set Environment Variables
env:
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
DATABRICKS_HTTP_PATH: ${{ secrets.DATABRICKS_HTTP_PATH }}
PROXY_URL: "http://localhost:3128"
CF_PROXY_URL: "http://localhost:8889"
run: |
echo "DATABRICKS_TOKEN=${DATABRICKS_TOKEN}" >> $GITHUB_ENV
echo "DATABRICKS_HOST=${DATABRICKS_HOST}" >> $GITHUB_ENV
echo "DATABRICKS_HTTP_PATH=${DATABRICKS_HTTP_PATH}" >> $GITHUB_ENV
echo "PROXY_URL=${PROXY_URL}" >> $GITHUB_ENV
echo "CF_PROXY_URL=${CF_PROXY_URL}" >> $GITHUB_ENV
################################################################
# 13) Run Proxy Tests
################################################################
- name: Run ProxyTest
run: |
mvn -pl jdbc-core test -Dtest=**/ProxyTest.java
################################################################
# 14) Cleanup
################################################################
- name: Cleanup Squid
if: always()
run: |
echo "Stopping and disabling primary Squid..."
sudo systemctl stop squid
sudo systemctl disable squid
echo "Killing Squid for CloudFetch proxy if still running..."
sudo pkill squid