Compare commits

..

1 Commits

Author SHA1 Message Date
Philipp Rothmann 12b2248b74 wip replicasets 2022-07-21 13:11:54 +02:00
11 changed files with 77 additions and 227 deletions

View File

@ -1,41 +0,0 @@
---
kind: pipeline
name: deploy to swarm-test.autonomic.zone
steps:
- name: deployment
image: git.coopcloud.tech/coop-cloud/stack-ssh-deploy:latest
settings:
host: swarm-test.autonomic.zone
stack: wekan
generate_secrets: true
purge: true
deploy_key:
from_secret: drone_ssh_swarm_test
networks:
- proxy
environment:
DOMAIN: wekan.swarm-test.autonomic.zone
STACK_NAME: wekan
LETS_ENCRYPT_ENV: production
SECRET_OAUTH2_SECRET_VERSION: v1
ENTRYPOINT_VERSION: v1
SECRET_OAUTH2_SECRET_VERSION: v1
trigger:
branch:
- main
---
kind: pipeline
name: generate recipe catalogue
steps:
- name: release a new version
image: plugins/downstream
settings:
server: https://build.coopcloud.tech
token:
from_secret: drone_abra-bot_token
fork: true
repositories:
- coop-cloud/auto-recipes-catalogue-json
trigger:
event: tag

View File

@ -1,16 +1,11 @@
TYPE=wekan
TIMEOUT=300
ENABLE_AUTO_UPDATE=true
LETS_ENCRYPT_ENV=production
SECRET_OAUTH2_SECRET_VERSION=v1
COMPOSE_FILE="compose.yml"
# Set this to run mongodb in replicaset mode (needs initialisation!)
# COMPOSE_FILE="${COMPOSE_FILE}:compose.rs.yml"
DOMAIN=wekan.example.com
ROOT_URL=https://wekan.example.com
DOMAIN=board.example.org
ROOT_URL=https://board.example.org
DEBUG=false
@ -26,15 +21,12 @@ RICHER_CARD_COMMENT_EDITOR=false
# PASSWORD_LOGIN_ENABLED=false
# LOGO_IMG_URL=https://authentik.example.com/static/dist/assets/icons/icon_left_brand.svg
# LOGO_LINK_URL=https://authentik.example.com
### OAUTH2 ###
OAUTH2_ENABLED=false
# OAUTH2_LOGIN_STYLE=redirect
# OAUTH2_CLIENT_ID=wekan
# OAUTH2_SERVER_URL=https://authentik.example.com
# OAUTH2_SERVER_URL=https://sso.${DOMAIN}
# OAUTH2_AUTH_ENDPOINT=/application/o/authorize/
# OAUTH2_USERINFO_ENDPOINT=/application/o/userinfo/
# OAUTH2_TOKEN_ENDPOINT=/application/o/token/
@ -44,7 +36,6 @@ OAUTH2_ENABLED=false
# OAUTH2_FULLNAME_MAP=given_name
# OAUTH2_EMAIL_MAP=email
# PROPAGATE_OIDC_DATA=true
# OIDC_REDIRECTION_ENABLED=true
### LDAP ###

View File

@ -35,19 +35,4 @@ needed to enable oplog setting in wekan, which isneeded to run bigger instances?
after mongo conaintainer came up the first time run:
```
abra app run wekan.example.org db mongo
> rs.initiate()
```
## Promote user to admin
If using SSO, it might happen that there is no admin user. If so, you can fix it manually in the database:
```
$ abra app run <app-name> db bash
# mongo
> use wekan
> db.users.find({'username': '<your username>'})
> db.users.updateOne({'_id': '<_id from result above>'}, {$set: {'isAdmin': true}})
```
abra app command wekan.example.org db init_db

18
abra.sh
View File

@ -1,17 +1,3 @@
export SECRET_OAUTH2_SECRET_VERSION=v1
export ENTRYPOINT_VERSION=v2
set_settings(){
mongo wekan --eval '
db.settings.updateOne(
{},
{
$set: {
"disableForgotPassword": true,
"displayAuthenticationMethod" : false,
"disableRegistration" : true,
"customTopLeftCornerLogoImageUrl": "'$LOGO_IMG_URL'",
"customTopLeftCornerLogoLinkUrl": "'$LOGO_LINK_URL'",
}
}
)'
}
export INIT_REPLICA_VERSION=v2

View File

@ -1,20 +0,0 @@
authentik:
env:
OAUTH2_ENABLED: "true"
OAUTH2_SERVER_URL: https://authentik.example.com
# TODO: set CLIENT_ID as secret
OAUTH2_CLIENT_ID: wekan
uncomment:
- OAUTH2_LOGIN_STYLE
- OAUTH2_AUTH_ENDPOINT
- OAUTH2_USERINFO_ENDPOINT
- OAUTH2_TOKEN_ENDPOINT
- OAUTH2_REQUEST_PERMISSIONS
- OAUTH2_ID_MAP
- OAUTH2_USERNAME_MAP
- OAUTH2_FULLNAME_MAP
- OAUTH2_EMAIL_MAP
- PROPAGATE_OIDC_DATA
- OIDC_REDIRECTION_ENABLED
shared_secrets:
wekan_secret: oauth2_secret

BIN
backup.db Normal file

Binary file not shown.

View File

@ -1,10 +0,0 @@
version: "3.8"
services:
db:
command: mongod --oplogSize 128 --replSet rs0
app:
environment:
- MONGO_URL=mongodb://db:27017/wekan?replicaSet=rs01
- MONGO_OPLOG_URL=mongodb://db:27017/local?replicaSet=rsWekan=value

View File

@ -1,15 +1,16 @@
version: '3.8'
services:
db:
image: mongo:5.0
environment:
- LOGO_IMG_URL
- LOGO_LINK_URL
command: mongod --oplogSize 128 --quiet
image: mongo:4.4
command: mongod --bind_ip_all --oplogSize 128 --replSet rs0
volumes:
- wekan-db:/data/db
networks:
- internal
configs:
- source: init-replica
target: /docker-entrypoint-initdb.d/init-replica.sh
mode: 0555
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet
interval: 30s
@ -19,14 +20,15 @@ services:
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: "mongodump --archive=/data/db/wekan.db"
backupbot.backup.post-hook: "rm -rf /data/db/wekan.db"
backupbot.backup.path: "/data/db/wekan.db"
backupbot.backup.pre-hook: "mkdir /tmp/backup/ && mongodump --archive=/tmp/backup/wekan.db"
backupbot.backup.post-hook: "rm -rf /tmp/backup"
backupbot.backup.path: "/tmp/backup/"
app:
image: quay.io/wekan/wekan:v7.30
image: quay.io/wekan/wekan:v6.28
environment:
- MONGO_URL=mongodb://db:27017/wekan
- MONGO_URL=mongodb://db:27017/wekan?replicaSet=rs0
- MONGO_OPLOG_URL=mongodb://db:27017/local?replicaSet=rs0
- DOMAIN
- ROOT_URL
- DEBUG
@ -53,23 +55,22 @@ services:
- OAUTH2_EMAIL_MAP
- DEFAULT_AUTHENTICATION_METHOD
- PROPAGATE_OIDC_DATA
- OIDC_REDIRECTION_ENABLED
networks:
- internal
- proxy
depends_on:
- db
healthcheck:
test: bash /build/healthcheck.sh
test: node /build/healthcheck.js # no curl for healthcheck in wekan container
interval: 30s
timeout: 10s
retries: 10
start_period: 3m
start_period: 1m
secrets:
- oauth2_secret
configs:
- source: healthcheck_sh
target: /build/healthcheck.sh
- source: healthcheck_js
target: /build/healthcheck.js
mode: 0555
- source: entrypoint
target: /home/wekan/app/docker-entrypoint.sh
@ -86,8 +87,7 @@ services:
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
- "coop-cloud.${STACK_NAME}.version=2.1.1+v7.30"
- "coop-cloud.${STACK_NAME}.timeout=${TIMEOUT:-120}"
- "coop-cloud.${STACK_NAME}.version=0.6.0+v6.28"
volumes:
wekan-db:
@ -98,13 +98,15 @@ networks:
internal:
configs:
healthcheck_sh:
name: ${STACK_NAME}_healthcheck_sh
file: healthcheck.sh
healthcheck_js:
name: ${STACK_NAME}_healthcheck_js
file: healthcheck.js
entrypoint:
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
file: entrypoint.sh.tmpl
template_driver: golang
init-replica:
name: ${STACK_NAME}_init-replica_${INIT_REPLICA_VERSION}
file: init-replica.sh
secrets:
oauth2_secret:

23
healthcheck.js Normal file
View File

@ -0,0 +1,23 @@
const http = require('http');
const options = {
host: '0.0.0.0',
port: 8080,
timeout: 2000
};
const healthCheck = http.request(options, (res) => {
console.log(`HEALTHCHECK STATUS: ${res.statusCode}`);
if (res.statusCode == 200) {
process.exit(0);
}
else {
process.exit(1);
}
});
healthCheck.on('error', function (err) {
console.error('ERROR');
process.exit(1);
});
healthCheck.end();

View File

@ -1,87 +0,0 @@
#!/bin/sh
printf "GET / HTTP/1.1\n\n" > /dev/tcp/127.0.0.1/8080
if [ $? != 0 ]; then
echo "Webservice not accessible"
exit 1
fi
CPU_USAGE_THRESHOLD=100.0
PID=$(pidof node)
if [ -z "$PID" ]; then
echo "Node.js process not running."
exit 1
fi
STATE_FILE="/tmp/cpu_usage_state_$PID"
# Function to get total CPU time
get_total_cpu_time() {
cat /proc/stat | grep '^cpu ' | awk '{sum=0; for(i=2;i<=NF;i++) sum += $i; print sum;}'
}
# Function to get process CPU time
get_process_cpu_time() {
cat /proc/$PID/stat | awk '{print $14+$15}' # Only user and system time
}
# Function to get the number of CPUs
get_cpu_count() {
grep -c '^processor' /proc/cpuinfo
}
# Main script
if [ -z "$PID" ]; then
echo "Usage: $0 <pid>"
exit 1
fi
# Check if the process directory exists
if [ ! -d "/proc/$PID" ]; then
echo "Process with PID $PID does not exist."
exit 1
fi
# Get current CPU times
current_total=$(get_total_cpu_time)
current_process=$(get_process_cpu_time $PID)
# Check for previous state
if [ -f "$STATE_FILE" ]; then
# Read previous state
read prev_total prev_process < "$STATE_FILE"
# Calculate the CPU usage
delta_total=$((current_total - prev_total))
delta_process=$((current_process - prev_process))
CPU_COUNT=$(get_cpu_count)
# Normalize CPU usage across all CPUs and calculate percentage
if [ $delta_total -gt 0 ]; then # To avoid division by zero
CPU_USAGE=$(awk -v delta_process="$delta_process" -v delta_total="$delta_total" -v cpu_count="$CPU_COUNT" \
'BEGIN {printf "%.2f", (delta_process / delta_total) * 100 * cpu_count}')
awk -v usage="$CPU_USAGE" -v threshold="$CPU_USAGE_THRESHOLD" '
BEGIN {
if (usage > threshold) {
print "High CPU usage: " usage "% (Threshold: " threshold "%)";
exit 1; # Exit with status 1 for high usage
} else {
print "CPU usage within limits: " usage "%";
exit 0; # Normal exit status
}
}'
EXIT_STATUS=$?
else
echo "No enough data to calculate CPU usage. Please try again."
fi
else
echo "No previous data found. Run the script later to get CPU usage."
fi
# Save current state
echo "$current_total $current_process" > "$STATE_FILE"
if [ $EXIT_STATUS -ne 0 ]; then
echo "Exiting due to high CPU usage."
exit $EXIT_STATUS
fi

21
init-replica.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/sh
set -e
#host=${HOSTNAME:-$(hostname -f)}
# shut down again
#mongod --pidfilepath /tmp/docker-entrypoint-temp-mongod.pid --shutdown
# # restart again binding to 0.0.0.0 to allow a replset with 10.7.7.6
# mongod --oplogSize 8 --replSet rs0 --noauth \
# --config /tmp/docker-entrypoint-temp-config.json \
# --bind_ip 0.0.0.0 --port 27017 \
# --tlsMode disabled \
# --logpath /proc/1/fd/1 --logappend \
# --pidfilepath /tmp/docker-entrypoint-temp-mongod.pid --fork
# init replset with defaults
mongo 0.0.0.0 --eval "rs.initiate()"
echo "Waiting to become a master"
echo 'while (!db.isMaster().ismaster) { sleep(100); }' | mongo
echo "I'm the master!"