Skip to content

Commit e5f74ad

Browse files
committed
1.2.0pre
1 parent 0a11812 commit e5f74ad

9 files changed

Lines changed: 185 additions & 100 deletions

File tree

Containerfile

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ RUN echo "" && \
5757
" \
5858
&& \
5959
ZT_NET_RUN_DEPS_ALPINE=" \
60+
moreutils \
6061
nodejs \
6162
npm \
6263
postgresql-client \
@@ -76,22 +77,22 @@ RUN echo "" && \
7677
package build go && \
7778
\
7879
clone_git_repo "${ZEROTIER_REPO_URL}" "${ZEROTIER_VERSION}" /usr/src/zerotier && \
79-
#build_assets src /build-assets/zerotier/src /usr/src/zerotier && \
80-
#build_assets scripts /build-assets/zerotier/scripts && \
80+
build_assets src /build-assets/zerotier/src "${GIT_REPO_SRC_ZEROTIER}" && \
81+
build_assets scripts /build-assets/zerotier/scripts && \
8182
\
82-
#if [ -d "/build-assets/zerotier/src" ] ; then cp -Rp /build-assets/zerotier/src/* /usr/src/ztnet ; fi; \
83-
#if [ -d "/build-assets/zerotier/scripts" ] ; then for script in /build-assets/zerotier/scripts/*.sh; do echo "** Applying $script"; bash $script; done && \ ; fi ; \
83+
cd "${GIT_REPO_SRC_ZEROTIER}" && \
8484
sed -i "s|ZT_SSO_SUPPORTED=1|ZT_SSO_SUPPORTED=0|g" make-linux.mk && \
8585
make -j $(nproc) -f make-linux.mk ZT_NONFREE=1 ZT_CONTROLLER=0 && \
8686
make install && \
8787
rm -rf /var/lib/zerotier-one && \
8888
container_build_log add "Zerotier" "${ZEROTIER_VERSION}" "${ZEROTIER_REPO_URL}" && \
8989
\
9090
clone_git_repo "${ZT_NET_REPO_URL}" "${ZT_NET_VERSION}" /usr/src/ztnet && \
91-
#build_assets src /build-assets/zt-net/src /usr/src/ztnet && \
92-
#build_assets scripts /build-assets/zt-net/scripts && \
93-
#if [ -d "/build-assets/zt-net/src" ] ; then cp -aRp /build-assets/zt-net/src/* /usr/src/ztnet ; fi; \
94-
#if [ -d "/build-assets/zt-net/scripts" ] ; then for script in /build-assets/zt-net/scripts/*.sh; do echo "** Applying $script"; bash $script; done && \ ; fi ; \
91+
build_assets src /build-assets/zt-net/src /usr/src/ztnet && \
92+
build_assets scripts /build-assets/zt-net/scripts && \
93+
cd /usr/src/ztnet/ztnodeid && \
94+
go mod tidy && \
95+
go build -ldflags='-s -w' -trimpath -o /usr/local/bin/ztmkworld cmd/mkworld/main.go && \
9596
cd /usr/src/ztnet && \
9697
npm install \
9798
@@ -104,12 +105,8 @@ RUN echo "" && \
104105
&& \
105106
npx prisma generate && \
106107
npm ci && \
107-
SKIP_ENV_VALIDATION=1 npm run build && \
108-
cd /usr/src/ztnet/ztnodeid && \
109-
go mod tidy && \
110-
go build -ldflags='-s -w' -trimpath -o /usr/bin/ztmkworld cmd/mkworld/main.go && \
111-
cd /usr/src/ztnet && \
112-
mkdir -p /app /app/.next && \
108+
SKIP_ENV_VALIDATION=1 npm run build:webpack && \
109+
mkdir -p /app/.next && \
113110
cp next.config.mjs package.json /app/ && \
114111
cp -R \
115112
public \
@@ -128,9 +125,9 @@ RUN echo "" && \
128125
/app/.next/ && \
129126
cd /app && \
130127
npm install \
131-
@prisma/client \
132-
@paralleldrive/cuid2 \
133-
&& \
128+
@prisma/client@6.16.3 \
129+
@paralleldrive/cuid2 \
130+
&& \
134131
\
135132
container_build_log add "ZT Net" "${ZT_NET_VERSION}" "${ZT_NET_REPO_URL}" && \
136133
echo "${ZT_NET_VERSION}" > /app/.ztnet-version && \

README.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ Images are built for `amd64` by default, with optional support for `arm64` and o
9090

9191
The following directories are used for configuration and can be mapped for persistent storage.
9292

93-
| Directory | Description |
94-
| --------- | ----------------------------- |
95-
| `/data/` | ZeroTier state information |
96-
| `/logs/` | zerotier Log Output Directory |
93+
| Directory | Description |
94+
| --------- | -------------------------- |
95+
| `/data/` | ZeroTier state information |
96+
| `/logs/` | Log Output Directory |
9797

9898
### Environment Variables
9999

@@ -128,6 +128,7 @@ Below is the complete list of available options that can be used to customize yo
128128
| `CONTROLLER_ENABLE_PORT_MAPPING` | Enable Port mapping | `TRUE` | |
129129
| `CONTROLLER_LISTEN_PORT` | Zerotier Controller listen port | `9993` | |
130130
| `CONTROLLER_LOG_FILE` | Controller Log File | `controller.log` | |
131+
| `CONTROLLER_LOG_PATH` | Where to store logs | `/logs/zerotier/` | |
131132
| `CONTROLLER_MANAGEMENT_NETWORKS` | Comma seperated value of networks allowed to manage controller | `0.0.0.0/0` | |
132133
| `CONTROLLER_USER` | What username to run controller as | `root` | |
133134
| `CONTROLLER_NETWORK` | (optional) Networks to join as Controller | | x |
@@ -136,19 +137,24 @@ Below is the complete list of available options that can be used to customize yo
136137

137138
#### UI Options
138139

139-
| Variable | Description | Default | `_FILE` |
140-
| ------------------- | -------------------------------------------------- | -------------------------------------------- | ------- |
141-
| `ENABLE_NGINX` | If wanting to use Nginx as proxy to UI_LISTEN_PORT | `TRUE` | |
142-
| `NGINX_LISTEN_PORT` | Nginx Listening Port | `80` | |
143-
| `UI_CONTROLLER_URL` | How can the UI access the controller | `http://localhost:${CONTROLLER_LISTEN_PORT}` | |
144-
| `UI_DB_HOST` | DB Host for Postgresql | | x |
145-
| `UI_DB_NAME` | DB Name for UI | | x |
146-
| `UI_DB_PASS` | Password for UI_DB_USER | | x |
147-
| `UI_DB_PORT` | DB Port for Postgresql | `5432` | x |
148-
| `UI_DB_USER` | DB User for UI_DB_NAME | | x |
149-
| `UI_LISTEN_PORT` | What port for the UI to listen on | `3000` | |
150-
| `UI_SECRET` | Random secret for session and cookie storage | `random` | x |
151-
| `UI_SITE_NAME` | Site name to display on UI | `ZTNET` | |
140+
| Variable | Description | Default | `_FILE` |
141+
| ------------------- | -------------------------------------------------------------- | -------------------------------------------- | ------- |
142+
| `ENABLE_NGINX` | If wanting to use Nginx as proxy to UI_LISTEN_PORT/UI_HOSTNAME | `TRUE` | |
143+
| `NGINX_LISTEN_PORT` | Nginx Listening Port | `80` | |
144+
| `UI_CONTROLLER_URL` | How can the UI access the controller | `http://127.0.0.1:${CONTROLLER_LISTEN_PORT}` | |
145+
| `UI_DB_HOST` | DB Host for Postgresql | | x |
146+
| `UI_DB_NAME` | DB Name for UI | | x |
147+
| `UI_DB_PASS` | Password for UI_DB_USER | | x |
148+
| `UI_DB_PORT` | DB Port for Postgresql | `5432` | x |
149+
| `UI_DB_USER` | DB User for UI_DB_NAME | | x |
150+
| `UI_HOSTNAME` | (nginx) Internal hostname to access UI for proxy purposes | `(container_hostname)` | x |
151+
| `UI_LISTEN_PORT` | What port for the UI to listen on | `3000` | |
152+
| `UI_LOG_FILE` | UI Log File | `ztnet.log` | |
153+
| `UI_LOG_PATH` | Where to store logs | `/logs/ui/` | |
154+
| `UI_PROTOCOL` | (nginx) Protocol to use for proxy | `http` | x |
155+
| `UI_SECRET` | Random secret for session and cookie storage | `random` | x |
156+
| `UI_SITE_NAME` | Site name to display on UI | `ZTNET` | |
157+
| `UI_USER` | Run UI as this user | `zerotier` | |
152158

153159
#### DNS Options
154160

examples/compose.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ services:
1616
- ./logs:/logs
1717
environment:
1818
- TIMEZONE=America/Vancouver
19-
- CONTAINER_NAME=zerotier-app
20-
- CONTAINER_ENABLE_MONITORING=FALSE
2119

2220
- MODE=CONTROLLER,UI
2321

@@ -36,13 +34,13 @@ services:
3634
restart: always
3735

3836
zerotier-db:
39-
image: docker.io/tiredofit/postgres:17
37+
image: docker.io/nfrastack/postgres:18
4038
container_name: zerotier-db
4139
volumes:
42-
- ./db:/var/lib/postgresql/data
40+
- ./logs:/logs
41+
- ./db:/data
4342
environment:
4443
- TIMEZONE=America/Vancouver
45-
- CONTAINER_NAME=zerotier-db
4644

4745
- SUPERUSER_PASS=password
4846
- DB_NAME=zerotier

rootfs/container/defaults/20-zerotier

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
LOG_PATH=${LOG_PATH:-"/logs/"}
6+
LOG_TYPE=${LOG_TYPE:-"FILE"}
7+
#
58
CONTROLLER_ALLOW_TCP_FALLBACK_RELAY=${CONTROLLER_ALLOW_TCP_FALLBACK_RELAY:-"TRUE"}
69
CONTROLLER_DATA_PATH=${CONTROLLER_DATA_PATH:-"/data/controller/"}
710
CONTROLLER_ENABLE_METRICS=${CONTROLLER_ENABLE_METRICS:-"FALSE"}
811
CONTROLLER_ENABLE_PORT_MAPPING=${CONTROLLER_ENABLE_PORT_MAPPING:-"TRUE"}
912
CONTROLLER_LISTEN_PORT=${CONTROLLER_LISTEN_PORT:-"9993"}
10-
CONTROLLER_LOG_FILE=${CONTROLLER_LOG_FILE:-"controller.log"}
13+
CONTROLLER_LOG_PATH=${CONTROLLER_LOG_PATH:-"${LOG_PATH%/}/controller/"}
14+
CONTROLLER_LOG_FILE=${CONTROLLER_LOG_FILE:-"zerotier.log"}
15+
CONTROLLER_LOG_TYPE=${CONTROLLER_LOG_TYPE:-"${LOG_TYPE}"}
1116
CONTROLLER_MANAGEMENT_NETWORKS=${CONTROLLER_MANAGEMENT_NETWORKS:-"127.0.0.1"}
1217
CONTROLLER_USER=${CONTROLLER_USER:-"root"}
13-
LOG_PATH=${LOG_PATH:-"/logs/"}
14-
LOG_TYPE=${LOG_TYPE:-"FILE"}
1518
MODE=${MODE:-"CONTROLLER,UI"}
19+
UI_DB_PORT=${UI_DB_PORT:-"5432"}
20+
UI_HOSTNAME=${UI_HOSTNAME:-"$(hostname)"}
1621
UI_LISTEN_PORT=${UI_LISTEN_PORT:-"3000"}
22+
UI_LOG_FILE=${UI_LOG_FILE:-"ztnet.log"}
23+
UI_LOG_PATH=${UI_LOG_PATH:-"${LOG_PATH%/}/ui/"}
24+
UI_LOG_TYPE=${UI_LOG_TYPE:-"${LOG_TYPE}"}
25+
UI_PROTOCOL=${UI_PROTOCOL:-"http"}
1726
UI_SITE_NAME=${UI_SITE_NAME:-"ZTNET"}
18-
UI_DB_PORT=${UI_DB_PORT:-"5432"}
19-
ZEROTIER_USER=${ZEROTIER_USER:-"zerotier"}
27+
UI_USER=${UI_USER:-"zerotier"}

rootfs/container/functions/20-zerotier

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,22 @@ complete -F _zerotier_zerotier-cli_completions zerotier-cli
5454
EOF
5555
}
5656

57-
zerotier_bootstrap_filesystem() {
58-
create_folder \
59-
"${CONTROLLER_DATA_PATH}" \
60-
zerotier:root 750
61-
62-
ln -sf "${CONTROLLER_DATA_PATH}" /var/lib/zerotier-one
63-
create_folder \
64-
"${LOG_PATH}" \
65-
zerotier:root 755
66-
}
57+
zerotier_controller_configure() {
58+
create_folder \
59+
"${CONTROLLER_DATA_PATH}" \
60+
"${CONTROLLER_USER}":root 750
61+
62+
ln -sf "${CONTROLLER_DATA_PATH}" /var/lib/zerotier-one
63+
64+
case "${CONTROLLER_LOG_TYPE,,}" in
65+
"file" | "both")
66+
create_folder \
67+
"${CONTROLLER_LOG_PATH}" \
68+
"${CONTROLLER_USER}":root 750
69+
create_logrotate zerotier-controller "${CONTROLLER_LOG_PATH%/}/${CONTROLLER_LOG_FILE}" "${CONTROLLER_USER}" root
70+
;;
71+
esac
6772

68-
zerotier_configure_controller() {
6973
if var_false "${CONTROLLER_ENABLE_METRICS}" ; then ln -sf /dev/null "${CONTROLLER_DATA_PATH%/}"/metrics.prom ; fi
7074
for management_network in ${CONTROLLER_MANAGEMENT_NETWORKS//,/$IFS}; do
7175
management_networks=${management_networks}"\"${management_network}\","
@@ -130,25 +134,40 @@ EOF
130134
fi
131135
}
132136

133-
zerotier_configure_ui() {
137+
zerotier_ui_configure() {
134138
sanity_var UI_SITE_URL "Site URL eg https://example.com"
135139

136-
sed -i \
137-
-e "s|{{UI_LISTEN_PORT}}|${UI_LISTEN_PORT}|g" \
138-
/etc/nginx/sites.enabled/${NGINX_SITE_ENABLED}.conf
140+
case "${UI_LOG_TYPE,,}" in
141+
"file" | "both" )
142+
create_folder \
143+
"${UI_LOG_PATH}" \
144+
"${UI_USER}":root 750
145+
create_logrotate zt-net "${UI_LOG_PATH%/}/${UI_LOG_FILE}" "${UI_USER}" root
146+
;;
147+
esac
139148

140149
transform_var file \
141150
DB_HOST \
142151
DB_NAME \
143152
DB_PASS \
144153
DB_PORT \
145154
DB_USER \
146-
UI_SECRET \
147155
UI_DB_HOST \
148156
UI_DB_NAME \
149157
UI_DB_PASS \
150158
UI_DB_PORT \
151-
UI_DB_USER
159+
UI_DB_USER \
160+
UI_HOSTNAME \
161+
UI_LISTEN_PORT \
162+
UI_PROTOCOL \
163+
UI_SECRET
164+
165+
update_template \
166+
/etc/nginx/sites.enabled/"${NGINX_SITE_ENABLED}".conf \
167+
UI_HOSTNAME \
168+
UI_LISTEN_PORT \
169+
UI_PROTOCOL \
170+
UI_SITE_URL
152171

153172
if [ -n "${UI_DB_HOST}" ]; then DB_HOST=${DB_HOST:-${UI_DB_HOST}}; fi
154173
if [ -n "${UI_DB_NAME}" ]; then DB_NAME=${DB_NAME:-${UI_DB_NAME}}; fi
@@ -164,11 +183,11 @@ ZT_ADDR=${ZT_ADDR}
164183
NEXT_PUBLIC_APP_VERSION=$(grep -o "ADD: ZT Net .* |" /container/build/${IMAGE_NAME/\//_}/build.log | awk '{print $4}')
165184
EOF
166185

167-
#envFilename='.env.production'
168-
#nextFolder='/app/.next/'
169-
170186
cd /app
171187
print_info "[ui] Applying migrations to the database"
188+
set -a
189+
source /app/.env
190+
set +a
172191
silent npx prisma migrate deploy
173192
silent print_info "[ui] Migrations applied successfully"
174193

@@ -187,9 +206,8 @@ PORT=${UI_LISTEN_PORT}
187206
NEXTAUTH_SECRET=${UI_SECRET}
188207
AUTH_SECRET=${UI_SECRET}
189208
NEXT_PUBLIC_SITE_NAME=${UI_SITE_NAME}
209+
NEXTAUTH_URL_INTERNAL=http://127.0.0.1:${UI_LISTEN_PORT}
190210
EOF
191-
192-
update_template /etc/nginx/sites.enabled/ztnet.conf HOSTNAME
193211
}
194212

195213
zerotier_setup_container_mode() {

rootfs/container/init/init.d/20-zerotier

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ SERVICE_NAME="zerotier"
99

1010
zerotier_setup_container_mode
1111
zerotier_add_bash_completion
12-
zerotier_bootstrap_filesystem
12+
1313

1414
if check_container_restarted ; then
1515
if var_true "${ENABLE_CONTROLLER}" ; then
1616
print_debug "Configuring Controller"
17-
zerotier_configure_controller
17+
zerotier_controller_configure
1818
else
1919
service_stop 20-controller
2020
fi
2121

2222
if var_true "${ENABLE_UI}" ; then
2323
print_debug "Configuring UI"
24-
zerotier_configure_ui
24+
25+
zerotier_ui_configure
2526
else
2627
service_stop 10-nginx
28+
service_stop 11-nginx-config-reload
2729
service_stop 20-ui
2830
fi
2931

rootfs/container/run/available/20-controller/run

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,39 @@
44
# SPDX-License-Identifier: MIT
55

66
source /container/base/functions/container/init
7-
SERVICE_NAME="zerotier-controller"
7+
SERVICE_NAME="controller"
88
prepare_service 20-zerotier
99
check_container_initialized
1010

11-
liftoff
11+
if [ "${CONTROLLER_USER}" != "root" ] ; then
12+
sudo_prefix="sudo -u ${CONTROLLER_USER}"
13+
fi
14+
15+
case "${CONTROLLER_LOG_TYPE,,}" in
16+
both )
17+
SHOW_OUTPUT=TRUE
18+
${sudo_prefix} touch "${CONTROLLER_LOG_PATH%/}"/"${CONTROLLER_LOG_FILE}"
19+
;;
20+
console )
21+
SHOW_OUTPUT=TRUE
22+
CONTROLLER_LOG_PATH=/dev
23+
CONTROLLER_LOG_FILE=null
1224

25+
;;
26+
file )
27+
SHOW_OUTPUT=FALSE
28+
${sudo_prefix} touch "${CONTROLLER_LOG_PATH%/}"/"${CONTROLLER_LOG_FILE}"
29+
silent_arg="silent"
30+
;;
31+
none )
32+
SHOW_OUTPUT=FALSE
33+
CONTROLLER_LOG_PATH=/dev
34+
CONTROLLER_LOG_FILE=null
35+
silent_arg="silent"
36+
;;
37+
esac
38+
39+
liftoff
1340
print_start "Starting Zerotier One $(zerotier-cli -v) in Controller Mode"
14-
silent exec zerotier-one ${ZEROTIER_ARGS}
41+
exec ${sudo_prefix} \
42+
zerotier-one ${ZEROTIER_ARGS} 2>&1| ts -m '%Y-%m-%dT%H:%M.%S [controller]' | ${silent_arg} ${sudo_prefix} tee -a "${CONTROLLER_LOG_PATH%/}"/"${CONTROLLER_LOG_FILE}"

0 commit comments

Comments
 (0)