Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keycloak upgrade #1187

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
src/node_modules
src/.npm
src/_tmp
src/.cache
src/.config
src/.nyc_output
src/dist
**/.next
_data
_data
**/node_modules
__coverage__
3 changes: 2 additions & 1 deletion .github/workflows/aps-cypress-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- name: Build GWA API Image
run: |
git clone https://github.com/bcgov/gwa-api.git
git clone -b feature/kc-upgrade https://github.com/bcgov/gwa-api.git
cd gwa-api/microservices/gatewayApi
docker build -t gwa-api:e2e .

Expand Down Expand Up @@ -54,6 +54,7 @@ jobs:
break
else
echo "Waiting for Cypress to Complete E2E Tests....."
docker compose logs cypress -n 5
sleep 1m
fi
done
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#FROM node:lts-alpine3.17
FROM node:16.14.2-alpine3.15
FROM node:20-alpine3.19

ARG APP_VERSION
ENV NEXT_PUBLIC_APP_VERSION=${APP_VERSION}
Expand All @@ -11,6 +10,9 @@ RUN apk add curl jq

WORKDIR /app

# Workaround due to an ESM error
COPY src/keycloak-admin-client ./keycloak-admin-client

COPY src/*.json ./
RUN npm install --legacy-peer-deps

Expand Down
62 changes: 40 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: e2e
version: '3.8'

x-common-variables: &common-variables
Expand All @@ -8,39 +9,56 @@ x-common-variables: &common-variables
KONG_PG_PASSWORD: konguser

services:
keycloak:
image: quay.io/keycloak/keycloak:15.1.1
container_name: keycloak
hostname: keycloak
keycloak-nodes:
image: keycloak:latest
deploy:
replicas: 2
endpoint_mode: dnsrr
build:
context: .
dockerfile: ./local/keycloak/Dockerfile
depends_on:
- kong-db
command:
[
'-b',
'0.0.0.0',
'-Djboss.socket.binding.port-offset=1001',
'-Dkeycloak.migration.action=import',
'-Dkeycloak.migration.provider=singleFile',
'-Dkeycloak.migration.file=/tmp/realm-config/master-realm.json',
'-Dkeycloak.migration.strategy=OVERWRITE_EXISTING',
'-Dkeycloak.profile.feature.upload_scripts=enabled',
'start',
'--optimized',
'--cache=ispn',
'--hostname',
'http://keycloak.localtest.me:9081/auth',
'--db-url',
'jdbc:postgresql://kong-db/keycloak',
'--db-username',
'keycloakuser',
'--db-password',
'keycloakuser',
'--http-enabled',
'true',
'--http-port',
'9081',
'--import-realm',
]
volumes:
- ./local/keycloak/master-realm.json:/opt/keycloak/data/import/master-realm.json
networks:
aps-net: {}

keycloak:
image: nginx:latest
ports:
- 9081:9081/tcp
environment:
#KEYCLOAK_USER: local
#KEYCLOAK_PASSWORD: local
DB_VENDOR: POSTGRES
DB_SCHEMA: public
DB_ADDR: kong-db:5432
DB_USER: keycloakuser
DB_PASSWORD: keycloakuser
- '9081:9081'
depends_on:
- keycloak-nodes
volumes:
- ./local/keycloak/master-realm.json:/tmp/realm-config/master-realm.json
- ./local/keycloak/nginx-lb.conf:/etc/nginx/conf.d/default.conf
networks:
aps-net:
aliases:
- keycloak.localtest.me
deploy:
restart_policy:
condition: any

oauth2-proxy:
image: quay.io/oauth2-proxy/oauth2-proxy:v7.2.0
container_name: oauth2-proxy
Expand Down
2 changes: 1 addition & 1 deletion e2e/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cd /tmp

while true; do
keycloakstatus=$(curl -o /dev/null -Isw '%{http_code}\n' http://keycloak.localtest.me:9081/auth/realms/master)
keycloakstatus=$(curl -o /dev/null -sw '%{http_code}\n' http://keycloak.localtest.me:9081/auth/realms/master)
echo "$keycloakstatus"
if [[ "$keycloakstatus" == "200" ]]; then
echo "Keycloak is up"
Expand Down
3 changes: 0 additions & 3 deletions local/db/database-init.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
CREATE ROLE keystonejsuser WITH LOGIN PASSWORD 'keystonejsuser';

CREATE DATABASE keystonejs OWNER keystonejsuser;

CREATE ROLE konguser WITH LOGIN PASSWORD 'konguser';

CREATE DATABASE kong OWNER konguser;

CREATE ROLE keycloakuser WITH LOGIN PASSWORD 'keycloakuser';

CREATE DATABASE keycloak OWNER keycloakuser;
2 changes: 1 addition & 1 deletion local/feeder-init/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apk add --no-cache curl
cd /tmp

while true; do
keycloakstatus=$(curl -o /dev/null -Isw '%{http_code}\n' http://keycloak.localtest.me:9081/auth/realms/master)
keycloakstatus=$(curl -o /dev/null -sw '%{http_code}\n' http://keycloak.localtest.me:9081/auth/realms/master)
echo "$keycloakstatus"
if [[ "$keycloakstatus" == "200" ]]; then
echo "Keycloak is up"
Expand Down
3 changes: 2 additions & 1 deletion local/gwa-api/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ PORTAL_ACTIVITY_TOKEN=
HOST_TRANSFORM_ENABLED=false
HOST_TRANSFORM_BASE_URL=
PLUGINS_RATELIMITING_REDIS_PASSWORD=s3cr3t
LOCAL_ENVIRONMENT=True
LOCAL_ENVIRONMENT=True
DATA_PLANES_CONFIG_PATH=/tmp/gwa/data_planes_config.json
9 changes: 9 additions & 0 deletions local/gwa-api/data_planes_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data_planes": {
"local.dataplane": {
"kube-api": "http://kubenull",
"kube-ns": "local-cluster",
"validate-upstreams": false
}
}
}
2 changes: 1 addition & 1 deletion local/gwa-api/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ kong-addr: $KONG_ADMIN_URL
EOF

while true; do
keycloakstatus=$(curl -o /dev/null -Isw '%{http_code}\n' http://keycloak.localtest.me:9081/auth/realms/master)
keycloakstatus=$(curl -o /dev/null -sw '%{http_code}\n' http://keycloak.localtest.me:9081/auth/realms/master)
echo "$keycloakstatus"
if [[ "$keycloakstatus" == "200" ]]; then
echo "Keycloak is up"
Expand Down
10 changes: 10 additions & 0 deletions local/keycloak/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM quay.io/keycloak/keycloak:nightly as builder

ENV KC_DB=postgres
RUN /opt/keycloak/bin/kc.sh build --http-relative-path=/auth

FROM quay.io/keycloak/keycloak:nightly
COPY --from=builder /opt/keycloak/ /opt/keycloak/
WORKDIR /opt/keycloak
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
CMD ["start", "--optimized", "--hostname", "http://localhost:8080", "--http-enabled", "true"]
Loading
Loading