Skip to content

Commit fb7eebd

Browse files
committed
optimize build image - run webpack to have nice cache, get rid of choco. Create ce_healthy_check.py for healthy checks
1 parent 31269f4 commit fb7eebd

File tree

2 files changed

+113
-20
lines changed

2 files changed

+113
-20
lines changed

Dockerfile

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,42 @@ FROM ${BASE_IMAGE}
66

77
SHELL ["cmd", "/S", "/C"]
88

9-
ENV GIT_VERSION=2.43.0
10-
ENV GIT_GODBOLT_REPOSITORY_PATH=C:\compiler-explorer
11-
ENV CE_URL=https://github.com/Devsh-Graphics-Programming/compiler-explorer.git
12-
ENV CE_SHA=ce980aded514ae6a0a1b1f63e7fb358e57c9ed57
13-
ENV NODEJS_MSI=https://nodejs.org/dist/v18.19.0/node-v18.19.0-x64.msi
9+
ENV GIT_VERSION=2.47.1
1410

15-
RUN `
16-
# Install Chocolatey
17-
`
18-
powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
11+
RUN `
12+
# Download Git
13+
`
14+
curl -SL --output git.zip https://github.com/git-for-windows/git/releases/download/v%GIT_VERSION%.windows.1/MinGit-%GIT_VERSION%-64-bit.zip `
15+
`
16+
&& mkdir "C:\\git" `
17+
`
18+
&& tar -xf git.zip -C "C:\\git" `
19+
`
20+
&& setx PATH "%PATH%;C:\\git\\cmd" /M `
21+
`
22+
&& del /q git.zip
23+
24+
RUN `
25+
# Post git configuration
26+
`
27+
git config --system --add safe.directory *
28+
29+
ENV PYTHON_VERSION=3.11.0
1930

2031
RUN `
21-
# Install Git
32+
# Download Python
33+
`
34+
curl -SL --output python.zip https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-embed-amd64.zip `
2235
`
23-
choco install -y git --version %GIT_VERSION%
36+
&& mkdir "C:\\python" `
37+
`
38+
&& tar -xf python.zip -C "C:\\python" `
39+
`
40+
&& setx PATH "%PATH%;C:\\python" /M `
41+
`
42+
&& del /q python.zip
43+
44+
ENV NODEJS_MSI=https://nodejs.org/dist/v18.19.0/node-v18.19.0-x64.msi
2445

2546
RUN `
2647
# Install Node LTS
@@ -31,6 +52,10 @@ RUN `
3152
`
3253
&& del /q nodejs.msi
3354

55+
ENV GIT_GODBOLT_REPOSITORY_PATH=C:\compiler-explorer
56+
ENV CE_URL=https://github.com/Devsh-Graphics-Programming/compiler-explorer.git
57+
ENV CE_SHA=ce980aded514ae6a0a1b1f63e7fb358e57c9ed57
58+
3459
RUN `
3560
# Checkout Compiler-Explorer
3661
`
@@ -46,18 +71,20 @@ RUN `
4671
`
4772
&& setx GIT_GODBOLT_REPOSITORY_PATH %GIT_GODBOLT_REPOSITORY_PATH% /M
4873

74+
ENV NODE_OPTIONS="--max-old-space-size=4096"
75+
4976
RUN `
50-
# Install node depenendencies
77+
# Install Node.js dependencies & precompile production
5178
`
5279
cd %GIT_GODBOLT_REPOSITORY_PATH% `
5380
`
54-
&& npm install
55-
56-
RUN `
57-
# Post git configuration, trust containers
58-
`
59-
git config --system --add safe.directory * `
81+
&& npm ci `
6082
`
61-
# Enable Long Paths feature
83+
&& npm run webpack
84+
85+
RUN `
86+
# Post registry configuration
6287
`
63-
&& reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v "LongPathsEnabled" /t REG_DWORD /d 1 /f
88+
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v "LongPathsEnabled" /t REG_DWORD /d 1 /f
89+
90+
COPY ce_healthy_check.py /ce_healthy_check.py

ce_healthy_check.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
import argparse
3+
import time
4+
import urllib.request
5+
import sys
6+
7+
8+
def check_health(url):
9+
"""
10+
Check the health of the server by making a HEAD request to the provided URL.
11+
:param url: URL to check health (e.g., http://localhost:10240)
12+
:return: True if the server responds with status code 200, False otherwise.
13+
"""
14+
try:
15+
request = urllib.request.Request(url, method="HEAD")
16+
with urllib.request.urlopen(request, timeout=5) as response:
17+
return response.status == 200
18+
except Exception as e:
19+
print(f"[ERROR] Exception thrown during health check: {e}", file=sys.stderr, flush=True)
20+
return False
21+
22+
23+
def run_health_checks(url, interval, ticks):
24+
"""
25+
Run health checks on a server for a specified number of attempts.
26+
:param url: URL to check health (e.g., http://localhost:10240)
27+
:param interval: Time interval between checks (in seconds)
28+
:param ticks: Number of health check attempts
29+
:return: 0 if successful, 1 if all attempts fail.
30+
"""
31+
for attempt in range(1, ticks + 1):
32+
print(f"[INFO] Attempt {attempt} of {ticks}: Checking health...", flush=True)
33+
if check_health(url):
34+
print(f"[SUCCESS] Health check succeeded on attempt {attempt}.", flush=True)
35+
return 0
36+
else:
37+
print(f"[ERROR] Health check failed on attempt {attempt}. Retrying in {interval} seconds...", flush=True)
38+
time.sleep(interval)
39+
40+
print(f"[ERROR] Server did not become healthy after {ticks} attempts.", file=sys.stderr, flush=True)
41+
return 1
42+
43+
44+
if __name__ == "__main__":
45+
parser = argparse.ArgumentParser(description="Run health checks for a server.")
46+
parser.add_argument(
47+
"--url",
48+
type=str,
49+
default="http://localhost:10240",
50+
help="The URL to check health (default: http://localhost:10240).",
51+
)
52+
parser.add_argument(
53+
"--interval",
54+
type=int,
55+
default=5,
56+
help="Interval between health checks (in seconds). Default is 5.",
57+
)
58+
parser.add_argument(
59+
"--ticks",
60+
type=int,
61+
default=15,
62+
help="Number of health check attempts. Default is 15.",
63+
)
64+
65+
args = parser.parse_args()
66+
sys.exit(run_health_checks(args.url, args.interval, args.ticks))

0 commit comments

Comments
 (0)