Skip to content

Commit bb1c9d7

Browse files
authored
Authentik: change install to UV & increase resources to 10GB RAM (#4364)
1 parent 3b5a901 commit bb1c9d7

File tree

3 files changed

+89
-75
lines changed

3 files changed

+89
-75
lines changed

ct/authentik.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ APP="Authentik"
99
var_tags="${var_tags:-identity-provider}"
1010
var_disk="${var_disk:-12}"
1111
var_cpu="${var_cpu:-6}"
12-
var_ram="${var_ram:-8192}"
12+
var_ram="${var_ram:-10240}"
1313
var_os="${var_os:-debian}"
1414
var_version="${var_version:-12}"
1515
var_unprivileged="${var_unprivileged:-1}"
@@ -29,6 +29,13 @@ function update_script() {
2929
fi
3030
RELEASE=$(curl -fsSL https://api.github.com/repos/goauthentik/authentik/releases/latest | grep "tarball_url" | awk '{print substr($2, 2, length($2)-3)}')
3131
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
32+
NODE_VERSION="22"
33+
PG_VERSION="16"
34+
setup_uv
35+
install_postgresql
36+
install_node_and_modules
37+
install_go
38+
3239
msg_info "Stopping ${APP}"
3340
systemctl stop authentik-server
3441
systemctl stop authentik-worker
@@ -54,17 +61,14 @@ function update_script() {
5461
go build -o /opt/authentik/authentik-server /opt/authentik/cmd/server/
5562
msg_ok "Built ${APP} server"
5663

57-
msg_info "Installing Python Dependencies"
64+
msg_info "Building Authentik"
5865
cd /opt/authentik
59-
$STD poetry install --only=main --no-ansi --no-interaction --no-root
60-
$STD poetry export --without-hashes --without-urls -f requirements.txt --output requirements.txt
61-
$STD pip install --no-cache-dir -r requirements.txt
62-
$STD pip install .
63-
msg_ok "Installed Python Dependencies"
66+
$STD uv sync --frozen --no-install-project --no-dev
67+
uv run python -m lifecycle.migrate
68+
ln -s /opt/authentik/.venv/bin/gunicorn /usr/local/bin/gunicorn
69+
ln -s /opt/authentik/.venv/bin/celery /usr/local/bin/celery
70+
msg_ok "Authentik built"
6471

65-
msg_info "Updating ${APP} to v${RELEASE} (Patience)"
66-
cp -r /opt/authentik/authentik/blueprints /opt/authentik/blueprints
67-
$STD bash /opt/authentik/lifecycle/ak migrate
6872
echo "${RELEASE}" >/opt/${APP}_version.txt
6973
msg_ok "Updated ${APP} to v${RELEASE}"
7074

frontend/public/json/authentik.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"script": "ct/authentik.sh",
2121
"resources": {
2222
"cpu": 6,
23-
"ram": 8192,
23+
"ram": 10240,
2424
"hdd": 12,
2525
"os": "debian",
2626
"version": "12"
@@ -33,7 +33,11 @@
3333
},
3434
"notes": [
3535
{
36-
"text": "Authentik is very resource-heavy, it is recommended to use at least 8GB RAM anytime!",
36+
"text": "Authentik is very resource-heavy, it is recommended to use at least 10GB RAM anytime!",
37+
"type": "warning"
38+
},
39+
{
40+
"text": "Some updates don't work due to massive dependency errors, it's recommended to do a backup before updating or a pg_dump and a new LXC.",
3741
"type": "warning"
3842
}
3943
]

install/authentik-install.sh

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ update_os
1515

1616
msg_info "Installing Dependencies (Patience)"
1717
$STD apt-get install -y \
18-
gpg \
1918
pkg-config \
2019
libffi-dev \
2120
build-essential \
@@ -33,9 +32,15 @@ $STD apt-get install -y \
3332
libxmlsec1-openssl \
3433
libmaxminddb0 \
3534
python3-pip \
35+
redis-server \
3636
git
3737
msg_ok "Installed Dependencies"
3838

39+
setup_uv
40+
PG_VERSION="16" install_postgresql
41+
NODE_VERSION="22" install_node_and_modules
42+
install_go
43+
3944
msg_info "Installing yq"
4045
cd /tmp
4146
YQ_LATEST="$(curl -fsSL https://api.github.com/repos/mikefarah/yq/releases/latest | grep -Po '"tag_name": "\K.*?(?=")')"
@@ -56,46 +61,8 @@ cat <<EOF >/etc/GeoIP.conf
5661
EOF
5762
msg_ok "Installed GeoIP"
5863

59-
msg_info "Setting up Python 3"
60-
cd /tmp
61-
curl -fsSL "https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz" -o "Python.tgz"
62-
tar -zxf Python.tgz
63-
cd Python-3.12.1
64-
$STD ./configure --enable-optimizations
65-
$STD make altinstall
66-
cd ~
67-
$STD update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1
68-
msg_ok "Setup Python 3"
69-
70-
msg_info "Setting up Node.js Repository"
71-
mkdir -p /etc/apt/keyrings
72-
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
73-
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
74-
msg_ok "Set up Node.js Repository"
75-
76-
msg_info "Installing Node.js"
77-
$STD apt-get update
78-
$STD apt-get install -y nodejs
79-
msg_ok "Installed Node.js"
80-
81-
msg_info "Installing Golang"
82-
set +o pipefail
83-
temp_file=$(mktemp)
84-
golang_tarball=$(curl -fsSL https://go.dev/dl/ | grep -oP 'go[\d\.]+\.linux-amd64\.tar\.gz' | head -n 1)
85-
curl -fsSL "https://golang.org/dl/${golang_tarball}" -o "$temp_file"
86-
tar -C /usr/local -xzf "$temp_file"
87-
ln -sf /usr/local/go/bin/go /usr/local/bin/go
88-
rm -f "$temp_file"
89-
set -o pipefail
90-
msg_ok "Installed Golang"
91-
92-
msg_info "Installing Redis"
93-
$STD apt-get install -y redis-server
94-
systemctl enable -q --now redis-server
95-
msg_ok "Installed Redis"
96-
9764
msg_info "Installing PostgreSQL"
98-
$STD apt-get install -y postgresql postgresql-contrib
65+
$STD apt-get install -y postgresql-16 postgresql-contrib-16
9966
DB_NAME="authentik"
10067
DB_USER="authentik"
10168
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
@@ -111,71 +78,110 @@ RELEASE=$(curl -fsSL https://api.github.com/repos/goauthentik/authentik/releases
11178
mkdir -p /opt/authentik
11279
curl -fsSL "${RELEASE}" -o "authentik.tar.gz"
11380
tar -xzf authentik.tar.gz -C /opt/authentik --strip-components 1 --overwrite
81+
export NODE_OPTIONS="--max-old-space-size=4096"
11482
cd /opt/authentik/website
11583
$STD npm install
11684
$STD npm run build-bundled
85+
11786
cd /opt/authentik/web
11887
$STD npm install
11988
$STD npm run build
120-
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
89+
12190
cd /opt/authentik
12291
$STD go mod download
12392
$STD go build -o /go/authentik ./cmd/server
12493
$STD go build -o /opt/authentik/authentik-server /opt/authentik/cmd/server/
125-
cd /opt/authentik
126-
$STD pip3 install --upgrade pip
127-
$STD pip3 install poetry poetry-plugin-export
128-
ln -s /usr/local/bin/poetry /usr/bin/poetry
129-
$STD poetry install --only=main --no-ansi --no-interaction --no-root
130-
$STD poetry export --without-hashes --without-urls -f requirements.txt --output requirements.txt
131-
$STD pip install --no-cache-dir -r requirements.txt
132-
$STD pip install .
94+
$STD uv sync --frozen --no-install-project --no-dev
95+
#$STD pip3 install --no-cache-dir --upgrade pip
96+
#$STD pip3 install --upgrade pip
97+
#$STD pip3 install poetry poetry-plugin-export
98+
99+
#ln -s /usr/local/bin/poetry /usr/bin/poetry
100+
#$STD poetry install --only=main --no-ansi --no-interaction --no-root
101+
#$STD poetry export --without-hashes --without-urls -f requirements.txt --output requirements.txt
102+
#$STD pip install --no-cache-dir -r requirements.txt
103+
#$STD pip install .
133104
mkdir -p /etc/authentik
134105
mv /opt/authentik/authentik/lib/default.yml /etc/authentik/config.yml
135106
$STD yq -i ".secret_key = \"$(openssl rand -hex 32)\"" /etc/authentik/config.yml
136107
$STD yq -i ".postgresql.password = \"${DB_PASS}\"" /etc/authentik/config.yml
137108
$STD yq -i ".geoip = \"/opt/authentik/tests/GeoLite2-City-Test.mmdb\"" /etc/authentik/config.yml
138109
cp -r /opt/authentik/authentik/blueprints /opt/authentik/blueprints
139110
$STD yq -i ".blueprints_dir = \"/opt/authentik/blueprints\"" /etc/authentik/config.yml
140-
ln -s /usr/bin/python3 /usr/bin/python
141-
ln -s /usr/local/bin/gunicorn /usr/bin/gunicorn
142-
ln -s /usr/local/bin/celery /usr/bin/celery
143-
$STD bash /opt/authentik/lifecycle/ak migrate
144-
cd ~
111+
#ln -s /usr/bin/python3 /usr/bin/python
112+
#ln -s /usr/local/bin/gunicorn /usr/bin/gunicorn
113+
#ln -s /usr/local/bin/celery /usr/bin/celery
114+
#$STD bash /opt/authentik/lifecycle/ak migrate
115+
cd /opt/authentik
116+
uv run python -m lifecycle.migrate
117+
ln -s /opt/authentik/.venv/bin/gunicorn /usr/local/bin/gunicorn
118+
ln -s /opt/authentik/.venv/bin/celery /usr/local/bin/celery
119+
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
145120
msg_ok "Installed authentik"
146121

147122
msg_info "Creating Services"
148123
cat <<EOF >/etc/systemd/system/authentik-server.service
149124
[Unit]
150-
Description = authentik Server
125+
Description=authentik Go Server (API Gateway)
126+
After=network.target
127+
Wants=redis.service postgresql.service
151128
152129
[Service]
153-
ExecStart=/opt/authentik/authentik-server
154130
WorkingDirectory=/opt/authentik/
131+
ExecStart=/opt/authentik/authentik-server
155132
Restart=always
156133
RestartSec=5
134+
Environment=DJANGO_SETTINGS_MODULE=authentik.root.settings
157135
158136
[Install]
159137
WantedBy=multi-user.target
160138
EOF
161139

162140
cat <<EOF >/etc/systemd/system/authentik-worker.service
163141
[Unit]
164-
Description = authentik Worker
142+
Description=authentik Celery Worker
143+
After=network.target redis.service postgresql.service
144+
Requires=redis.service
165145
166146
[Service]
167-
Environment=DJANGO_SETTINGS_MODULE="authentik.root.settings"
168-
ExecStart=celery -A authentik.root.celery worker -Ofair --max-tasks-per-child=1 --autoscale 3,1 -E -B -s /tmp/celerybeat-schedule -Q authentik,authentik_scheduled,authentik_events
169-
WorkingDirectory=/opt/authentik/authentik
147+
Type=simple
148+
WorkingDirectory=/opt/authentik
149+
ExecStart=/opt/authentik/.venv/bin/celery \
150+
-A authentik.root.celery worker \
151+
-Ofair \
152+
--max-tasks-per-child=1 \
153+
--autoscale 3,1 \
154+
-Q authentik,authentik_scheduled,authentik_events \
155+
-E
170156
Restart=always
171157
RestartSec=5
158+
Environment=DJANGO_SETTINGS_MODULE=authentik.root.settings
172159
173160
[Install]
174161
WantedBy=multi-user.target
175162
EOF
176-
systemctl enable -q --now authentik-server
177-
sleep 2
178-
systemctl enable -q --now authentik-worker
163+
164+
cat <<EOF >/etc/systemd/system/authentik-celery-beat.service
165+
[Unit]
166+
Description=authentik Celery Beat Scheduler
167+
After=network.target
168+
169+
[Service]
170+
Type=simple
171+
WorkingDirectory=/opt/authentik
172+
ExecStart=/opt/authentik/.venv/bin/celery \
173+
-A authentik.root.celery beat \
174+
-s /tmp/celerybeat-schedule
175+
Restart=always
176+
RestartSec=5
177+
#User=authentik
178+
Environment=DJANGO_SETTINGS_MODULE=authentik.root.settings
179+
180+
[Install]
181+
WantedBy=multi-user.target
182+
EOF
183+
184+
systemctl enable -q --now authentik-server authentik-worker authentik-celery-beat
179185
msg_ok "Created Services"
180186

181187
motd_ssh

0 commit comments

Comments
 (0)