Skip to content

Commit 0f1c658

Browse files
committed
made keycloak required for new deployments and using profile instead of multiple compose files
1 parent 9a24b25 commit 0f1c658

File tree

5 files changed

+70
-105
lines changed

5 files changed

+70
-105
lines changed

config-keycloak.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"session_type": "synced",
3-
"demo_mode": false
3+
"demo_mode": false,
4+
"authenticator": "keycloak",
5+
"account_url": "https://accounts.aam-digital.com"
46
}

docker-compose-backend.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

docker-compose.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,36 @@ services:
55
image: aamdigital/ndb-server:${VERSION:?No release specified}
66
networks:
77
- internal
8-
- nginx-proxy_default
98
depends_on:
10-
- couchdb
9+
- ${COMPOSE_PROFILES:-couchdb}
1110
volumes:
1211
- ./config.json:/usr/share/nginx/html/assets/config.json
13-
- ./child-photos:/usr/share/nginx/html/assets/child-photos
14-
#- ./keycloak.json:/usr/share/nginx/html/assets/keycloak.json
12+
- ./keycloak.json:/usr/share/nginx/html/assets/keycloak.json
1513
environment:
1614
VIRTUAL_HOST: ${APP_URL:?App URL not set}
1715
LETSENCRYPT_HOST: ${APP_URL:?App URL not set}
18-
COUCHDB_URL: http://couchdb:5984
16+
COUCHDB_URL: http://${COMPOSE_PROFILES:-couchdb}:5984
17+
restart: unless-stopped
18+
19+
# (optional) backend. Only deployed if "COMPOSE_PROFILES=backend" is set in the `.env` file
20+
backend:
21+
image: aamdigital/replication-ms:latest
22+
networks:
23+
- internal
24+
depends_on:
25+
- couchdb
26+
environment:
27+
DATABASE_URL: http://couchdb:5984
28+
DATABASE_NAME: app
29+
DATABASE_USER: admin
30+
DATABASE_PASSWORD: ${COUCHDB_PASSWORD:?Admin password not set}
31+
JWT_SECRET: ${JWT_SECRET:?JWT secret not set}
32+
JWT_PUBLIC_KEY: "-----BEGIN PUBLIC KEY-----\n${PUBLIC_KEY}\n-----END PUBLIC KEY-----"
33+
SENTRY_DSN: ${SENTRY_DSN}
34+
PORT: 5984
1935
restart: unless-stopped
36+
profiles:
37+
- backend
2038

2139
couchdb:
2240
image: couchdb:3

interactive_setup.sh

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,51 +52,19 @@ if [ "$app" == 0 ]; then
5252
url=$org.$DOMAIN
5353
echo "APP_URL=$url" >> "$path/.env"
5454
echo "App URL: $url"
55-
(cd "$path" && docker compose up -d)
56-
57-
# wait for DB to be ready
58-
source "$path/.env"
59-
while [ "$status" != 200 ]; do
60-
sleep 4
61-
echo "Waiting for DB to be ready"
62-
status=$(curl --silent --output /dev/null "https://$APP_URL/db/_utils/" -I -w "%{http_code}\n")
63-
done
64-
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app"
65-
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app-attachments"
6655
else
6756
echo "Instance '$org' already exists"
6857
fi
6958

7059
backend=$(docker ps | grep -c "\-$org-backend")
71-
if [ "$backend" == 0 ]; then
72-
echo "Do you want to add the permission backend?[y/n]"
73-
read -r withBackend
74-
if [ "$withBackend" == "y" ] || [ "$withBackend" == "Y" ]; then
75-
cp docker-compose-backend.yml "$path/docker-compose.yml"
76-
generate_password
77-
echo "JWT_SECRET=$password" >> "$path/.env"
78-
79-
if [ -f "$path/keycloak.json" ]; then
80-
# adjust Keycloak config
81-
getKeycloakKey
82-
echo "PUBLIC_KEY=$publicKey" >> "$path/.env"
83-
sed -i "s/$kid/<KID>/g" "$path/couchdb.ini"
84-
sed -i "s|$publicKey|<PUBLIC_KEY>|g" "$path/couchdb.ini"
85-
(cd "$path" && docker compose down)
86-
fi
87-
88-
(cd "$path" && docker compose up -d)
89-
backend=1
90-
echo "Backend added"
91-
elif [ "$app" == 0 ]; then
92-
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app/_security" -d '{"admins": { "names": [], "roles": [] }, "members": { "names": [], "roles": ["user_app"] } }'
93-
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app-attachments/_security" -d '{"admins": { "names": [], "roles": [] }, "members": { "names": [], "roles": ["user_app"] } }'
94-
fi
95-
fi
9660

9761
if [ ! -f "$path/keycloak.json" ]; then
98-
echo "Do you want to add authentication via Keycloak?[y/n]"
99-
read -r keycloak
62+
if [ "$app" == 0 ]; then
63+
keycloak="y"
64+
else
65+
echo "Do you want to add authentication via Keycloak?[y/n]"
66+
read -r keycloak
67+
fi
10068
source "$path/.env"
10169
if [ "$keycloak" == "y" ] || [ "$keycloak" == "Y" ]; then
10270
container=$(docker ps -aqf "name=keycloak-keycloak")
@@ -108,9 +76,7 @@ if [ ! -f "$path/keycloak.json" ]; then
10876
# Get Keycloak config from API
10977
getKeycloakKey
11078
curl --silent --location "https://$KEYCLOAK_URL/admin/realms/$org/clients/$client/installation/providers/keycloak-oidc-keycloak-json" --header "Authorization: Bearer $token" > "$path/keycloak.json"
111-
cp config-keycloak.json "$path/config.json"
11279
sed -i "s/\"account_url\": \".*\"/\"account_url\": \"https:\/\/$ACCOUNTS_URL\"/g" "$path/config.json"
113-
sed -i "s/\#\- .\/keycloak/\- .\/keycloak/g" "$path/docker-compose.yml"
11480

11581
# Set Keycloak public key for bearer auth
11682
if [ "$backend" == 1 ]; then
@@ -119,7 +85,16 @@ if [ ! -f "$path/keycloak.json" ]; then
11985
sed -i "s/<KID>/$kid/g" "$path/couchdb.ini"
12086
sed -i "s|<PUBLIC_KEY>|$publicKey|g" "$path/couchdb.ini"
12187
fi
122-
(cd "$path" && docker compose down && docker compose up -d)
88+
89+
# wait for DB to be ready
90+
(cd "$path" && docker compose up -d)
91+
while [ "$status" != 200 ]; do
92+
sleep 4
93+
echo "Waiting for DB to be ready"
94+
status=$(curl --silent --output /dev/null "https://$APP_URL/db/_utils/" -I -w "%{http_code}\n")
95+
done
96+
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app"
97+
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app-attachments"
12398

12499
if [ "$app" == 1 ]; then
125100
echo "Do you want to migrate existing users from CouchDB to Keycloak?[y/n]"
@@ -143,6 +118,34 @@ if [ ! -f "$path/keycloak.json" ]; then
143118
fi
144119
fi
145120

121+
if [ "$backend" == 0 ]; then
122+
echo "Do you want to add the permission backend?[y/n]"
123+
read -r withBackend
124+
if [ "$withBackend" == "y" ] || [ "$withBackend" == "Y" ]; then
125+
echo "COMPOSE_PROFILES=backend" >> "$path/.env"
126+
generate_password
127+
echo "JWT_SECRET=$password" >> "$path/.env"
128+
129+
if [ -f "$path/keycloak.json" ]; then
130+
# adjust Keycloak config
131+
getKeycloakKey
132+
echo "PUBLIC_KEY=$publicKey" >> "$path/.env"
133+
sed -i "s/$kid/<KID>/g" "$path/couchdb.ini"
134+
sed -i "s|$publicKey|<PUBLIC_KEY>|g" "$path/couchdb.ini"
135+
(cd "$path" && docker compose down)
136+
fi
137+
138+
(cd "$path" && docker compose up -d)
139+
backend=1
140+
echo "Backend added"
141+
elif [ "$app" == 0 ]; then
142+
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app/_security" -d '{"admins": { "names": [], "roles": [] }, "members": { "names": [], "roles": ["user_app"] } }'
143+
curl -X PUT -u "admin:$COUCHDB_PASSWORD" "https://$APP_URL/db/app-attachments/_security" -d '{"admins": { "names": [], "roles": [] }, "members": { "names": [], "roles": ["user_app"] } }'
144+
fi
145+
fi
146+
147+
148+
146149
if [ "$app" == 0 ] && [ "$UPTIMEROBOT_API_KEY" != "" ] && [ "$UPTIMEROBOT_ALERT_ID" != "" ]; then
147150
echo "Do you want create UptimeRobot monitoring?[y/n]"
148151
read -r createsMonitors

0 commit comments

Comments
 (0)