100% kubernetes scalable now
Some checks failed
Build and push docker image / build (push) Failing after 1m40s
Some checks failed
Build and push docker image / build (push) Failing after 1m40s
This commit is contained in:
12
Dockerfile
12
Dockerfile
@@ -1,28 +1,28 @@
|
||||
FROM registry.brunner.ninja/library/ubuntu:devel AS build
|
||||
|
||||
RUN apt update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt install libqt6core6 libqt6httpserver6 libqt6websockets6 -y \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt install libqt6core6 libqt6httpserver6 libqt6websockets6 libhiredis1.1.0 -y \
|
||||
&& rm /var/lib/apt/lists/* /var/log/* -Rf
|
||||
|
||||
RUN apt update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt install qmake6 g++ make qt6-base-dev qt6-websockets-dev qt6-httpserver-dev -y \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt install qmake6 g++ make qt6-base-dev qt6-websockets-dev qt6-httpserver-dev libhiredis-dev -y \
|
||||
&& rm /var/lib/apt/lists/* /var/log/* -Rf
|
||||
|
||||
COPY ./ /less_shitty_proxyjs
|
||||
|
||||
RUN mkdir -pv /build \
|
||||
&& cd /build \
|
||||
&& qmake6 /less_shitty_proxyjs \
|
||||
&& qmake6 "CONFIG+=redis" /less_shitty_proxyjs \
|
||||
&& make -j4
|
||||
|
||||
FROM registry.brunner.ninja/library/ubuntu:devel AS runtime
|
||||
|
||||
RUN apt update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt install libqt6core6 libqt6httpserver6 libqt6websockets6 -y \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt install libqt6core6 libqt6httpserver6 libqt6websockets6 libhiredis1.1.0 -y \
|
||||
&& rm /var/lib/apt/lists/* /var/log/* -Rf
|
||||
|
||||
COPY --from=build /build/less_shitty_proxyjs /less_shitty_proxyjs
|
||||
|
||||
ENTRYPOINT [ "/less_shitty_proxyjs", "-l", "Any", "-p", "1234" ]
|
||||
ENTRYPOINT [ "/less_shitty_proxyjs" ]
|
||||
|
||||
EXPOSE 1234
|
||||
EXPOSE 8080
|
||||
|
@@ -6,12 +6,12 @@ metadata:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: less-shitty-proxyjs-deployment
|
||||
name: less-shitty-proxyjs
|
||||
namespace: less-shitty-proxyjs
|
||||
labels:
|
||||
app: less-shitty-proxyjs
|
||||
spec:
|
||||
replicas: 12
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: less-shitty-proxyjs
|
||||
@@ -24,16 +24,30 @@ spec:
|
||||
- name: less-shitty-proxyjs
|
||||
image: registry.brunner.ninja/feedc0de/less_shitty_proxyjs:latest
|
||||
ports:
|
||||
- containerPort: 1234
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: POD_NAME
|
||||
- name: PROXYJS_IDENTITY
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: PROXYJS_REDIS_HOST
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: less-shitty-proxyjs
|
||||
key: REDIS_HOST
|
||||
- name: PROXYJS_REDIS_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: less-shitty-proxyjs
|
||||
key: REDIS_PASSWORD
|
||||
- name: PROXYJS_ENDPOINT_ADDR
|
||||
value: "http://$(POD_IP):8080"
|
||||
imagePullSecrets:
|
||||
- name: quay-pull-secret
|
||||
---
|
||||
@@ -47,8 +61,9 @@ spec:
|
||||
app: less-shitty-proxyjs
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 1234
|
||||
targetPort: 1234
|
||||
name: http
|
||||
port: 80
|
||||
targetPort: 8080
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
@@ -69,4 +84,4 @@ spec:
|
||||
service:
|
||||
name: less-shitty-proxyjs
|
||||
port:
|
||||
number: 1234
|
||||
name: http
|
||||
|
@@ -20,7 +20,9 @@ OTHER_FILES += \
|
||||
client.html \
|
||||
index.html \
|
||||
script.js \
|
||||
style.css
|
||||
style.css \
|
||||
Dockerfile \
|
||||
kubernetes.yaml
|
||||
|
||||
redis {
|
||||
HEADERS += redisqtadapter.h
|
||||
|
82
main.cpp
82
main.cpp
@@ -9,6 +9,9 @@
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <QDebug>
|
||||
#include <QUuid>
|
||||
|
||||
static QHostAddress parseHostAddress(const QString &str);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -28,11 +31,27 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication::setApplicationVersion("1.0");
|
||||
|
||||
QHostAddress listenAddress = QHostAddress::Any;
|
||||
uint16_t port = 8000;
|
||||
QString identity = "test";
|
||||
if (auto str = qgetenv("PROXYJS_LISTEN_ADDR"); !str.isEmpty())
|
||||
listenAddress = parseHostAddress(str);
|
||||
|
||||
uint16_t port = 8080;
|
||||
if (auto str = qgetenv("PROXYJS_PORT"); !str.isEmpty())
|
||||
port = str.toInt();
|
||||
|
||||
QString identity = "proxyjs_" + QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
if (auto str = qgetenv("PROXYJS_IDENTITY"); !str.isEmpty())
|
||||
identity = str;
|
||||
|
||||
#ifdef FEATURE_REDIS
|
||||
QString redisHost = "localhost";
|
||||
if (auto str = qgetenv("PROXYJS_REDIS_HOST"); !str.isEmpty())
|
||||
redisHost = str;
|
||||
QString redisPassword;
|
||||
if (auto str = qgetenv("PROXYJS_REDIS_PASSWORD"); !str.isEmpty())
|
||||
redisPassword = str;
|
||||
QString endpointAddr;
|
||||
if (auto str = qgetenv("PROXYJS_ENDPOINT_ADDR"); !str.isEmpty())
|
||||
endpointAddr = str;
|
||||
#endif
|
||||
|
||||
{
|
||||
@@ -66,24 +85,18 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication::translate("main", "The redis password"),
|
||||
QCoreApplication::translate("main", "redisPassword")};
|
||||
parser.addOption(redisPasswordOption);
|
||||
|
||||
QCommandLineOption endpointAddrOption{QStringList{ "e", "endpointAddr" },
|
||||
QCoreApplication::translate("main", "Endpoint address for traefik"),
|
||||
QCoreApplication::translate("main", "endpointAddr")};
|
||||
parser.addOption(endpointAddrOption);
|
||||
#endif
|
||||
|
||||
parser.process(app);
|
||||
|
||||
if (parser.isSet(listenAddrOption))
|
||||
{
|
||||
if (const auto &str = parser.value(listenAddrOption); str == "Any")
|
||||
listenAddress = QHostAddress::Any;
|
||||
else if (str == "AnyIPv4")
|
||||
listenAddress = QHostAddress::AnyIPv4;
|
||||
else if (str == "AnyIPv6")
|
||||
listenAddress = QHostAddress::AnyIPv6;
|
||||
else if (str == "LocalHost")
|
||||
listenAddress = QHostAddress::LocalHost;
|
||||
else if (str == "LocalHostIPv6")
|
||||
listenAddress = QHostAddress::LocalHostIPv6;
|
||||
else
|
||||
listenAddress = QHostAddress{str};
|
||||
listenAddress = parseHostAddress(parser.value(listenAddrOption));
|
||||
}
|
||||
if (parser.isSet(portOption))
|
||||
{
|
||||
@@ -103,9 +116,16 @@ int main(int argc, char *argv[])
|
||||
redisHost = parser.value(redisHostOption);
|
||||
if (parser.isSet(redisPasswordOption))
|
||||
redisPassword = parser.value(redisPasswordOption);
|
||||
if (parser.isSet(endpointAddrOption))
|
||||
endpointAddr = parser.value(endpointAddrOption);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FEATURE_REDIS
|
||||
if (endpointAddr.isEmpty())
|
||||
endpointAddr = QString{"http://localhost:%0"}.arg(port);
|
||||
#endif
|
||||
|
||||
qSetMessagePattern(QString{"%{time dd.MM.yyyy HH:mm:ss.zzz} %0 "
|
||||
"["
|
||||
"%{if-debug}D%{endif}"
|
||||
@@ -134,10 +154,6 @@ int main(int argc, char *argv[])
|
||||
redisPassword.toUtf8().constData());
|
||||
}
|
||||
|
||||
redisAsyncCommand(redis, NULL, NULL, "SET %s %s",
|
||||
QString{"traefik/http/services/proxyjs_%0/loadbalancer/servers/0/url"}.arg(identity).toUtf8().constData(),
|
||||
QString{"http://localhost:%0"}.arg(port).toUtf8().constData());
|
||||
|
||||
qDebug() << "redis connected";
|
||||
#endif
|
||||
|
||||
@@ -160,10 +176,40 @@ int main(int argc, char *argv[])
|
||||
return -2;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_REDIS
|
||||
redisAsyncCommand(redis, NULL, NULL, "SET %s %s",
|
||||
QString{"traefik/http/services/%0/loadbalancer/servers/0/url"}
|
||||
.arg(identity).toUtf8().constData(),
|
||||
endpointAddr.toUtf8().constData()
|
||||
);
|
||||
#endif
|
||||
|
||||
qDebug() << "server started on" << listenAddress << "port" << port;
|
||||
|
||||
auto result = app.exec();
|
||||
|
||||
#ifdef FEATURE_REDIS
|
||||
redisAsyncCommand(redis, NULL, NULL, "DEL %s",
|
||||
QString{"traefik/http/services/%0/loadbalancer/servers/0/url"}
|
||||
.arg(identity).toUtf8().constData());
|
||||
#endif
|
||||
|
||||
qDebug() << "bey bey!";
|
||||
return result;
|
||||
}
|
||||
|
||||
static QHostAddress parseHostAddress(const QString &str)
|
||||
{
|
||||
if (str == "Any")
|
||||
return QHostAddress::Any;
|
||||
else if (str == "AnyIPv4")
|
||||
return QHostAddress::AnyIPv4;
|
||||
else if (str == "AnyIPv6")
|
||||
return QHostAddress::AnyIPv6;
|
||||
else if (str == "LocalHost")
|
||||
return QHostAddress::LocalHost;
|
||||
else if (str == "LocalHostIPv6")
|
||||
return QHostAddress::LocalHostIPv6;
|
||||
else
|
||||
return QHostAddress{str};
|
||||
}
|
||||
|
@@ -76,15 +76,15 @@ void WebServer::createTraefikRoute(const QString &serial)
|
||||
|
||||
redisAsyncCommand(m_redis, NULL, NULL, "SET %s %s",
|
||||
QString{"traefik/http/routers/proxyjs_%0/service"}.arg(serial).toUtf8().constData(),
|
||||
QString{"proxyjs_%0"}.arg(m_identity).toUtf8().constData());
|
||||
m_identity.toUtf8().constData());
|
||||
|
||||
redisAsyncCommand(m_redis, NULL, NULL, "SET %s %s",
|
||||
QString{"traefik/http/routers/proxyjs_%0/tls/certresolver"}.arg(serial).toUtf8().constData(),
|
||||
"myresolver");
|
||||
// redisAsyncCommand(m_redis, NULL, NULL, "SET %s %s",
|
||||
// QString{"traefik/http/routers/proxyjs_%0/tls/certresolver"}.arg(serial).toUtf8().constData(),
|
||||
// "myresolver");
|
||||
|
||||
redisAsyncCommand(m_redis, NULL, NULL, "SET %s %s",
|
||||
QString{"traefik/http/routers/proxyjs_%0/priority"}.arg(serial).toUtf8().constData(),
|
||||
"15");
|
||||
"999999");
|
||||
}
|
||||
|
||||
void WebServer::destroyTraefikRoute(const QString &serial)
|
||||
@@ -100,8 +100,8 @@ void WebServer::destroyTraefikRoute(const QString &serial)
|
||||
redisAsyncCommand(m_redis, NULL, NULL, "DEL %s",
|
||||
QString{"traefik/http/routers/proxyjs_%0/service"}.arg(serial).toUtf8().constData());
|
||||
|
||||
redisAsyncCommand(m_redis, NULL, NULL, "DEL %s",
|
||||
QString{"traefik/http/routers/proxyjs_%0/tls/certresolver"}.arg(serial).toUtf8().constData());
|
||||
// redisAsyncCommand(m_redis, NULL, NULL, "DEL %s",
|
||||
// QString{"traefik/http/routers/proxyjs_%0/tls/certresolver"}.arg(serial).toUtf8().constData());
|
||||
|
||||
redisAsyncCommand(m_redis, NULL, NULL, "DEL %s",
|
||||
QString{"traefik/http/routers/proxyjs_%0/priority"}.arg(serial).toUtf8().constData());
|
||||
|
Reference in New Issue
Block a user