mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-16 03:56:54 +02:00
Working controller & docker container for GKE
This commit is contained in:
parent
0510f85a8f
commit
417aa9547b
4 changed files with 75 additions and 3 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "../version.h"
|
||||
|
||||
#include <libpq-fe.h>
|
||||
#include <sstream>
|
||||
|
||||
using json = nlohmann::json;
|
||||
namespace {
|
||||
|
@ -200,6 +201,10 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
|
|||
json empty;
|
||||
json config;
|
||||
|
||||
const char *nwidparam[1] = {
|
||||
PQgetvalue(res, i, 0)
|
||||
};
|
||||
|
||||
config["id"] = PQgetvalue(res, i, 0);
|
||||
config["nwid"] = PQgetvalue(res, i, 0);
|
||||
config["creationTime"] = std::stoull(PQgetvalue(res, i, 1));
|
||||
|
@ -225,7 +230,7 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
|
|||
"SELECT host(ip_range_start), host(ip_range_end) FROM ztc_network_assignment_pool WHERE network_id = $1",
|
||||
1,
|
||||
NULL,
|
||||
params,
|
||||
nwidparam,
|
||||
NULL,
|
||||
NULL,
|
||||
0);
|
||||
|
@ -252,7 +257,7 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
|
|||
"SELECT host(address), bits, host(via) FROM ztc_network_route WHERE network_id = $1",
|
||||
1,
|
||||
NULL,
|
||||
params,
|
||||
nwidparam,
|
||||
NULL,
|
||||
NULL,
|
||||
0);
|
||||
|
@ -284,6 +289,8 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
|
|||
PQclear(r2);
|
||||
|
||||
_networkChanged(empty, config, false);
|
||||
|
||||
fprintf(stderr, "%s", OSUtils::jsonDump(config, 2).c_str());
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
|
@ -1234,4 +1241,4 @@ void PostgreSQL::onlineNotificationThread()
|
|||
}
|
||||
PQfinish(conn);
|
||||
}
|
||||
#endif //ZT_CONTROLLER_USE_LIBPQ
|
||||
#endif //ZT_CONTROLLER_USE_LIBPQ
|
||||
|
|
15
docker/Dockerfile
Normal file
15
docker/Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Dockerfile for ZeroTier Central Controllers
|
||||
FROM centos:7
|
||||
MAINTAINER Adam Ierymekno <adam.ierymenko@zerotier.com>, Grant Limberg <grant.limberg@zerotier.com>
|
||||
|
||||
RUN yum update -y
|
||||
RUN yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
|
||||
RUN yum install -y postgresql10
|
||||
|
||||
ADD zerotier-one /usr/local/bin/zerotier-one
|
||||
RUN chmod a+x /usr/local/bin/zerotier-one
|
||||
|
||||
ADD docker/main.sh /
|
||||
RUN chmod a+x /main.sh
|
||||
|
||||
ENTRYPOINT /main.sh
|
44
docker/main.sh
Normal file
44
docker/main.sh
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "$ZT_IDENTITY_PATH" ]; then
|
||||
echo '*** FAILED: ZT_IDENTITY_PATH environment variable is not defined'
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$ZT_DB_HOST" ]; then
|
||||
echo '*** FAILED: ZT_DB_HOST environment variable not defined'
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$ZT_DB_PORT" ]; then
|
||||
echo '*** FAILED: ZT_DB_PORT environment variable not defined'
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$ZT_DB_USER" ]; then
|
||||
echo '*** FAILED: ZT_DB_USER environment variable not defined'
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$ZT_DB_PASSWORD" ]; then
|
||||
echo '*** FAILED: ZT_DB_PASSWORD environment variable not defined'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p /var/lib/zerotier-one
|
||||
|
||||
pushd /var/lib/zerotier-one
|
||||
ln -s $ZT_IDENTITY_PATH/identity.public identity.public
|
||||
ln -s $ZT_IDENTITY_PATH/identity.secret identity.secret
|
||||
popd
|
||||
|
||||
echo "{
|
||||
\"settings\": {
|
||||
\"portMappingEnabled\": true,
|
||||
\"softwareUpdate\": \"disable\",
|
||||
\"interfadePrefixBlacklist\": [
|
||||
\"inot\",
|
||||
\"nat64\"
|
||||
],
|
||||
\"controllerDbPath\": \"postgres:host=${ZT_DB_HOST} port=${ZT_DB_PORT} dbname=ztc user=${ZT_DB_USER} password=${ZT_DB_PASSWORD}\"
|
||||
}
|
||||
}
|
||||
" > /var/lib/zerotier-one/local.conf
|
||||
|
||||
exec /usr/local/bin/zerotier-one /var/lib/zerotier-one
|
|
@ -22,6 +22,9 @@ ONE_OBJS+=osdep/LinuxNetLink.o
|
|||
NLTEST_OBJS+=osdep/LinuxNetLink.o node/InetAddress.o node/Utils.o node/Salsa20.o
|
||||
NLTEST_OBJS+=nltest.o
|
||||
|
||||
# for central controller builds
|
||||
TIMESTAMP=$(shell date +"%Y%m%d%H%M")
|
||||
|
||||
# Auto-detect miniupnpc and nat-pmp as well and use system libs if present,
|
||||
# otherwise build into binary as done on Mac and Windows.
|
||||
ONE_OBJS+=osdep/PortMapper.o
|
||||
|
@ -318,6 +321,9 @@ official: FORCE
|
|||
central-controller: FORCE
|
||||
make -j4 LDLIBS="-L/usr/pgsql-10/lib/ -lpq" CXXFLAGS="-I/usr/pgsql-10/include -fPIC" DEFS="-DZT_CONTROLLER_USE_LIBPQ" ZT_OFFICIAL=1 ZT_USE_X64_ASM_ED25519=1 one
|
||||
|
||||
central-controller-docker: central-controller
|
||||
docker build -t gcr.io/zerotier-central/ztcentral-controller:${TIMESTAMP} -f docker/Dockerfile .
|
||||
|
||||
debug: FORCE
|
||||
make ZT_DEBUG=1 one
|
||||
make ZT_DEBUG=1 selftest
|
||||
|
|
Loading…
Add table
Reference in a new issue