Skip to content

Commit

Permalink
update for https and add dev mode command
Browse files Browse the repository at this point in the history
  • Loading branch information
Charro Gruver committed Oct 12, 2023
1 parent 53f5268 commit 23d1b38
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
33 changes: 30 additions & 3 deletions dev-init/env-init.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
#!/usr/bin/env bash

if [[ ! -d ${PROJECTS_ROOT}/env-tmp]]
set -x

OC=/projects/bin/oc

while [[ ! -f /home/user/.kube/config ]]
do
printf '.'
sleep 2
done

if [[ -f ${PROJECTS_ROOT}/env-tmp/set-env.sh ]]
then
mkdir -p ${PROJECTS_ROOT}/env-tmp
rm ${PROJECTS_ROOT}/env-tmp/set-env.sh
touch ${PROJECTS_ROOT}/env-tmp/set-env.sh
else
if [[ ! -d ${PROJECTS_ROOT}/env-tmp ]]
then
mkdir -p ${PROJECTS_ROOT}/env-tmp
fi
touch ${PROJECTS_ROOT}/env-tmp/set-env.sh
fi

API_ROUTE=https://$(oc get route ${DEVWORKSPACE_ID}-${CONTAINER_NAME}-${TARGET_PORT}-${ENDPOINT_NAME} -o jsonpath={.spec.host})
APP_URL=https://$(${OC} --kubeconfig=/home/user/.kube/config get route ${DEVWORKSPACE_ID}-dev-tools-3000-pelorus-metrics -o jsonpath={.spec.host})
KEYCLOAK_URL=https://$(${OC} --kubeconfig=/home/user/.kube/config get route ${DEVWORKSPACE_ID}-keycloak-8081-keycloak -o jsonpath={.spec.host})

echo "export NEXTAUTH_URL=${APP_URL}" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export APP_ROOT=${APP_URL}" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export NEXTAUTH_SECRET=\"+03/pWr4sFvxrcm29hwnXLREWjFfmW2toTCUyNcLytc=\"" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export KEYCLOAK_ISSUER=${KEYCLOAK_URL}/realms/pelorus" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export KEYCLOAK_ID=pelorus-client" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export KEYCLOAK_SECRET=null" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export KCADM=/opt/keycloak/bin/kcadm.sh" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
echo "export KCADM_CONFIG=/tmp/kcadm.config" >> ${PROJECTS_ROOT}/env-tmp/set-env.sh
18 changes: 11 additions & 7 deletions dev-init/keycloak.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#!/usr/bin/env bash

KCADM=/opt/keycloak/bin/kcadm.sh
KCADM_CONFIG=/tmp/kcadm.config
APP_ROOT=http://cgruver-pelorus-workspace-pelorus-metrics.apps.sno-2.clg.lab
echo "Wait for env config"
while [[ ! -f ${PROJECTS_ROOT}/env-tmp/set-env.sh ]]
do
printf '.'
sleep 2
done
. ${PROJECTS_ROOT}/env-tmp/set-env.sh

echo "Waiting for KeyCloak to start"
while ! ${KCADM} config credentials --server http://localhost:8081 --realm master --user admin --password admin --config ${KCADM_CONFIG}
do
printf '.'
sleep 5
sleep 2
done

${KCADM} create realms -s realm=pelorus -s enabled=true -o --config ${KCADM_CONFIG}
${KCADM} create users -r pelorus -s username=pelorus-metrics -s enabled=true --config ${KCADM_CONFIG}
${KCADM} set-password -r pelorus --username pelorus-metrics --new-password pelorus --config ${KCADM_CONFIG}
${KCADM} create users -r pelorus -s username=pelorus -s enabled=true --config ${KCADM_CONFIG}
${KCADM} set-password -r pelorus --username pelorus --new-password pelorus --config ${KCADM_CONFIG}
${KCADM} create clients -r pelorus -s clientId=pelorus-client -s publicClient="true" -s "redirectUris=[\"${APP_ROOT}/*\"]" -s enabled=true -s "rootUrl=${APP_ROOT}" -s "webOrigins=[\"+\"]" --config ${KCADM_CONFIG}
${KCADM} create roles -r pelorus -s name=pelorus-metrics --config ${KCADM_CONFIG}
${KCADM} add-roles --uusername pelorus-metrics --rolename pelorus-metrics -r pelorus --config ${KCADM_CONFIG}
${KCADM} add-roles --uusername pelorus --rolename pelorus-metrics -r pelorus --config ${KCADM_CONFIG}
19 changes: 18 additions & 1 deletion devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ components:
path: /home/user/.npm
endpoints:
- exposure: public
protocol: https
name: pelorus-metrics
targetPort: 3000
- volume:
Expand Down Expand Up @@ -93,8 +94,13 @@ components:
value: admin
- name: KEYCLOAK_ADMIN_PASSWORD
value: admin
- name: PROXY_ADDRESS_FORWARDING
value: "true"
- name: KC_PROXY
value: edge
endpoints:
- exposure: public
protocol: https
name: keycloak
targetPort: 8081
- name: oc-cli
Expand All @@ -115,11 +121,22 @@ commands:
label: Copy OpenShift CLI
id: cp-oc-cli
- exec:
commandLine: "${PROJECT_SOURCE}/dev-init/keycloak.sh"
commandLine: ". ${PROJECTS_ROOT}/env-tmp/set-env.sh ; export NODE_EXTRA_CA_CERTS=/tmp/node-extra-certificates/ca.crt ; npm run dev"
component: dev-tools
workingDir: "${PROJECTS_ROOT}/developer-intelligence-prototype"
label: "Developer Intelligence Dev Mode"
id: dev-intel-run
- exec:
commandLine: "nohup ${PROJECT_SOURCE}/dev-init/env-init.sh > ${PROJECTS_ROOT}/env-init.log 2>&1 &"
component: dev-tools
id: init-env
- exec:
commandLine: "nohup ${PROJECT_SOURCE}/dev-init/keycloak.sh> ${PROJECTS_ROOT}/keycloak-init.log 2>&1 &"
component: keycloak
id: init-keycloak
events:
preStart:
- cp-oc-cli
postStart:
- init-env
- init-keycloak

0 comments on commit 23d1b38

Please sign in to comment.