Skip to content

Commit aab868b

Browse files
authored
Update run-nsc.yml, add reverse proxy, require authentication to connect to tested NSC Godbolt instance, add options to set timeout and default to 1h
to not violate Github ToS we do not allow for public connections and restrict to members of DevshGraphicsProgramming only
1 parent 104422f commit aab868b

File tree

1 file changed

+81
-24
lines changed

1 file changed

+81
-24
lines changed

.github/workflows/run-nsc.yml

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ on:
1515
- Release
1616
- RelWithDebInfo
1717
- Debug
18+
tunnelDurationHours:
19+
description: "Hours amount the restricted tunnel should stay up"
20+
required: true
21+
default: "1"
22+
type: choice
23+
options:
24+
- "1"
25+
- "2"
26+
- "3"
27+
- "4"
28+
- "5"
1829
withDiscordMSG:
1930
description: "Send Discord message after tunnel is up"
2031
required: true
@@ -44,7 +55,47 @@ jobs:
4455
docker network create --driver nat docker_default
4556
if ($LASTEXITCODE -ne 0) { exit 1 }
4657
}
47-
58+
59+
$sendDiscord = "${{ inputs.withDiscordMSG }}" -eq "true"
60+
Write-Host "::notice::Should send discord message? $sendDiscord"
61+
62+
- name: Download Restricted Reverse Proxy binaries, setup NGINX config
63+
run: |
64+
Invoke-WebRequest -Uri https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe -OutFile cloudflared.exe
65+
Invoke-WebRequest -Uri "https://nginx.org/download/nginx-1.24.0.zip" -OutFile nginx.zip
66+
Expand-Archive nginx.zip -DestinationPath nginx
67+
68+
Remove-Item -Recurse -Force "nginx/nginx-1.24.0/conf"
69+
New-Item -ItemType Directory -Path "nginx/nginx-1.24.0/conf" -Force | Out-Null
70+
71+
'${{ secrets.NSC_BASIC_AUTH_HTPASSWD }}' | Out-File nginx/nginx-1.24.0/conf/.htpasswd -Encoding ascii
72+
$htpasswdPath = (Resolve-Path "nginx/nginx-1.24.0/conf/.htpasswd").Path -replace '\\', '/'
73+
74+
@"
75+
events {}
76+
77+
http {
78+
server {
79+
listen 10241;
80+
81+
location / {
82+
auth_basic "Restricted Compiler Explorer access for Development & NSC Artifact Tests, downloaded from Nabla actions pipeline";
83+
auth_basic_user_file "$htpasswdPath";
84+
85+
proxy_pass http://127.0.0.1:10240;
86+
proxy_set_header Host `$host;
87+
proxy_set_header X-Real-IP `$remote_addr;
88+
}
89+
}
90+
}
91+
"@ | Out-File nginx/nginx-1.24.0/conf/nginx.conf -Encoding ascii
92+
93+
Write-Host "::group::Generated nginx.conf"
94+
Get-Content nginx/nginx-1.24.0/conf/nginx.conf
95+
Write-Host "::endgroup::"
96+
97+
& "nginx/nginx-1.24.0/nginx.exe" -t -p "nginx/nginx-1.24.0" -c "conf/nginx.conf"
98+
4899
- name: Download NSC Godbolt artifact
49100
uses: actions/download-artifact@v4
50101
with:
@@ -107,7 +158,7 @@ jobs:
107158
108159
docker compose -f compose.generated.yml up -d
109160
110-
- name: Wait for local server on port 10240
161+
- name: Wait for NSC container response on port
111162
run: |
112163
$maxRetries = 24
113164
$retryDelay = 5
@@ -117,34 +168,35 @@ jobs:
117168
try {
118169
$response = Invoke-WebRequest -Uri "http://localhost:10240" -UseBasicParsing -TimeoutSec 5
119170
if ($response.StatusCode -eq 200) {
120-
Write-Host "Local server is up and responding."
171+
Write-Host "NSC container is up listening on port 10240 and responding."
121172
$success = $true
122173
break
123174
} else {
124175
Write-Host "Received HTTP $($response.StatusCode), retrying..."
125176
}
126177
} catch {
127-
Write-Host "Local server not responding yet, retrying..."
178+
Write-Host "NSC container is not responding on port 10240, retrying..."
128179
}
129180
Start-Sleep -Seconds $retryDelay
130181
}
131182

132183
if (-not $success) {
133-
Write-Error "Local server on port 10240 did not respond within timeout."
184+
Write-Error "No response from NSC container on port 10240, timeout."
134185
exit 1
135186
}
136187

137-
- name: Print Container Logs
188+
- name: Print NSC container logs
138189
run: |
139190
docker logs nsc-godbolt
140191
141-
- name: Download cloudflared
192+
- name: Start Restricted Tunnel
193+
env:
194+
DISCORD_ENABLED: ${{ inputs.withDiscordMSG }}
195+
TUNNEL_DURATION_HOURS: ${{ inputs.tunnelDurationHours }}
142196
run: |
143-
Invoke-WebRequest -Uri https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe -OutFile cloudflared.exe
144-
145-
- name: Start tunnel
146-
run: |
147-
Start-Process -NoNewWindow -FilePath .\cloudflared.exe -ArgumentList "tunnel", "--url", "http://localhost:10240", "--logfile", "cf.log"
197+
Start-Process -NoNewWindow -FilePath .\nginx\nginx-1.24.0\nginx.exe -ArgumentList '-p', (Join-Path $PWD 'nginx/nginx-1.24.0'), '-c', 'conf/nginx.conf'
198+
Start-Process -NoNewWindow -FilePath .\cloudflared.exe -ArgumentList "tunnel", "--url", "http://localhost:10241", "--logfile", "cf.log"
199+
netstat -an | findstr 10241
148200
149201
$tries = 60
150202
$url = $null
@@ -164,23 +216,27 @@ jobs:
164216
Start-Sleep -Seconds 1
165217
$tries -= 1
166218
}
167-
219+
168220
if (-not $url) {
169221
Write-Error "Could not get tunnel URL from cloudflared log"
170222
exit 1
171223
}
172224
173225
$webhookUrl = "$env:DISCORD_WEBHOOK"
174-
$runId = "${{ inputs.run_id }}"
226+
$runId = "$env:GITHUB_RUN_ID"
175227
$actor = "$env:GITHUB_ACTOR"
176-
$startTime = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
177228
$composedURL = "https://github.com/Devsh-Graphics-Programming/Nabla/actions/runs/$runId"
178-
$workflowRunURL = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
179-
$sendDiscord = "${{ inputs.withDiscordMSG }}" -eq "true"
229+
$workflowRunURL = "https://github.com/$env:GITHUB_REPOSITORY/actions/runs/$runId"
230+
$sendDiscord = "$env:DISCORD_ENABLED" -eq "true"
231+
$hours = [int]$env:TUNNEL_DURATION_HOURS
232+
$duration = $hours * 3600
233+
234+
Write-Host "Blocking job for $hours hours"
180235
181236
$description = @"
182-
- tunnel opened for 5 hours, click [here](<$url>) to connect
183-
- workflow [logs #${{ github.run_id }}](<$workflowRunURL>)
237+
- tunnel opened for $hours hours, click [here](<$url>) to connect
238+
- requires authentication
239+
- workflow [logs #$runId](<$workflowRunURL>)
184240
- image downloaded from [run #$runId](<$composedURL>)
185241
- dispatched by $actor
186242
"@
@@ -191,16 +247,17 @@ jobs:
191247
title = "Running NSC Godbolt Container"
192248
description = $description
193249
color = 15844367
194-
footer = @{
195-
text = "sent from GitHub Actions runner"
196-
}
250+
footer = @{ text = "sent from GitHub Actions runner" }
197251
timestamp = (Get-Date).ToString("o")
198252
}
199253
)
200254
} | ConvertTo-Json -Depth 10
201-
255+
202256
if ($sendDiscord) {
257+
Write-Host "Sending Discord webhook..."
203258
Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType 'application/json' -Body $payload
259+
} else {
260+
Write-Host "Discord webhook disabled"
204261
}
205262
206-
Start-Sleep -Seconds 18000
263+
Start-Sleep -Seconds $duration

0 commit comments

Comments
 (0)