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