Merge pull request #3380 from DrDynamic/keycloak

add Keycloak
This commit is contained in:
Shao Yu-Lung (Allen) 2023-04-28 23:32:09 +08:00 committed by GitHub
commit 1473bbfbd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 0 deletions

View File

@ -1067,3 +1067,15 @@ SOKETI_METRICS_SERVER_PORT=9601
### ONEDEV ##################################################
ONEDEV_HTTP_PORT=6610
ONEDEV_SSH_PORT=6611
### Keycloak ################################################
KEYCLOAK_VERSION=latest
KEYCLOAK_POSTGRES_INIT=true
KEYCLOAK_HTTP_PORT=8081
KEYCLOAK_CREATE_ADMIN_USER=true
KEYCLOAK_ADMIN_USER='admin'
KEYCLOAK_ADMIN_PASSWORD='secret'
KEYCLOAK_POSTGRES_HOST=postgres
KEYCLOAK_POSTGRES_USER=laradock_keycloak
KEYCLOAK_POSTGRES_PASSWORD=laradock_keycloak
KEYCLOAK_POSTGRES_DB=laradock_keycloak

View File

@ -1490,6 +1490,23 @@ docker-compose exec tarantool console
7 - There you can operate with tarantool database ([official documentation](https://www.tarantool.io/en/doc/latest/) can be helpful).
<br>
<a name="use Keycloak"></a>
## Use Keycloak
1. Run the Keycloak Container (`keycloak`) with the `docker-compose up` command. Example:
```bash
docker-compose up -d keycloak
```
2. Open your browser and visit the localhost on port 8081: `http://localhost:8081`
3. Login with the following credentials:
- Username: `admin`
- Password: `secret`
<br>
<a name="CodeIgniter"></a>

View File

@ -631,6 +631,10 @@ services:
- GITLAB_POSTGRES_USER=${GITLAB_POSTGRES_USER}
- GITLAB_POSTGRES_PASSWORD=${GITLAB_POSTGRES_PASSWORD}
- GITLAB_POSTGRES_DB=${GITLAB_POSTGRES_DB}
- KEYCLOAK_POSTGRES_INIT=${KEYCLOAK_POSTGRES_INIT}
- KEYCLOAK_POSTGRES_USER=${KEYCLOAK_POSTGRES_USER}
- KEYCLOAK_POSTGRES_PASSWORD=${KEYCLOAK_POSTGRES_PASSWORD}
- KEYCLOAK_POSTGRES_DB=${KEYCLOAK_POSTGRES_DB}
- JUPYTERHUB_POSTGRES_INIT=${JUPYTERHUB_POSTGRES_INIT}
- JUPYTERHUB_POSTGRES_USER=${JUPYTERHUB_POSTGRES_USER}
- JUPYTERHUB_POSTGRES_PASSWORD=${JUPYTERHUB_POSTGRES_PASSWORD}
@ -2100,3 +2104,24 @@ services:
- frontend
- backend
restart: always
### keycloak ##################################################
keycloak:
image: bitnami/keycloak:${KEYCLOAK_VERSION}
ports:
- "${KEYCLOAK_HTTP_PORT}:${KEYCLOAK_HTTP_PORT}"
environment:
- KEYCLOAK_HTTP_PORT=${KEYCLOAK_HTTP_PORT}
- KEYCLOAK_CREATE_ADMIN_USER=${KEYCLOAK_CREATE_ADMIN_USER}
- KEYCLOAK_ADMIN_USER=${KEYCLOAK_ADMIN_USER}
- KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_ADMIN_PASSWORD}
- KEYCLOAK_DATABASE_HOST=${KEYCLOAK_POSTGRES_HOST}
- KEYCLOAK_DATABASE_PORT=${POSTGRES_PORT}
- KEYCLOAK_DATABASE_NAME=${KEYCLOAK_POSTGRES_DB}
- KEYCLOAK_DATABASE_USER=${KEYCLOAK_POSTGRES_USER}
- KEYCLOAK_DATABASE_PASSWORD=${KEYCLOAK_POSTGRES_PASSWORD}
depends_on:
- postgres
networks:
- frontend
- backend

View File

@ -0,0 +1,44 @@
#!/bin/bash
#
# Copy createdb.sh.example to createdb.sh
# then uncomment then set database name and username to create you need databases
#
# example: .env POSTGRES_USER=appuser and need db name is myshop_db
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER myuser WITH PASSWORD 'mypassword';
# CREATE DATABASE myshop_db;
# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO myuser;
# EOSQL
#
# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found.
#
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db1 WITH PASSWORD 'db1';
# CREATE DATABASE db1;
# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1;
# EOSQL
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db2 WITH PASSWORD 'db2';
# CREATE DATABASE db2;
# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2;
# EOSQL
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db3 WITH PASSWORD 'db3';
# CREATE DATABASE db3;
# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3;
# EOSQL
#
### default database and user for keycloak ##############################################
if [ "$KEYCLOAK_POSTGRES_INIT" == 'true' ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER $KEYCLOAK_POSTGRES_USER WITH PASSWORD '$KEYCLOAK_POSTGRES_PASSWORD';
CREATE DATABASE $KEYCLOAK_POSTGRES_DB;
GRANT ALL PRIVILEGES ON DATABASE $KEYCLOAK_POSTGRES_DB TO $KEYCLOAK_POSTGRES_USER;
ALTER ROLE $KEYCLOAK_POSTGRES_USER CREATEROLE SUPERUSER;
EOSQL
echo
fi