Skip to content

Commit e0a429e

Browse files
authored
25: docker compose (#27)
* 25: Adds docker-compose build * 25: Trims URI cmdline arg strings
1 parent 196a176 commit e0a429e

File tree

6 files changed

+84
-11
lines changed

6 files changed

+84
-11
lines changed

Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ RUN sudo dnf update --assumeyes --verbose && dnf install --assumeyes --verbose \
2121
&& dnf clean all \
2222
&& rm -rf /var/cache/yum
2323

24+
COPY CMakeLists.txt /tmp/srt-game-server/
25+
COPY config.yaml /tmp/srt-game-server/
26+
COPY src/ /tmp/srt-game-server/src/
27+
2428
WORKDIR /tmp/srt-game-server/src/Proto
2529
RUN for i in `ls -lC1 *.proto`; do `echo protoc $i --cpp_out=.`; done; mkdir /tmp/build
2630
WORKDIR /tmp/build
@@ -54,9 +58,9 @@ ENV USER_UID=1000
5458
ENV USER_NAME=srt
5559
ENV EXECUTABLE_NAME=srt-game-server.bin
5660
ENV EXECUTABLE=/home/${USER_NAME}/bin/${EXECUTABLE_NAME}
57-
ENV BROKER_URI="tcp://127.0.0.1:5672"
58-
ENV LOG_LEVEL="1"
59-
ENV SLEEP_CYCLE="1500"
61+
ENV BROKER_URI=tcp://artemiscloud:5672
62+
ENV LOG_LEVEL=1
63+
ENV SLEEP_CYCLE=1500
6064

6165
WORKDIR /
6266

@@ -68,7 +72,8 @@ COPY containerbuild/bin/entrypoint /home/${USER_NAME}/bin
6872

6973
RUN chown -R `id -u`:0 /home/${USER_NAME}/bin && chmod -R 755 /home/${USER_NAME}/bin
7074
USER ${USER_UID}:0
71-
ENTRYPOINT "/home/srt/bin/entrypoint" "--broker-uri" "$BROKER_URI" "-v" "$LOG_LEVEL" "--sleep-cycle" "$SLEEP_CYCLE"
75+
ENTRYPOINT /home/srt/bin/entrypoint --broker-uri ${BROKER_URI} --sleep-cycle ${SLEEP_CYCLE}
76+
CMD [-v, ${LOG_LEVEL}]
7277

7378
LABEL \
7479
com.srt.component="srt-game-server" \

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
broker-uri: "tcp://10.88.0.5:5672"
2+
broker-uri: "tcp://artemiscloud:5672"
33
sleep-cycle: 1500
44
command-in: "COMMAND.IN"
55
game-event-out: "GAME.EVENT.OUT"

containerbuild/bin/entrypoint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ if ! whoami &>/dev/null; then
1111
fi
1212
fi
1313

14-
echo "exec ${EXECUTABLE}"
15-
exec ${EXECUTABLE} $@
14+
echo "exec ${EXECUTABLE} ${@}"
15+
exec "${EXECUTABLE}" "${@}"

docker-compose.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.3'
2+
services:
3+
artemiscloud:
4+
container_name: artemis
5+
ports:
6+
- '5672:5672'
7+
environment:
8+
- AMQ_USER=admin
9+
- AMQ_PASSWORD=admin
10+
- AMQ_ALLOW_ANONYMOUS=true
11+
image: 'quay.io/artemiscloud/activemq-artemis-broker:latest'
12+
restart: unless-stopped
13+
srt-game-server:
14+
container_name: srt-game-server
15+
build:
16+
context: .
17+
args:
18+
fedora_version: 33
19+
environment:
20+
- BROKER_URI=tcp://artemiscloud:5672
21+
image: 'srt-game-server:latest'
22+
links:
23+
- artemiscloud
24+
restart: unless-stopped

src/Application/Configuration.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "Configuration.h"
16-
#include "../Logging/loguru.hpp"
15+
#include <cstring>
1716
#include <yaml-cpp/node/node.h>
1817
#include <yaml-cpp/node/parse.h>
19-
#include <cstring>
18+
19+
#include "Configuration.h"
20+
#include "../Logging/loguru.hpp"
21+
#include "../Shared/Strings.h"
2022

2123
// Define the static Singleton pointer
2224
Configuration *Configuration::m_pConInstance = nullptr;
@@ -60,7 +62,9 @@ void Configuration::Init(int &argc, char *argv[]) {
6062
// Override yaml config and default values with any matching command line args
6163
for (int i = 1; i < argc; ++i) {
6264
if (0 == strcmp(argv[i], "--broker-uri")) {
63-
m_pConInstance->BrokerUri = argv[++i];
65+
std::string m_strBrokerUri(argv[++i]);
66+
trim(m_strBrokerUri);
67+
m_pConInstance->BrokerUri = m_strBrokerUri;
6468
} else if (0 == strcmp(argv[i], "--sleep-cycle")) {
6569
m_pConInstance->SleepCycle = strtol(argv[++i], nullptr, 0);
6670
} else if (0 == strcmp(argv[i], "--command-in")) {

src/Shared/Strings.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
// Provides useful String functions.
4+
//
5+
// Copyright 2021 Derek Reese
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
19+
#include <algorithm>
20+
#include <cctype>
21+
#include <cstring>
22+
// @TODO: Convert this to string_view for CPP17.
23+
#include <string>
24+
25+
static inline void ltrim(std::string &str) {
26+
str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char chr) {
27+
return !std::isspace(chr) || reinterpret_cast<const char*>(chr) == "\"";
28+
}));
29+
}
30+
31+
static inline void rtrim(std::string &str) {
32+
str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char chr) {
33+
return !std::isspace(chr) || reinterpret_cast<const char*>(chr) == "\"";
34+
}).base(), str.end());
35+
}
36+
37+
static inline void trim(std::string &str) {
38+
ltrim(str);
39+
rtrim(str);
40+
}

0 commit comments

Comments
 (0)