Skip to content

Commit

Permalink
Merge pull request #1128 from cloud-pi-native/refactor/improve-integ-…
Browse files Browse the repository at this point in the history
…env-variables

refactor: ♻️ improve integration env vars management
  • Loading branch information
this-is-tobi authored May 22, 2024
2 parents 4598131 + 89ba672 commit 4bedbaf
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ apps/server/src/plugins/external
charts/

# integration helm values
env/dso-values-int.yaml
env/kind-values.yml
**/env/dso-values-integ.yaml
**/env/kind-values.yml

# tmp dev files
ci/kind/configs/rendered
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ Un chart Helm utilitaire est installé pour déployer les services qui ne sont p
Différents fichiers de `values.yml` sont disponibles pour personnaliser le déploiement de l'application dans le cluster Kind:

- Le fichier [./env/dso-values.yaml](./env/dso-values.yaml) contient les variables de base l'application.
- Le fichier [./env/dso-values-dev.yaml](./env/dso-values-dev.yaml) contient les variables de l'application pour le mode développement.
- Le fichier [./env/dso-values-int-example.yaml](./env/dso-values-int-example.yaml) contient les variables de l'application pour le mode intégration.
- Le fichier [./ci/kind/env/dso-values.yaml](./ci/kind/env/dso-values.yaml) contient les variables de base l'application.
- Le fichier [./ci/kind/env/dso-values-dev.yaml](./ci/kind/env/dso-values-dev.yaml) contient les variables de l'application pour le mode développement.
- Le fichier [./ci/kind/env/dso-values-int-example.yaml](./ci/kind/env/dso-values-int-example.yaml) contient les variables de l'application pour le mode intégration.

*__Notes:__ Un fichier d'environnement `./env/.env` est disponible pour fournir le chemin d'accès vers la `kubeconfig` du cluster d'intégration.*
> *__Notes:__*
> - *Un fichier d'environnement `./env/.env` est disponible pour fournir le chemin d'accès vers la `kubeconfig` du cluster d'intégration.*
> - *Les values du chart de la console sont disponibles [ici](https://github.com/cloud-pi-native/helm-charts/tree/main/charts/dso-console).*
### Base de données

Expand Down
1 change: 0 additions & 1 deletion apps/server/.env.integ-example
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ SONARQUBE_URL=
VAULT_TOKEN=
VAULT_URL=

KUBECONFIG_HOST_PATH=/path/to/kubeconfig
KUBECONFIG_PATH=$HOME/.kube/config
KUBECONFIG_CTX=

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ci/kind/run-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ if [ -z "$(kind get clusters | grep 'kind')" ]; then
[[ -d "$SCRIPTPATH/configs/rendered" ]] || mkdir -p "$SCRIPTPATH/configs/rendered/"

# Prepare kind config
if [[ -f "$SCRIPTPATH/../../env/kind-values.yml" ]]; then
if [[ -f "$SCRIPTPATH/env/kind-values.yml" ]]; then
KIND_CONFIG="$(helm template dev $SCRIPTPATH/configs/cluster \
--values $SCRIPTPATH/../../env/kind-values.yml)"
--values $SCRIPTPATH/env/kind-values.yml)"
echo "$KIND_CONFIG" > $SCRIPTPATH/configs/rendered/kind-config.yml
else
KIND_CONFIG="$(helm template dev $SCRIPTPATH/configs/cluster)"
Expand Down
27 changes: 15 additions & 12 deletions ci/kind/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export DOCKER_VERSION="$(docker --version)"
# Default
export SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
export HELM_RELEASE_NAME="dso"
export HELM_DIRECTORY="./helm"
export INTEGRATION_ARG=""
export INTEGRATION_ARGS_UTILS=""
export CI_ARGS=""
Expand All @@ -32,14 +31,16 @@ Following flags are available:
load - Load docker images from compose file into cluster nodes.
dev - Run application in development mode.
prod - Run application in production mode.
int - Run application in integration mode (need to combine with 'dev' or 'prod').
integ - Run application in integration mode (need to combine with 'dev' or 'prod').
-d Domains to add in /etc/hosts for local services resolution. Comma separated list. This will require sudo.
-f Path to the docker-compose file that will be used with Kind.
-i Install kind.
-k Path to the kubeconfig to use.
-t Tag used to deploy application images.
-h Print script help.\n\n"
Expand All @@ -60,7 +61,7 @@ while getopts hc:d:f:ik:t: flag; do
i)
export INSTALL_KIND=true;;
k)
export DEV_KUBECONFIG_PATH=${OPTARG};;
export KUBECONFIG_HOST_PATH=${OPTARG};;
t)
export TAG=${OPTARG};;
h | *)
Expand Down Expand Up @@ -165,15 +166,17 @@ fi


# Check for integration mode
if [[ "$COMMAND" =~ "int" ]]; then
if [[ "$COMMAND" =~ "integ" ]]; then
wait $JOB_LOAD
source ./env/.env.int
export INTEGRATION_ARGS="--values ./env/dso-values-int.yaml"
if [ -z "$DEV_KUBECONFIG_PATH" ]; then
printf "\n\n${red}[kind wrapper].${no_color} DEV_KUBECONFIG_PATH not defined in ./env/.env.int integration will certainly fail\nYou should also check you KUBECONFIG_CTX in ./env/dso-values-int.yaml\n\n"
source $SCRIPTPATH/../../env/.env.integ
export KUBECONFIG_HOST_PATH=$KUBECONFIG_HOST_PATH
export INTEGRATION_ARGS="--values $SCRIPTPATH/env/dso-values-integ.yaml"

if [ -z "$KUBECONFIG_HOST_PATH" ]; then
printf "\n\n${red}[kind wrapper].${no_color} KUBECONFIG_HOST_PATH not defined in ./env/.env.integ integration will certainly fail\nYou should also check you KUBECONFIG_CTX in $SCRIPTPATH/env/dso-values-integ.yaml\n\n"
exit 1
fi
export INTEGRATION_ARGS_UTILS="--set keycloak.enabled=false --set integration=true --set-file kubeconfig=$DEV_KUBECONFIG_PATH"
export INTEGRATION_ARGS_UTILS="--set integration=true --set-file kubeconfig=$KUBECONFIG_HOST_PATH"
fi


Expand All @@ -192,8 +195,8 @@ if [[ "$COMMAND" =~ "dev" ]]; then
helm --kube-context kind-kind upgrade \
--install \
--wait \
--values ./env/dso-values.yaml \
--values ./env/dso-values-dev.yaml \
--values $SCRIPTPATH/env/dso-values.yaml \
--values $SCRIPTPATH/env/dso-values-dev.yaml \
$INTEGRATION_ARGS \
$HELM_RELEASE_NAME cloud-pi-native/cpn-console

Expand All @@ -219,7 +222,7 @@ elif [[ "$COMMAND" =~ "prod" ]]; then
helm --kube-context kind-kind upgrade \
--install \
--wait \
--values ./env/dso-values.yaml \
--values $SCRIPTPATH/env/dso-values.yaml \
$CI_ARGS \
$INTEGRATION_ARGS \
$HELM_RELEASE_NAME cloud-pi-native/cpn-console
Expand Down
2 changes: 0 additions & 2 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
keycloak:
restart: always
Expand Down
2 changes: 0 additions & 2 deletions docker/docker-compose.integ.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
postgres:
restart: always
Expand Down
2 changes: 0 additions & 2 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
keycloak:
restart: always
Expand Down
2 changes: 1 addition & 1 deletion env/.env.int-example → env/.env.integ-example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# path to kubeconfig on host used for integration mode
export DEV_KUBECONFIG_PATH=
KUBECONFIG_HOST_PATH=$HOME/.kube/config
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"docker:dev:delete": "docker compose -f ./docker/docker-compose.dev.yml down -v",
"docker:e2e": "docker compose -f ./docker/docker-compose.dev.yml up -d; turbo run test:e2e --filter=client --color --no-daemon; docker compose -f ./docker/docker-compose.dev.yml down",
"docker:e2e-ci": "docker compose -f ./docker/docker-compose.prod.yml up -d; turbo run test:e2e-ci --filter=client --color --no-daemon; docker compose -f ./docker/docker-compose.prod.yml down",
"docker:integ": "docker compose --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml up -d; docker compose --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml watch --no-up & docker compose --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml logs server client -f",
"docker:integ": "docker compose --env-file env/.env.integ --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml up -d; docker compose --env-file env/.env.integ --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml watch --no-up & docker compose --env-file env/.env.integ --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml logs server client -f",
"docker:integ:build": "export $(cat apps/server/.env.integ | grep -v '#' | xargs) && export COMPOSE_FILE=./docker/docker-compose.integ.yml && cd $(dirname $COMPOSE_FILE) && docker buildx bake --file $(basename $COMPOSE_FILE) --load && cd - > /dev/null",
"docker:integ:clean": "docker compose --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml down",
"docker:integ:delete": "docker compose --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml down -v",
"docker:integ:clean": "docker compose --env-file env/.env.integ --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml down",
"docker:integ:delete": "docker compose --env-file env/.env.integ --env-file apps/server/.env.integ -f ./docker/docker-compose.integ.yml down -v",
"docker:prod": "docker compose -f ./docker/docker-compose.prod.yml up",
"docker:prod:build": "export COMPOSE_FILE=./docker/docker-compose.prod.yml && ./ci/kind/run-build.sh $COMPOSE_FILE",
"docker:prod:delete": "docker compose -f ./docker/docker-compose.prod.yml down -v",
Expand All @@ -35,8 +35,8 @@
"kube:dev": "pnpm kube:dev:build; pnpm kube:dev:run",
"kube:integ:build": "pnpm kube:dev:build",
"kube:integ:load": "pnpm kube:dev:load",
"kube:integ:run": "ci/kind/run.sh -c create,dev,int",
"kube:integ": "pnpm kube:int:build; pnpm kube:int:run",
"kube:integ:run": "ci/kind/run.sh -c create,dev,integ",
"kube:integ": "pnpm kube:integ:build; pnpm kube:integ:run",
"kube:prod:build": "ci/kind/run.sh -c create,build,load -f docker/docker-compose.prod.yml",
"kube:prod:load": "ci/kind/run.sh -c create,load -f docker/docker-compose.prod.yml",
"kube:prod:run": "ci/kind/run.sh -c create,prod",
Expand Down

0 comments on commit 4bedbaf

Please sign in to comment.