@colisweb/rescript-toolkit 5.10.0 → 5.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -250,11 +250,11 @@ entries:
250
250
  cronjob:
251
251
  EOT
252
252
 
253
- # helm3 stable repo have changed and must be updated manually, in versions < v2.17.0
254
- helm3 repo add colisweb s3://colisweb-helm-charts/colisweb --force-update
255
- helm3 repo add stable https://charts.helm.sh/stable --force-update
256
- helm3 repo update
257
- helm3 dependency update ${ROOT_PATH}/${CHART_PATH}
253
+ # helm stable repo have changed and must be updated manually, in versions < v2.17.0
254
+ helm repo add colisweb s3://colisweb-helm-charts/colisweb --force-update
255
+ helm repo add stable https://charts.helm.sh/stable --force-update
256
+ helm repo update
257
+ helm dependency update ${ROOT_PATH}/${CHART_PATH}
258
258
 
259
259
  # Gather values/*.yaml files
260
260
  VALUES_PATH="${ROOT_PATH}/${CHART_NAME}/values"
@@ -262,7 +262,7 @@ EOT
262
262
  [ -d $VALUES_PATH ] && VALUES_FILES=$(find $VALUES_PATH -type f -maxdepth 1 -name "*.yaml" | sed 's/^/ -f /' | tr -d \\n | sed 's/%//')
263
263
 
264
264
  # Deploy
265
- helm3 upgrade --install \
265
+ helm upgrade --install \
266
266
  --namespace ${ENVIRONMENT} \
267
267
  ${VALUES_FILES} \
268
268
  -f ${ROOT_PATH}/${CONFIG_PATH}/common.yaml \
@@ -272,7 +272,7 @@ EOT
272
272
  ${CHART_NAME} ${ROOT_PATH}/${CHART_PATH}
273
273
 
274
274
 
275
- verify_deployments_v3 -t 10m $ENVIRONMENT $CHART_NAME
275
+ verify_deployments -t 10m $ENVIRONMENT $CHART_NAME
276
276
 
277
277
  }
278
278
 
@@ -596,7 +596,7 @@ mysql_on_k8() {
596
596
  local query=$7
597
597
 
598
598
  kubectl -n ${namespace} run ${service}-mysql-init \
599
- --image widdpim/mysql-client \
599
+ --image arey/mysql-client \
600
600
  --restart=Never \
601
601
  --attach --rm \
602
602
  -- \
@@ -612,8 +612,6 @@ kube_init_database_once() {
612
612
  echo " Initializing Database '$db_database' for namespace $namespace"
613
613
  echo "======================="
614
614
 
615
- set -x
616
-
617
615
  echo "Checking if Database '$db_database' exists"
618
616
  set +e
619
617
  psql_on_k8 $namespace once "$db_init_username:$db_init_password@$db_host:$db_port" -lqtA | cut -d\| -f1 | grep "^$db_database$"
@@ -676,14 +674,14 @@ kube_init_datadog_in_database() {
676
674
  extract_args 8 namespace db_host db_port db_init_username db_init_password db_datadog_username db_datadog_password db_datadog_schema $*
677
675
 
678
676
  echo "======================="
679
- echo " Initializing Datadog Agent Requiement for namespace $namespace"
677
+ echo " Initializing Datadog Agent Requirement for namespace $namespace"
680
678
  echo "======================="
681
679
 
682
680
  echo "Checking if User '$db_datadog_username' exists"
683
681
  local service="datadog"
684
682
  found_db_users=$(mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'SELECT user FROM mysql.user;')
685
683
  set +e
686
- echo $found_db_users | grep "^$db_datadog_username$"
684
+ echo "$found_db_users" | grep "^$db_datadog_username$"
687
685
  return_code=$?
688
686
  set -e
689
687
 
@@ -843,8 +841,6 @@ kube_init_service_database() {
843
841
 
844
842
  local db_connection="$db_init_username:$db_init_password@$db_host:$db_port"
845
843
 
846
- set -x
847
-
848
844
  echo "Checking if Database '$db_database' exists"
849
845
  set +e
850
846
  psql_on_k8 $namespace $service $db_connection -lqtA | cut -d\| -f1 | grep "^$db_database$"
@@ -873,6 +869,57 @@ kube_init_service_database() {
873
869
 
874
870
  #!/usr/bin/env bash
875
871
 
872
+ # Allow to use JMX connection to retrieve data and metrics from the pods within kubernetes
873
+ # You will need visualVM to use this tool https://visualvm.github.io/
874
+ # ex: bind_jmx testing notification
875
+ bind_jmx() {
876
+
877
+ local ENV=$1
878
+ local SERVICE_NAME=$2
879
+ local PORT=2242
880
+
881
+ start_ssh_bastion $ENV $PORT
882
+
883
+ echo "root" | ssh -f -N -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -D 7777 root@127.0.0.1 -p 2242
884
+ local PODS=$(kubectl -n $ENV get pods -o wide | grep $SERVICE_NAME | grep -Eo '^[^ ]+')
885
+
886
+ echo "Choose one of the following pod to get metrics from..."
887
+ local POD_NAME=$(gum choose $PODS)
888
+ local POD_IP=$(
889
+ kubectl -n $ENV get pods -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.podIP}{"\n"}{end}' |
890
+ grep $POD_NAME |
891
+ cut -d' ' -f2 |
892
+ head -1
893
+ )
894
+
895
+ jconsole -J-DsocksProxyHost=localhost \
896
+ -J-DsocksProxyPort=7777 \
897
+ service:jmx:rmi:///jndi/rmi://$POD_IP:7199/jmxrmi \
898
+ -J-DsocksNonProxyHosts= &
899
+
900
+ cat << EOF
901
+ Now start VisualVM
902
+ Preferences > Network > Manual Proxy Settings
903
+ SOCKS Proxy Line: Set 'localhost' and Port '7777'
904
+ File > Add JMX Connection
905
+ Set $POD_IP:7199, check 'do not require an SSL connection'
906
+ Remember to kill you bastion afterward using 'stop_ssh_bastion'
907
+ EOF
908
+ }
909
+ #!/usr/bin/env bash
910
+
911
+ k8_nodes_stats() {
912
+ kubectl get nodes -o name |
913
+ xargs kubectl describe |
914
+ grep "^Name\|workType\|cpu \|memory " |
915
+ sed -r 's/[ :=]+/\t/g' |
916
+ sed 's/\tworkType\t//g' |
917
+ sed -r 's/^Name/---\nName/g' |
918
+ grep --color "Name\|web\|workers\|cpu\|memory\|---"
919
+ }
920
+
921
+ #!/usr/bin/env bash
922
+
876
923
  # Port forward on the first matching pod
877
924
  # Ex :
878
925
  # pod_forward testing notification-http
@@ -950,12 +997,58 @@ pick_pod() {
950
997
 
951
998
  #!/usr/bin/env bash
952
999
 
1000
+ bastion_config_for_redis_ca() {
1001
+ ssh_config xufte6.0001.euw1.cache.amazonaws.com redis 2223 63789 tests testing recette-001 sandbox prod > $1
1002
+ }
1003
+
1004
+ bastion_config_for_redis_toutatis() {
1005
+ ssh_config xufte6.0001.euw1.cache.amazonaws.com toutatis 2223 63789 tests testing recette staging production > $1
1006
+ }
1007
+
1008
+ ssh_config() {
1009
+ host=$1
1010
+ host_prefix=$2
1011
+ port0=$3
1012
+ forward0=$4
1013
+ shift 4
1014
+ instance_names=("$@") # /!\ indices start at 1 with zsh
1015
+ ssh_header
1016
+
1017
+ environments=(tests testing recette staging production)
1018
+
1019
+ length=${#environments[@]}
1020
+ for (( i=1; i<=${length}; i++ ));
1021
+ do
1022
+ bastion_block bastion_${environments[$i]} $(($port0 + $i)) $(($forward0 + $i)) ${host_prefix}-${instance_names[$i]}.$host
1023
+ done
1024
+ }
1025
+
1026
+ ssh_header() {
1027
+ cat <<EOF
1028
+ UserKnownHostsFile /dev/null
1029
+ StrictHostKeyChecking no
1030
+ User root
1031
+ EOF
1032
+ }
1033
+
1034
+ bastion_block() {
1035
+ cat <<EOF
1036
+ Host $1
1037
+ HostName 127.0.0.1
1038
+ Port $2
1039
+ LocalForward $3 $4:6379
1040
+ EOF
1041
+ }
1042
+
953
1043
  redis_k8s() {
954
1044
  MODE=$1
1045
+ REDIS_INSTANCE=${2:-ca}
955
1046
  case $MODE in
1047
+ "tests") SSH_LOCAL_PORT=2224;REDIS_LOCAL_PORT=63790;ENV="tests";;
956
1048
  "testing") SSH_LOCAL_PORT=2225;REDIS_LOCAL_PORT=63791;ENV="testing";;
957
- "staging") SSH_LOCAL_PORT=2226;REDIS_LOCAL_PORT=63792;ENV="staging";;
958
- "production") SSH_LOCAL_PORT=2227;REDIS_LOCAL_PORT=63793;ENV="production";;
1049
+ "recette") SSH_LOCAL_PORT=2226;REDIS_LOCAL_PORT=63792;ENV="recette";;
1050
+ "staging") SSH_LOCAL_PORT=2227;REDIS_LOCAL_PORT=63793;ENV="staging";;
1051
+ "production") SSH_LOCAL_PORT=2228;REDIS_LOCAL_PORT=63794;ENV="production";;
959
1052
  *) echo "Unsupported ENV : $MODE"; return 1 ;;
960
1053
  esac
961
1054
 
@@ -964,23 +1057,11 @@ redis_k8s() {
964
1057
  lsof -ti tcp:$REDIS_LOCAL_PORT | xargs kill
965
1058
 
966
1059
  bastion_config=$(mktemp)
967
- cat > "$bastion_config" <<EOF
968
- UserKnownHostsFile /dev/null
969
- StrictHostKeyChecking no
970
- User root
971
- Host bastion_testing
972
- HostName 127.0.0.1
973
- Port 2225
974
- LocalForward 63791 redis-testing.xufte6.0001.euw1.cache.amazonaws.com:6379
975
- Host bastion_staging
976
- HostName 127.0.0.1
977
- Port 2226
978
- LocalForward 63792 redis-sandbox.xufte6.0001.euw1.cache.amazonaws.com:6379
979
- Host bastion_production
980
- HostName 127.0.0.1
981
- Port 2227
982
- LocalForward 63793 redis-prod.xufte6.0001.euw1.cache.amazonaws.com:6379
983
- EOF
1060
+ case $REDIS_INSTANCE in
1061
+ "ca") bastion_config_for_redis_ca "$bastion_config";;
1062
+ "toutatis") bastion_config_for_redis_toutatis "$bastion_config";;
1063
+ *) echo "Unsupported redis instance (ca or toutatis available) : $REDIS_INSTANCE"; return 1;;
1064
+ esac
984
1065
 
985
1066
  ssh -f -N \
986
1067
  -F "$bastion_config" \
@@ -1823,11 +1904,11 @@ datadog_schedule_downtime_single() {
1823
1904
  {
1824
1905
  "active": true,
1825
1906
  "downtime_type": 0,
1826
- "start": $START,
1827
- "end": $END,
1828
- "message": "CA Deployment - performance for $SERVICE may be lower for next $DOWNTIME_MINUTES min",
1907
+ "start": '$START',
1908
+ "end": '$END',
1909
+ "message": "CA Deployment - performance for '$SERVICE' may be lower for next '$DOWNTIME_MINUTES' min",
1829
1910
  "monitor_tags": [
1830
- "service:$SERVICE",
1911
+ "service:'$SERVICE'",
1831
1912
  "performance"
1832
1913
  ],
1833
1914
  "scope": [
@@ -1837,11 +1918,13 @@ datadog_schedule_downtime_single() {
1837
1918
  }
1838
1919
  '
1839
1920
  }
1921
+
1840
1922
  #!/usr/bin/env bash
1841
1923
 
1842
1924
  docker_build_push() {
1843
1925
  read -r -a BUILD_ARGS <<< "$1"
1844
1926
  DOCKER_BUILD_ARGS="--build-arg VCS_REF=$(git rev-parse --short HEAD)"
1927
+
1845
1928
  for ARG_NAME in "${BUILD_ARGS[@]}"
1846
1929
  do
1847
1930
  DOCKER_BUILD_ARGS="$DOCKER_BUILD_ARGS --build-arg $ARG_NAME=${!ARG_NAME}"
@@ -1850,13 +1933,17 @@ docker_build_push() {
1850
1933
  if ! image_exists $DOCKER_REGISTRY_ID $APPLICATION $CI_COMMIT_SHORT_SHA ; then
1851
1934
  docker pull $DOCKER_IMAGE || true
1852
1935
  SOURCE_URL=${CI_PROJECT_URL:8} # without "https://" protocol, like gitlab.com/colisweb-idl/colisweb/back/packing
1853
- docker build $DOCKER_BUILD_ARGS \
1936
+
1937
+ docker buildx create --use
1938
+
1939
+ docker buildx build $DOCKER_BUILD_ARGS \
1854
1940
  -t $DOCKER_IMAGE_SHA \
1941
+ --platform "linux/arm64,linux/amd64" \
1855
1942
  --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
1856
1943
  --label org.opencontainers.image.source=$SOURCE_URL \
1857
- --cache-from $DOCKER_IMAGE \
1944
+ --provenance=false \
1945
+ --push \
1858
1946
  $DOCKER_STAGE_PATH
1859
- docker push $DOCKER_IMAGE_SHA
1860
1947
  fi
1861
1948
  }
1862
1949
 
@@ -1992,7 +2079,7 @@ init_migrate_db() {
1992
2079
 
1993
2080
  unset KUBECONFIG
1994
2081
 
1995
- configure_kubectl_for_ci ${ENVIRONMENT}
2082
+ configure_kubectl_for ${ENVIRONMENT}
1996
2083
 
1997
2084
  kube_init_service_database \
1998
2085
  --namespace ${ENVIRONMENT} \
@@ -2038,7 +2125,7 @@ flyway_migrate() {
2038
2125
  CONFIGMAP_NAME="$service-flyway-migration-sql"
2039
2126
  POD_NAME="$service-flyway-migration"
2040
2127
 
2041
- configure_kubectl_for_ci $environment
2128
+ configure_kubectl_for $environment
2042
2129
 
2043
2130
  kubectl -n $namespace delete configmap $CONFIGMAP_NAME --ignore-not-found
2044
2131
  kubectl -n $namespace delete pod $POD_NAME --ignore-not-found
@@ -2091,7 +2178,7 @@ flyway_migrate() {
2091
2178
 
2092
2179
  flyway_sql_folder=$(pwd)/${MIGRATION_SQL_PATH}
2093
2180
 
2094
- configure_kubectl_for_ci "${ENVIRONMENT}"
2181
+ configure_kubectl_for "${ENVIRONMENT}"
2095
2182
  POD_NAME="${APPLICATION}-flyway-repair"
2096
2183
  CONFIGMAP_NAME="${APPLICATION}-flyway-repair-sql"
2097
2184
 
@@ -2157,11 +2244,11 @@ git_reveal() {
2157
2244
  }
2158
2245
  #!/usr/bin/env bash
2159
2246
 
2160
- helm_deploy_v3() {
2247
+ helm_deploy() {
2161
2248
  APPLICATION=$1
2162
2249
  ENVIRONMENT=$2
2163
2250
  VERSION=$3
2164
- deploy_chart_v3 \
2251
+ deploy_chart \
2165
2252
  --path_configs deploy \
2166
2253
  --path_chart deploy/$APPLICATION \
2167
2254
  --application $APPLICATION \
@@ -2170,7 +2257,7 @@ helm_deploy_v3() {
2170
2257
  --helm_extra_args --set global.version=$VERSION
2171
2258
  }
2172
2259
 
2173
- deploy_chart_v3() {
2260
+ deploy_chart() {
2174
2261
  set -e
2175
2262
  set -x
2176
2263
 
@@ -2217,15 +2304,15 @@ deploy_chart_v3() {
2217
2304
  unset KUBECONFIG
2218
2305
 
2219
2306
  # Configure Kubectl
2220
- configure_kubectl_for_ci ${environment}
2307
+ configure_kubectl_for ${environment}
2221
2308
 
2222
- # Configure helm3
2223
- helm3 version --namespace ${namespace} || true
2224
- # helm3 stable repo have changed and must be updated manually, in versions < v2.17.0
2225
- helm3 repo add colisweb s3://colisweb-helm-charts/colisweb
2226
- helm3 repo add stable https://charts.helm.sh/stable
2227
- helm3 repo update
2228
- helm3 dependency update ${root_path}/${path_chart}
2309
+ # Configure helm
2310
+ helm version --namespace ${namespace} || true
2311
+ # helm stable repo have changed and must be updated manually, in versions < v2.17.0
2312
+ helm repo add colisweb s3://colisweb-helm-charts/colisweb
2313
+ helm repo add stable https://charts.helm.sh/stable
2314
+ helm repo update
2315
+ helm dependency update ${root_path}/${path_chart}
2229
2316
 
2230
2317
  # Gather values/*.yaml files
2231
2318
  values_path="${root_path}/${path_chart}/values"
@@ -2233,7 +2320,7 @@ deploy_chart_v3() {
2233
2320
  [ -d $values_path ] && values_files=$(find $values_path -type f -maxdepth 1 -name "*.yaml" | sed 's/^/ -f /' | tr -d \\n | sed 's/%//')
2234
2321
 
2235
2322
  # Deploy
2236
- helm3 upgrade --install \
2323
+ helm upgrade --install \
2237
2324
  --namespace ${namespace} \
2238
2325
  ${values_files} \
2239
2326
  -f ${root_path}/${path_configs}/common.yaml \
@@ -2255,7 +2342,7 @@ deploy_chart_v3() {
2255
2342
  set +x
2256
2343
  }
2257
2344
 
2258
- verify_deployments_v3() {
2345
+ verify_deployments() {
2259
2346
  set -e
2260
2347
 
2261
2348
  # usage :
@@ -2275,7 +2362,7 @@ verify_deployments_v3() {
2275
2362
 
2276
2363
  # Get all Deployments names from the deployed chart
2277
2364
  DEPLOYMENTS=(
2278
- $(helm3 get manifest --namespace $NAMESPACE $RELEASE | yq -rs '.[] | select(.kind=="Deployment") | .metadata.name')
2365
+ $(helm get manifest --namespace $NAMESPACE $RELEASE | yq --no-doc -r 'select(.kind=="Deployment").metadata.name')
2279
2366
  )
2280
2367
 
2281
2368
  echo "verifying on $NAMESPACE deployments ${DEPLOYMENTS[@]} with a timeout of $TIMEOUT"
@@ -2318,40 +2405,6 @@ check_config_file() {
2318
2405
  fi
2319
2406
  }
2320
2407
 
2321
- #!/usr/bin/env bash
2322
-
2323
- configure_kubectl_for_ci() {
2324
- if [ -z ${GITLAB_PAT} ]; then
2325
- echo "Cannot configure kubectl: no GITLAB_PAT configured"
2326
- exit 1
2327
- fi
2328
-
2329
- infra_env="$1"
2330
- valid_envs="[testing][staging][production][performance][tests][recette]"
2331
- echo "$valid_envs" | grep -q "\[$infra_env\]"
2332
-
2333
- if [ $? -ne 0 ]; then
2334
- echo "Cannot configure kubectl for invalid env : $infra_env"
2335
- echo "choose one of $valid_envs"
2336
- exit 1
2337
- fi
2338
-
2339
- mkdir -p ~/.kube
2340
- curl -fsS \
2341
- --header "PRIVATE-TOKEN: $GITLAB_PAT" \
2342
- "https://gitlab.com/api/v4/projects/8141053/jobs/artifacts/$infra_env/raw/$infra_env.kubeconfig?job=4_kubernetes_config_output" \
2343
- > ~/.kube/$infra_env.kubeconfig
2344
-
2345
- curl_return_code=$?
2346
- if [ ${curl_return_code} -ne 0 ]; then
2347
- echo "Cannot configure kubectl for $infra_env, get configuration failed with code $curl_return_code"
2348
- exit ${curl_return_code}
2349
- fi
2350
-
2351
- rm -f ~/.kube/config
2352
- ln -s ~/.kube/$infra_env.kubeconfig ~/.kube/config
2353
- echo "Configured kubectl for env : $infra_env"
2354
- }
2355
2408
  notify_new_deployment() {
2356
2409
  jq --version || (apt update && apt install -y jq)
2357
2410
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "5.10.0",
3
+ "version": "5.10.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -23,13 +23,18 @@ module Make = (StateLenses: Config) => {
23
23
 
24
24
  module RadioGroup = {
25
25
  @react.component
26
- let make = (~field, ~elements, ~inline=?) =>
26
+ let make = (~field, ~elements, ~variant=?, ~inline=?, ~containerClassName=?) =>
27
27
  <Field
28
28
  field
29
29
  render={({handleChange, error, value}) =>
30
30
  <React.Fragment>
31
31
  <Toolkit__Ui_RadioGroup
32
- defaultValue=value onChange={v => handleChange(v)} elements ?inline
32
+ ?containerClassName
33
+ ?variant
34
+ defaultValue=value
35
+ onChange={v => handleChange(v)}
36
+ elements
37
+ ?inline
33
38
  />
34
39
  <ErrorMessage ?error />
35
40
  </React.Fragment>}
@@ -7,7 +7,14 @@ type element = {
7
7
  }
8
8
 
9
9
  @react.component
10
- let make = (~onChange, ~elements: array<element>, ~defaultValue=?, ~inline=false) => {
10
+ let make = (
11
+ ~onChange,
12
+ ~elements: array<element>,
13
+ ~variant=?,
14
+ ~defaultValue=?,
15
+ ~containerClassName="",
16
+ ~inline=false,
17
+ ) => {
11
18
  let name = "radio-" ++ ReachUi_AutoId.use("")
12
19
  let (value, setValue) = React.useState(() => defaultValue->Option.getWithDefault(""))
13
20
 
@@ -16,10 +23,11 @@ let make = (~onChange, ~elements: array<element>, ~defaultValue=?, ~inline=false
16
23
  None
17
24
  }, [value])
18
25
 
19
- <div className={inline ? "flex gap-3" : ""}>
26
+ <div className={cx([inline ? "flex gap-3" : "", containerClassName])}>
20
27
  {elements
21
28
  ->Array.mapWithIndex((i, element) =>
22
29
  <Radio
30
+ ?variant
23
31
  key={"radio-" ++ string_of_int(i)}
24
32
  value=element.value
25
33
  name