Skip to content

Commit f68b6a4

Browse files
committed
Zitadel Refactor Test
1 parent 2484a38 commit f68b6a4

2 files changed

Lines changed: 275 additions & 0 deletions

File tree

‎ct/zitadel.sh‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
_CS_DEFAULT_URL="https://raw.githubusercontent.com/community-scripts/DevScripts/main"
3+
_cs_boot="${COMMUNITY_SCRIPTS_CORE_DIR:-$(dirname "${BASH_SOURCE[0]}")/../../core}/core/build.func"
4+
source "$_cs_boot" 2>/dev/null || source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/build.func")
5+
# Copyright (c) 2021-2026 community-scripts ORG
6+
# Author: dave-yap (dave-yap) | Co-Author: remz1337, MickLesk (CanbiZ)
7+
# License: MIT | https://github.com/community-scripts/DevScripts/raw/main/LICENSE
8+
# Source: https://github.com/zitadel/zitadel
9+
10+
APP="Zitadel"
11+
var_tags="${var_tags:-identity-provider}"
12+
var_cpu="${var_cpu:-1}"
13+
var_ram="${var_ram:-1024}"
14+
var_disk="${var_disk:-8}"
15+
var_os="${var_os:-debian}"
16+
var_version="${var_version:-13}"
17+
var_arm64="${var_arm64:-yes}"
18+
var_unprivileged="${var_unprivileged:-1}"
19+
20+
if [[ -z "${var_zitadel_login:-}" ]] && command -v pveversion >/dev/null 2>&1; then
21+
var_zitadel_login=$(msg_menu "Choose the Zitadel login UI" \
22+
"v2" "Login V2 (Zitadel's default for new instances)" \
23+
"v1" "Login V1 (classic login built into the API)")
24+
fi
25+
export var_zitadel_login="${var_zitadel_login:-v2}"
26+
27+
header_info "$APP"
28+
variables
29+
color
30+
catch_errors
31+
32+
if [[ ! "${var_zitadel_login}" =~ ^v[12]$ ]]; then
33+
msg_error "var_zitadel_login must be v1 or v2"
34+
exit 1
35+
fi
36+
37+
function update_script() {
38+
header_info
39+
check_container_storage
40+
check_container_resources
41+
if [[ ! -f /etc/systemd/system/zitadel.service ]]; then
42+
msg_error "No ${APP} Installation Found!"
43+
exit
44+
fi
45+
46+
if check_for_gh_release "zitadel" "zitadel/zitadel"; then
47+
msg_info "Stopping Zitadel"
48+
if [[ -f /etc/systemd/system/zitadel-login.service ]]; then
49+
systemctl stop zitadel-login
50+
fi
51+
systemctl stop zitadel
52+
msg_ok "Stopped Zitadel"
53+
54+
fetch_and_deploy_gh_release "zitadel" "zitadel/zitadel" "prebuild" "${CHECK_UPDATE_RELEASE}" "/usr/local/bin" "zitadel-linux-$(arch_resolve).tar.gz"
55+
if [[ -f /etc/systemd/system/zitadel-login.service ]]; then
56+
NODE_VERSION="24" setup_nodejs
57+
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "zitadel-login" "zitadel/zitadel" "prebuild" "${CHECK_UPDATE_RELEASE}" "/opt/zitadel-login" "zitadel-login.tar.gz"
58+
fi
59+
60+
msg_info "Migrating Zitadel Database"
61+
$STD zitadel setup --masterkeyFile /opt/zitadel/.masterkey --config /opt/zitadel/config.yaml --init-projections=true
62+
msg_ok "Migrated Zitadel Database"
63+
64+
msg_info "Starting Zitadel"
65+
systemctl start zitadel
66+
if [[ -f /etc/systemd/system/zitadel-login.service ]]; then
67+
systemctl start zitadel-login
68+
fi
69+
msg_ok "Started Zitadel"
70+
msg_ok "Updated successfully!"
71+
fi
72+
exit
73+
}
74+
75+
start
76+
build_container
77+
description
78+
79+
msg_ok "Completed successfully!\n"
80+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
81+
echo -e "${INFO}${YW}Access it using the following URL:${CL}"
82+
if [[ "${var_zitadel_login}" == "v1" ]]; then
83+
echo -e "${GATEWAY}${BGN}http://${IP}:8080/ui/console${CL}"
84+
else
85+
echo -e "${GATEWAY}${BGN}https://${IP}:8080/ui/console${CL}"
86+
fi
87+
echo -e "${INFO}${YW}Admin credentials: ~/zitadel.creds (inside the container)${CL}"

‎install/zitadel-install.sh‎

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2026 community-scripts ORG
4+
# Author: dave-yap (dave-yap) | Co-Author: remz1337, MickLesk (CanbiZ)
5+
# License: MIT | https://github.com/community-scripts/DevScripts/raw/main/LICENSE
6+
# Source: https://github.com/zitadel/zitadel
7+
8+
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
9+
color
10+
verb_ip6
11+
catch_errors
12+
setting_up_container
13+
network_check
14+
update_os
15+
16+
var_zitadel_login="${var_zitadel_login:-v2}"
17+
18+
PG_VERSION="17" setup_postgresql
19+
PG_DB_NAME="zitadel" PG_DB_USER="zitadel" setup_postgresql_db
20+
fetch_and_deploy_gh_release "zitadel" "zitadel/zitadel" "prebuild" "latest" "/usr/local/bin" "zitadel-linux-$(arch_resolve).tar.gz"
21+
22+
msg_info "Configuring Zitadel"
23+
mkdir -p /opt/zitadel
24+
random_password 32 >/opt/zitadel/.masterkey
25+
# Zitadel's default password policy wants upper and lower case, a digit and a symbol
26+
ADMIN_PASS="$(random_password 20)Aa1!"
27+
cat <<EOF >/opt/zitadel/config.yaml
28+
ExternalDomain: ${LOCAL_IP}
29+
ExternalPort: 8080
30+
TLS:
31+
Enabled: false
32+
Database:
33+
postgres:
34+
Host: localhost
35+
Port: 5432
36+
Database: zitadel
37+
User:
38+
Username: zitadel
39+
Password: ${PG_DB_PASS}
40+
SSL:
41+
Mode: disable
42+
EOF
43+
if [[ "$var_zitadel_login" == "v1" ]]; then
44+
cat <<EOF >>/opt/zitadel/config.yaml
45+
Port: 8080
46+
ExternalSecure: false
47+
DefaultInstance:
48+
Features:
49+
LoginV2:
50+
Required: false
51+
FirstInstance:
52+
Org:
53+
Human:
54+
UserName: zitadel-admin@zitadel.localhost
55+
Password: ${ADMIN_PASS}
56+
PasswordChangeRequired: true
57+
EOF
58+
else
59+
cat <<EOF >>/opt/zitadel/config.yaml
60+
Port: 8081
61+
ExternalSecure: true
62+
DefaultInstance:
63+
Features:
64+
LoginV2:
65+
Required: true
66+
FirstInstance:
67+
LoginClientPatPath: /opt/zitadel/login-client.pat
68+
Org:
69+
Human:
70+
UserName: zitadel-admin@zitadel.localhost
71+
Password: ${ADMIN_PASS}
72+
PasswordChangeRequired: true
73+
LoginClient:
74+
Machine:
75+
Username: login-client
76+
Name: Automatically Initialized IAM_LOGIN_CLIENT
77+
Pat:
78+
ExpirationDate: 2099-01-01T00:00:00Z
79+
EOF
80+
fi
81+
chmod 600 /opt/zitadel/.masterkey /opt/zitadel/config.yaml
82+
msg_ok "Configured Zitadel"
83+
84+
msg_info "Initializing Zitadel"
85+
$STD zitadel init zitadel --config /opt/zitadel/config.yaml
86+
$STD zitadel setup --masterkeyFile /opt/zitadel/.masterkey --config /opt/zitadel/config.yaml --steps /opt/zitadel/config.yaml
87+
cat <<EOF >>~/zitadel.creds
88+
89+
Zitadel Admin
90+
Username: zitadel-admin@zitadel.localhost
91+
Initial Password: ${ADMIN_PASS}
92+
EOF
93+
chmod 600 ~/zitadel.creds
94+
msg_ok "Initialized Zitadel"
95+
96+
msg_info "Creating Service"
97+
cat <<EOF >/etc/systemd/system/zitadel.service
98+
[Unit]
99+
Description=Zitadel
100+
After=network.target postgresql.service
101+
Wants=postgresql.service
102+
103+
[Service]
104+
Type=simple
105+
ExecStart=/usr/local/bin/zitadel start --masterkeyFile /opt/zitadel/.masterkey --config /opt/zitadel/config.yaml
106+
Restart=always
107+
RestartSec=5
108+
109+
[Install]
110+
WantedBy=multi-user.target
111+
EOF
112+
systemctl enable -q --now zitadel
113+
msg_ok "Created Service"
114+
115+
if [[ "$var_zitadel_login" == "v2" ]]; then
116+
NODE_VERSION="24" setup_nodejs
117+
fetch_and_deploy_gh_release "zitadel-login" "zitadel/zitadel" "prebuild" "latest" "/opt/zitadel-login" "zitadel-login.tar.gz"
118+
119+
msg_info "Setting up Zitadel Login"
120+
$STD apt install -y nginx
121+
create_self_signed_cert "zitadel"
122+
cat <<EOF >/opt/zitadel/login.env
123+
ZITADEL_API_URL=http://127.0.0.1:8081
124+
ZITADEL_API_AWAITINITIALCONN=5m
125+
ZITADEL_SERVICE_USER_TOKEN_FILE=/opt/zitadel/login-client.pat
126+
ZITADEL_SESSION_COOKIE_SECRET=$(openssl rand -base64 32)
127+
NEXT_PUBLIC_BASE_PATH=/ui/v2/login
128+
HOSTNAME=127.0.0.1
129+
PORT=3000
130+
EOF
131+
chmod 600 /opt/zitadel/login.env /opt/zitadel/login-client.pat
132+
cat <<EOF >/etc/systemd/system/zitadel-login.service
133+
[Unit]
134+
Description=Zitadel Login
135+
After=network.target zitadel.service
136+
Wants=zitadel.service
137+
138+
[Service]
139+
Type=simple
140+
WorkingDirectory=/opt/zitadel-login
141+
EnvironmentFile=/opt/zitadel/login.env
142+
ExecStart=/opt/zitadel-login/entrypoint.sh node apps/login/server.js
143+
Restart=always
144+
RestartSec=5
145+
146+
[Install]
147+
WantedBy=multi-user.target
148+
EOF
149+
systemctl enable -q --now zitadel-login
150+
cat <<'EOF' >/etc/nginx/sites-available/zitadel
151+
server {
152+
listen 8080 ssl;
153+
http2 on;
154+
server_name _;
155+
ssl_certificate /etc/ssl/zitadel/zitadel.crt;
156+
ssl_certificate_key /etc/ssl/zitadel/zitadel.key;
157+
error_page 497 =301 https://$http_host$request_uri;
158+
159+
location = / {
160+
return 302 /ui/v2/login/;
161+
}
162+
163+
location /ui/v2/login {
164+
proxy_pass http://127.0.0.1:3000;
165+
proxy_http_version 1.1;
166+
proxy_set_header Host $http_host;
167+
proxy_set_header X-Forwarded-Proto $scheme;
168+
}
169+
170+
location /api/ {
171+
rewrite ^/api(/.*)$ $1 break;
172+
grpc_pass grpc://127.0.0.1:8081;
173+
grpc_set_header Host $http_host;
174+
}
175+
176+
location / {
177+
grpc_pass grpc://127.0.0.1:8081;
178+
grpc_set_header Host $http_host;
179+
}
180+
}
181+
EOF
182+
nginx_enable_site "zitadel"
183+
msg_ok "Set up Zitadel Login"
184+
fi
185+
186+
motd_ssh
187+
customize
188+
cleanup_lxc

0 commit comments

Comments
 (0)