-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile
More file actions
223 lines (197 loc) · 8.59 KB
/
Copy pathDockerfile
File metadata and controls
223 lines (197 loc) · 8.59 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
# Multi-stage Dockerfile for AKS Traffic Ingress Competitive Testing
# Base stage with common dependencies
FROM ubuntu:22.04 AS base
# Avoid interactive prompts during apt-get
ENV DEBIAN_FRONTEND=noninteractive
# Install common dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
jq \
gawk \
unzip \
bash \
ca-certificates \
gnupg \
apt-transport-https \
lsb-release \
iproute2 \
sudo \
&& rm -rf /var/lib/apt/lists/*
# Create a fake sudoo command that redirects to sudo (to handle typos in scripts)
RUN echo '#!/bin/bash\nsudo "$@"' > /usr/local/bin/sudoo && \
chmod +x /usr/local/bin/sudoo
# Install Go (required for KIND, jplot, and other Go tools)
ENV GOLANG_VERSION=1.23.0
ENV PATH=$PATH:/usr/local/go/bin:/root/go/bin
RUN curl -L https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz | tar -C /usr/local -xzf - && \
mkdir -p /root/go/bin
# Install Docker CLI for KIND
RUN install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
chmod a+r /etc/apt/keyrings/docker.gpg && \
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install -y docker-ce-cli && \
rm -rf /var/lib/apt/lists/*
# Install kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
chmod +x kubectl && \
mv kubectl /usr/local/bin/
# Install Helm
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \
chmod 700 get_helm.sh && \
./get_helm.sh && \
rm get_helm.sh
# Tools installation stage
FROM base AS tools
WORKDIR /app
# Copy the repository
COPY . .
# Make all scripts executable
RUN find modules -name "*.sh" -exec chmod +x {} + && \
find scripts -name "*.sh" -exec chmod +x {} +
# Create sudoers file for the root user to avoid sudo errors
RUN echo "root ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/root && \
chmod 0440 /etc/sudoers.d/root
# Install Vegeta
RUN bash modules/vegeta/install/install.sh
# Server build stage
FROM tools AS server-builder
WORKDIR /app/server
# Build the server
RUN CGO_ENABLED=0 GOOS=linux go build -o server
# Final stage
FROM tools AS final
WORKDIR /app
# Copy server binary from builder
COPY --from=server-builder /app/server/server /app/server/
# Create entrypoint script to handle different commands
RUN printf '%s\n' \
'#!/bin/bash' \
'if [ $# -eq 0 ]; then' \
' echo "AKS Traffic Ingress Competitive Testing Environment"' \
' echo ""' \
' echo "Usage: docker run <image> <command> [args...]"' \
' echo ""' \
' echo "Commands:"' \
' echo " master [args...] Run the full test pipeline (scripts/master.sh)"' \
' echo " scenario/<name> [args...] Run a scenario (e.g. scenario/basic_rps)"' \
' echo " install/<name> [args...] Run an install script (e.g. install/nginx)"' \
' echo " setup/<name> [args...] Run a setup script (e.g. setup/ingress)"' \
' echo " cleanup/<name> [args...] Run a cleanup script (e.g. cleanup/dns-ingresses)"' \
' echo " module/<name>/<action> [args...] Run a module script (e.g. module/vegeta/run)"' \
' echo " merge [args...] Merge vegeta .bin files (modules/vegeta/merge/merge.sh)"' \
' echo " server Start the HTTP server"' \
' echo " bash -c \"...\" Run a custom command"' \
' echo ""' \
' echo "Examples:"' \
' echo " docker run <image> master --traffic ingress --scenario basic-rps"' \
' echo " docker run <image> scenario/basic_rps --ingress-url http://localhost:8080 --rate 50"' \
' echo " docker run <image> install/nginx"' \
' echo " docker run <image> setup/ingress --ingress-class nginx --replica-count 3"' \
' echo " docker run <image> module/vegeta/install"' \
' echo " docker run <image> module/vegeta/run --target-url http://localhost:8080 --rate 50 --duration 30s"' \
' echo " docker run <image> module/kind/output host_port"' \
' echo " docker run -p 3333:3333 <image> server"' \
'elif [ "$1" = "server" ]; then' \
' cd /app/server && ./server' \
'elif [ "$1" = "master" ]; then' \
' shift' \
' exec bash /app/scripts/master.sh "$@"' \
'elif [[ "$1" == scenario/* ]]; then' \
' name="${1#scenario/}"' \
' shift' \
' if [ -f "/app/scripts/scenarios/${name}.sh" ]; then' \
' exec bash "/app/scripts/scenarios/${name}.sh" "$@"' \
' else' \
' echo "ERROR: Unknown scenario: ${name}"' \
' echo "Available scenarios:"' \
' ls /app/scripts/scenarios/*.sh 2>/dev/null | sed "s|/app/scripts/scenarios/||;s|\.sh||" | sed "s|^| |"' \
' exit 1' \
' fi' \
'elif [[ "$1" == install/* ]]; then' \
' name="${1#install/}"' \
' shift' \
' if [ -f "/app/scripts/install/${name}.sh" ]; then' \
' exec bash "/app/scripts/install/${name}.sh" "$@"' \
' else' \
' echo "ERROR: Unknown install script: ${name}"' \
' echo "Available install scripts:"' \
' ls /app/scripts/install/*.sh 2>/dev/null | sed "s|/app/scripts/install/||;s|\.sh||" | sed "s|^| |"' \
' exit 1' \
' fi' \
'elif [[ "$1" == setup/* ]]; then' \
' name="${1#setup/}"' \
' shift' \
' if [ -f "/app/scripts/setup/${name}.sh" ]; then' \
' exec bash "/app/scripts/setup/${name}.sh" "$@"' \
' else' \
' echo "ERROR: Unknown setup script: ${name}"' \
' echo "Available setup scripts:"' \
' ls /app/scripts/setup/*.sh 2>/dev/null | sed "s|/app/scripts/setup/||;s|\.sh||" | sed "s|^| |"' \
' exit 1' \
' fi' \
'elif [[ "$1" == cleanup/* ]]; then' \
' name="${1#cleanup/}"' \
' shift' \
' if [ -f "/app/scripts/cleanup/${name}.sh" ]; then' \
' exec bash "/app/scripts/cleanup/${name}.sh" "$@"' \
' else' \
' echo "ERROR: Unknown cleanup script: ${name}"' \
' echo "Available cleanup scripts:"' \
' ls /app/scripts/cleanup/*.sh 2>/dev/null | sed "s|/app/scripts/cleanup/||;s|\.sh||" | sed "s|^| |"' \
' exit 1' \
' fi' \
'elif [[ "$1" == module/* ]]; then' \
' path="${1#module/}"' \
' module_name="${path%%/*}"' \
' action="${path#*/}"' \
' shift' \
' script="/app/modules/${module_name}/${action}/${action}.sh"' \
' if [ -f "$script" ]; then' \
' exec bash "$script" "$@"' \
' else' \
' echo "ERROR: Unknown module script: module/${module_name}/${action}"' \
' echo "Available modules and actions:"' \
' for m in /app/modules/*/; do' \
' mname=$(basename "$m")' \
' actions=$(ls "$m"/*//*.sh 2>/dev/null | xargs -I{} basename $(dirname {}) | sort -u | tr "\\n" " ")' \
' [ -n "$actions" ] && echo " module/${mname}/{${actions}}"' \
' done' \
' exit 1' \
' fi' \
'elif [ "$1" = "merge" ]; then' \
' shift' \
' exec bash /app/modules/vegeta/merge/merge.sh "$@"' \
'else' \
' exec "$@"' \
'fi' \
> /app/entrypoint.sh && chmod +x /app/entrypoint.sh
SHELL [ "/bin/bash", "-c" ]
# Set entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]
# Default command - if no arguments provided, this will show usage information
CMD []
# Usage examples in comments:
# Run full pipeline:
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing master --traffic ingress --scenario basic-rps
#
# Run a scenario:
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing scenario/basic_rps --ingress-url http://localhost:8080 --rate 50
#
# Run an install script:
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing install/nginx
#
# Run a setup script:
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing setup/ingress --ingress-class nginx
#
# Run a module script:
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing module/vegeta/install
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing module/vegeta/run --target-url http://localhost:8080 --rate 50 --duration 30s
# docker run ghcr.io/azure/aks-traffic-ingress-competitive-testing module/kind/output host_port
#
# Run the server:
# docker run -p 3333:3333 ghcr.io/azure/aks-traffic-ingress-competitive-testing server