Skip to content

Commit 285386e

Browse files
committed
fix cobra to sentry + change ws docker file to use alpine (much smaller footprint)
1 parent c65fec7 commit 285386e

7 files changed

+60
-9
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
CMakeCache.txt
33
ws/CMakeCache.txt
4+
test/build

DOCKER_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
2.2.1

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
docker/Dockerfile.ubuntu_xenial
1+
docker/Dockerfile.alpine

docker/Dockerfile.alpine

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM alpine as build
2+
3+
RUN apk add --no-cache gcc g++ musl-dev linux-headers cmake openssl-dev
4+
RUN apk add --no-cache make
5+
RUN apk add --no-cache zlib-dev
6+
7+
RUN addgroup -S app && adduser -S -G app app
8+
RUN chown -R app:app /opt
9+
RUN chown -R app:app /usr/local
10+
11+
# There is a bug in CMake where we cannot build from the root top folder
12+
# So we build from /opt
13+
COPY --chown=app:app . /opt
14+
WORKDIR /opt
15+
16+
USER app
17+
RUN [ "make" ]
18+
19+
FROM alpine as runtime
20+
21+
RUN apk add --no-cache libstdc++
22+
23+
RUN addgroup -S app && adduser -S -G app app
24+
COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws
25+
RUN chmod +x /usr/local/bin/ws
26+
RUN ldd /usr/local/bin/ws
27+
28+
# Now run in usermode
29+
USER app
30+
WORKDIR /home/app
31+
32+
ENTRYPOINT ["ws"]
33+
CMD ["--help"]

makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ IMG := ${NAME}:${TAG}
2525
LATEST := ${NAME}:latest
2626
BUILD := ${NAME}:build
2727

28+
docker_test:
29+
docker build -f docker/Dockerfile.debian -t bsergean/ixwebsocket_test:build .
30+
2831
docker:
2932
docker build -t ${IMG} .
3033
docker tag ${IMG} ${BUILD}
@@ -34,7 +37,7 @@ docker_push:
3437
docker push ${LATEST}
3538

3639
run:
37-
docker run --cap-add sys_ptrace --entrypoint=bash -it bsergean/ws:build
40+
docker run --cap-add sys_ptrace --entrypoint=sh -it bsergean/ws:build
3841

3942
# this is helpful to remove trailing whitespaces
4043
trail:

test/IXWebSocketPingTest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ TEST_CASE("Websocket_ping_no_data_sent_setHeartBeatPeriod", "[setHeartBeatPeriod
427427
REQUIRE(server.getClients().size() == 0);
428428

429429
ix::reportWebSocketTraffic();
430+
server.stop();
430431
}
431432
}
432433

@@ -477,5 +478,6 @@ TEST_CASE("Websocket_ping_data_sent_setHeartBeatPeriod", "[setHeartBeatPeriod]")
477478
REQUIRE(server.getClients().size() == 0);
478479

479480
ix::reportWebSocketTraffic();
481+
server.stop();
480482
}
481483
}

ws/IXSentryClient.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ namespace ix
9999
return frames;
100100
}
101101

102+
std::string parseExceptionName(const std::string& stack)
103+
{
104+
// Split by lines
105+
std::string line;
106+
std::stringstream tokenStream(stack);
107+
108+
// Extract the first line
109+
std::getline(tokenStream, line);
110+
111+
return line;
112+
}
113+
102114
std::string SentryClient::computePayload(const Json::Value& msg)
103115
{
104116
Json::Value payload;
@@ -107,14 +119,14 @@ namespace ix
107119
payload["sdk"]["version"] = "1.0.0";
108120
payload["timestamp"] = SentryClient::getIso8601();
109121

110-
Json::Value exception;
111-
exception["value"] = msg["data"]["message"];
122+
bool isNoisyTypes = msg["id"].asString() == "game_noisytypes_id";
112123

113-
std::string stackTraceFieldName =
114-
(msg["id"].asString() == "game_noisytypes_id") ? "traceback" : "stack";
124+
std::string stackTraceFieldName = isNoisyTypes ? "traceback" : "stack";
125+
std::string stack(msg["data"][stackTraceFieldName].asString());
115126

116-
exception["stacktrace"]["frames"] =
117-
parseLuaStackTrace(msg["data"][stackTraceFieldName].asString());
127+
Json::Value exception;
128+
exception["stacktrace"]["frames"] = parseLuaStackTrace(stack);
129+
exception["value"] = isNoisyTypes ? parseExceptionName(stack) : msg["data"]["message"];
118130

119131
payload["exception"].append(exception);
120132

0 commit comments

Comments
 (0)