@colisweb/rescript-toolkit 4.29.1 → 4.29.2

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.
@@ -129,6 +129,27 @@ delete_images_all_repos() {
129
129
  done <<< "$REPOSITORIES"
130
130
  }
131
131
 
132
+ delete_old_cache() {
133
+ DATE=${1:-$(date -v-1m +%F)}
134
+ CACHE_BUCKET=${2:-"s3://gitlab-colisweb-distributed-cache/project/"}
135
+
136
+ echo "deleting from cache $CACHE_BUCKET all older than $DATE"
137
+
138
+ aws_ecr_login
139
+
140
+ while read -r line; do
141
+ datum=$(echo $line | cut -c1-10)
142
+ if [[ "$datum" < "$DATE" ]] ; then
143
+ # Shell Parameter Expansion: ${parameter##word}
144
+ # Allow to return the result from "word" to the end of "parameters"
145
+ # Here we need the end of the string after "project/" (corresponding to the S3 gitlab project id and filename)
146
+ TO_DELETE="$CACHE_BUCKET${line##* project/}"
147
+ echo $TO_DELETE
148
+ aws s3 rm $TO_DELETE
149
+ fi
150
+ done < <(aws s3 ls $CACHE_BUCKET --recursive)
151
+ }
152
+
132
153
  #!/usr/bin/env bash
133
154
 
134
155
  # If gitlab is down or pipeline are stuck, hotfixes need to be available
@@ -514,28 +535,29 @@ database_k8s() {
514
535
  HostName 127.0.0.1
515
536
  Port 2225
516
537
  LocalForward 24441 toutatis-testing-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
517
- LocalForward 25431 testapirds.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
538
+ LocalForward 25431 toutatis-testing-mysql-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
539
+ LocalForward 25531 testapirds.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
518
540
  Host bastion_staging
519
541
  HostName 127.0.0.1
520
542
  Port 2226
521
543
  LocalForward 24442 toutatis-staging-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
522
- LocalForward 25432 testapirds.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
544
+ LocalForward 25432 toutatis-staging-mysql-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
523
545
  Host bastion_recette
524
546
  HostName 127.0.0.1
525
547
  Port 2228
526
548
  LocalForward 24446 toutatis-recette-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
527
- LocalForward 25436 testapirds.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
549
+ LocalForward 25436 toutatis-recette-mysql-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
550
+ LocalForward 25536 testapirds.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
528
551
  Host bastion_production
529
552
  HostName 127.0.0.1
530
553
  Port 2227
531
554
  LocalForward 24443 toutatis-production-db-replica.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
532
- LocalForward 25433 api-production-rds-read-replica.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
533
- LocalForward 25435 archive-ca.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
555
+ LocalForward 25433 toutatis-production-mysql-db-replica.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
534
556
  EOF
535
557
  if [ "$MODE" = "production_rw" ] ; then
536
558
  cat >> "$bastion_config" <<EOF
537
559
  LocalForward 24444 toutatis-production-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
538
- LocalForward 25434 api-production-rds.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
560
+ LocalForward 25434 toutatis-production-mysql-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
539
561
  EOF
540
562
  fi
541
563
 
@@ -555,7 +577,7 @@ psql_on_k8() {
555
577
  CONNECTION=$3
556
578
  shift 3
557
579
 
558
- kubectl -n $NAMESPACE run ${SERVICE}-database-init \
580
+ kubectl -n $NAMESPACE run ${SERVICE}-postgres-init \
559
581
  --image jbergknoff/postgresql-client \
560
582
  --restart=Never \
561
583
  --attach --rm \
@@ -566,14 +588,15 @@ psql_on_k8() {
566
588
 
567
589
  mysql_on_k8() {
568
590
  local namespace=$1
569
- local db_host=$2
570
- local db_port=$3
571
- local db_init_username=$4
572
- local db_init_password=$5
573
- local query=$6
574
-
575
- kubectl -n ${namespace} run datadog-database-init \
576
- --image widdpim/mysql-client \
591
+ local service=$2
592
+ local db_host=$3
593
+ local db_port=$4
594
+ local db_init_username=$5
595
+ local db_init_password=$6
596
+ local query=$7
597
+
598
+ kubectl -n ${namespace} run ${service}-mysql-init \
599
+ --image arey/mysql-client \
577
600
  --restart=Never \
578
601
  --attach --rm \
579
602
  -- \
@@ -653,14 +676,14 @@ kube_init_datadog_in_database() {
653
676
  extract_args 8 namespace db_host db_port db_init_username db_init_password db_datadog_username db_datadog_password db_datadog_schema $*
654
677
 
655
678
  echo "======================="
656
- echo " Initializing Datadog Agent Requiement for namespace $namespace"
679
+ echo " Initializing Datadog Agent Requirement for namespace $namespace"
657
680
  echo "======================="
658
681
 
659
- set -x
660
-
661
682
  echo "Checking if User '$db_datadog_username' exists"
683
+ local service="datadog"
684
+ found_db_users=$(mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'SELECT user FROM mysql.user;')
662
685
  set +e
663
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'SELECT user FROM mysql.user;' | grep "^$db_datadog_username$"
686
+ echo "$found_db_users" | grep "^$db_datadog_username$"
664
687
  return_code=$?
665
688
  set -e
666
689
 
@@ -671,29 +694,29 @@ kube_init_datadog_in_database() {
671
694
 
672
695
  # All the query come from this docs : https://docs.datadoghq.com/fr/database_monitoring/setup_mysql/selfhosted/?tab=mysql56
673
696
 
674
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'CREATE USER '"$db_datadog_username"'@"%" IDENTIFIED BY '"'$db_datadog_password'"';'
697
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'CREATE USER '"$db_datadog_username"'@"%" IDENTIFIED BY '"'$db_datadog_password'"';'
675
698
  echo "USER created $db_datadog_username"
676
699
 
677
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'GRANT REPLICATION CLIENT ON *.* TO datadog@"%" WITH MAX_USER_CONNECTIONS 5;'
700
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'GRANT REPLICATION CLIENT ON *.* TO datadog@"%" WITH MAX_USER_CONNECTIONS 5;'
678
701
  echo "ALTER USER $db_datadog_username"
679
702
 
680
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'GRANT PROCESS ON *.* TO '"$db_datadog_username"'@"%";'
703
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'GRANT PROCESS ON *.* TO '"$db_datadog_username"'@"%";'
681
704
  echo "Granted PROCESS for $db_datadog_username"
682
705
 
683
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'GRANT SELECT ON performance_schema.* TO '"$db_datadog_username"'@"%";'
706
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'GRANT SELECT ON performance_schema.* TO '"$db_datadog_username"'@"%";'
684
707
  echo "Granted SELECT on performance_schema for $db_datadog_username"
685
708
 
686
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'CREATE SCHEMA IF NOT EXISTS datadog;'
709
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'CREATE SCHEMA IF NOT EXISTS datadog;'
687
710
  echo "CREATE SCHEMA datadog"
688
711
 
689
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'GRANT EXECUTE ON datadog.* to '"$db_datadog_username"'@"%";'
712
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'GRANT EXECUTE ON datadog.* to '"$db_datadog_username"'@"%";'
690
713
  echo "Granted 'GRANT EXECUTE for $db_datadog_username on datadog"
691
714
 
692
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'GRANT CREATE TEMPORARY TABLES ON datadog.* TO '"$db_datadog_username"'@"%";'
715
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'GRANT CREATE TEMPORARY TABLES ON datadog.* TO '"$db_datadog_username"'@"%";'
693
716
  echo "Granted CREATE TEMPORARY TABLES for $db_datadog_username"
694
717
 
695
718
 
696
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'DROP PROCEDURE IF EXISTS datadog.explain_statement;
719
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'DROP PROCEDURE IF EXISTS datadog.explain_statement;
697
720
  DELIMITER $$
698
721
  CREATE PROCEDURE datadog.explain_statement(IN query TEXT)
699
722
  SQL SECURITY DEFINER
@@ -706,7 +729,7 @@ kube_init_datadog_in_database() {
706
729
  DELIMITER ;'
707
730
  echo "CREATE PROCEDURE PROCEDURE datadog.explain_statement"
708
731
 
709
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'DROP PROCEDURE IF EXISTS '"$db_datadog_username"'.explain_statement;
732
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'DROP PROCEDURE IF EXISTS '"$db_datadog_username"'.explain_statement;
710
733
  DELIMITER $$
711
734
  CREATE PROCEDURE '"$db_datadog_username"'.explain_statement(IN query TEXT)
712
735
  SQL SECURITY DEFINER
@@ -720,7 +743,7 @@ kube_init_datadog_in_database() {
720
743
  GRANT EXECUTE ON PROCEDURE '"$db_datadog_username"'.explain_statement TO datadog@"%";'
721
744
  echo "CREATE PROCEDURE on SCHEMA $db_datadog_schema for $db_datadog_username"
722
745
 
723
- mysql_on_k8 $namespace $db_host $db_port $db_init_username $db_init_password 'DROP PROCEDURE IF EXISTS datadog.enable_events_statements_consumers;
746
+ mysql_on_k8 $namespace $service $db_host $db_port $db_init_username $db_init_password 'DROP PROCEDURE IF EXISTS datadog.enable_events_statements_consumers;
724
747
  DELIMITER $$
725
748
  CREATE PROCEDURE datadog.enable_events_statements_consumers()
726
749
  SQL SECURITY DEFINER
@@ -798,7 +821,7 @@ kube_init_datadog_in_postgres_database() {
798
821
  RETURNS NULL ON NULL INPUT
799
822
  SECURITY DEFINER;"
800
823
 
801
- kubectl -n $namespace run $service-database-init \
824
+ kubectl -n $namespace run $service-postgres-init \
802
825
  --image jbergknoff/postgresql-client \
803
826
  --restart=Never \
804
827
  --attach --rm \
@@ -836,17 +859,69 @@ kube_init_service_database() {
836
859
  psql_on_k8 $namespace $service $db_connection -c 'CREATE DATABASE '"$db_database"';'
837
860
  echo "DB created $db_database"
838
861
 
839
- psql_on_k8 $namespace $service $db_connection -c 'CREATE USER '"$db_datadog_username"' WITH ENCRYPTED PASSWORD '"'$db_password'"';'
840
- echo "USER created $db_datadog_username"
862
+ psql_on_k8 $namespace $service $db_connection -c 'CREATE USER '"$db_username"' WITH ENCRYPTED PASSWORD '"'$db_password'"';'
863
+ echo "USER created $db_username"
841
864
 
842
- psql_on_k8 $namespace $service $db_connection -c 'GRANT ALL PRIVILEGES ON DATABASE '"$db_database"' TO '"$db_datadog_username"';'
843
- echo "Granted all privileges for $db_datadog_username on $db_database"
865
+ psql_on_k8 $namespace $service $db_connection -c 'GRANT ALL PRIVILEGES ON DATABASE '"$db_database"' TO '"$db_username"';'
866
+ echo "Granted all privileges for $db_username on $db_database"
844
867
  fi
845
868
 
846
869
  echo "======================="
847
- echo " Database '$db_database' Initialization complete for namespace $namespace"
870
+ echo " Database '$db_database' Initialization complete for namespace $namespace"
848
871
  echo "======================="
849
872
  }
873
+
874
+ #!/usr/bin/env bash
875
+
876
+ # Allow to use JMX connection to retrieve data and metrics from the pods within kubernetes
877
+ # You will need visualVM to use this tool https://visualvm.github.io/
878
+ # ex: bind_jmx testing notification
879
+ bind_jmx() {
880
+
881
+ local ENV=$1
882
+ local SERVICE_NAME=$2
883
+ local PORT=2242
884
+
885
+ start_ssh_bastion $ENV $PORT
886
+
887
+ echo "root" | ssh -f -N -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -D 7777 root@127.0.0.1 -p 2242
888
+ local PODS=$(kubectl -n $ENV get pods -o wide | grep $SERVICE_NAME | grep -Eo '^[^ ]+')
889
+
890
+ echo "Choose one of the following pod to get metrics from..."
891
+ local POD_NAME=$(gum choose $PODS)
892
+ local POD_IP=$(
893
+ kubectl -n $ENV get pods -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.podIP}{"\n"}{end}' |
894
+ grep $POD_NAME |
895
+ cut -d' ' -f2 |
896
+ head -1
897
+ )
898
+
899
+ jconsole -J-DsocksProxyHost=localhost \
900
+ -J-DsocksProxyPort=7777 \
901
+ service:jmx:rmi:///jndi/rmi://$POD_IP:7199/jmxrmi \
902
+ -J-DsocksNonProxyHosts= &
903
+
904
+ cat << EOF
905
+ Now start VisualVM
906
+ Preferences > Network > Manual Proxy Settings
907
+ SOCKS Proxy Line: Set 'localhost' and Port '7777'
908
+ File > Add JMX Connection
909
+ Set $POD_IP:7199, check 'do not require an SSL connection'
910
+ Remember to kill you bastion afterward using 'stop_ssh_bastion'
911
+ EOF
912
+ }
913
+ #!/usr/bin/env bash
914
+
915
+ k8_nodes_stats() {
916
+ kubectl get nodes -o name |
917
+ xargs kubectl describe |
918
+ grep "^Name\|workType\|cpu \|memory " |
919
+ sed -r 's/[ :=]+/\t/g' |
920
+ sed 's/\tworkType\t//g' |
921
+ sed -r 's/^Name/---\nName/g' |
922
+ grep --color "Name\|web\|workers\|cpu\|memory\|---"
923
+ }
924
+
850
925
  #!/usr/bin/env bash
851
926
 
852
927
  # Port forward on the first matching pod
@@ -926,12 +1001,58 @@ pick_pod() {
926
1001
 
927
1002
  #!/usr/bin/env bash
928
1003
 
1004
+ bastion_config_for_redis_ca() {
1005
+ ssh_config xufte6.0001.euw1.cache.amazonaws.com redis 2223 63789 tests testing recette-001 sandbox prod > $1
1006
+ }
1007
+
1008
+ bastion_config_for_redis_toutatis() {
1009
+ ssh_config xufte6.0001.euw1.cache.amazonaws.com toutatis 2223 63789 tests testing recette staging production > $1
1010
+ }
1011
+
1012
+ ssh_config() {
1013
+ host=$1
1014
+ host_prefix=$2
1015
+ port0=$3
1016
+ forward0=$4
1017
+ shift 4
1018
+ instance_names=("$@") # /!\ indices start at 1 with zsh
1019
+ ssh_header
1020
+
1021
+ environments=(tests testing recette staging production)
1022
+
1023
+ length=${#environments[@]}
1024
+ for (( i=1; i<=${length}; i++ ));
1025
+ do
1026
+ bastion_block bastion_${environments[$i]} $(($port0 + $i)) $(($forward0 + $i)) ${host_prefix}-${instance_names[$i]}.$host
1027
+ done
1028
+ }
1029
+
1030
+ ssh_header() {
1031
+ cat <<EOF
1032
+ UserKnownHostsFile /dev/null
1033
+ StrictHostKeyChecking no
1034
+ User root
1035
+ EOF
1036
+ }
1037
+
1038
+ bastion_block() {
1039
+ cat <<EOF
1040
+ Host $1
1041
+ HostName 127.0.0.1
1042
+ Port $2
1043
+ LocalForward $3 $4:6379
1044
+ EOF
1045
+ }
1046
+
929
1047
  redis_k8s() {
930
1048
  MODE=$1
1049
+ REDIS_INSTANCE=${2:-ca}
931
1050
  case $MODE in
1051
+ "tests") SSH_LOCAL_PORT=2224;REDIS_LOCAL_PORT=63790;ENV="tests";;
932
1052
  "testing") SSH_LOCAL_PORT=2225;REDIS_LOCAL_PORT=63791;ENV="testing";;
933
- "staging") SSH_LOCAL_PORT=2226;REDIS_LOCAL_PORT=63792;ENV="staging";;
934
- "production") SSH_LOCAL_PORT=2227;REDIS_LOCAL_PORT=63793;ENV="production";;
1053
+ "recette") SSH_LOCAL_PORT=2226;REDIS_LOCAL_PORT=63792;ENV="recette";;
1054
+ "staging") SSH_LOCAL_PORT=2227;REDIS_LOCAL_PORT=63793;ENV="staging";;
1055
+ "production") SSH_LOCAL_PORT=2228;REDIS_LOCAL_PORT=63794;ENV="production";;
935
1056
  *) echo "Unsupported ENV : $MODE"; return 1 ;;
936
1057
  esac
937
1058
 
@@ -940,23 +1061,11 @@ redis_k8s() {
940
1061
  lsof -ti tcp:$REDIS_LOCAL_PORT | xargs kill
941
1062
 
942
1063
  bastion_config=$(mktemp)
943
- cat > "$bastion_config" <<EOF
944
- UserKnownHostsFile /dev/null
945
- StrictHostKeyChecking no
946
- User root
947
- Host bastion_testing
948
- HostName 127.0.0.1
949
- Port 2225
950
- LocalForward 63791 redis-testing.xufte6.0001.euw1.cache.amazonaws.com:6379
951
- Host bastion_staging
952
- HostName 127.0.0.1
953
- Port 2226
954
- LocalForward 63792 redis-sandbox.xufte6.0001.euw1.cache.amazonaws.com:6379
955
- Host bastion_production
956
- HostName 127.0.0.1
957
- Port 2227
958
- LocalForward 63793 redis-prod.xufte6.0001.euw1.cache.amazonaws.com:6379
959
- EOF
1064
+ case $REDIS_INSTANCE in
1065
+ "ca") bastion_config_for_redis_ca "$bastion_config";;
1066
+ "toutatis") bastion_config_for_redis_toutatis "$bastion_config";;
1067
+ *) echo "Unsupported redis instance (ca or toutatis available) : $REDIS_INSTANCE"; return 1;;
1068
+ esac
960
1069
 
961
1070
  ssh -f -N \
962
1071
  -F "$bastion_config" \
@@ -1498,24 +1607,13 @@ jconsole_k8s() {
1498
1607
 
1499
1608
  #!/usr/bin/env bash
1500
1609
 
1501
- # Interactive console on an existing pod. See also run_ruby_k8s
1502
- # Ex :
1503
- # railsc_k8s_old production
1504
- # railsc_k8s_old production "User.where(email:'toni@colisweb.com')"
1505
- railsc_k8s_old() {
1506
- ENV=$1
1507
- COMMAND=$2
1508
- configure_kubectl_for $ENV
1509
- POD=$(kubectl -n $ENV get pods -o=name | grep colisweb-api-web | head -1 | sed -e 's/pod\///')
1510
- KUBERAILS="kubectl -n $ENV exec -ti $POD -- /usr/src/app/bin/rails c"
1511
- [ -z "$COMMAND" ] && eval $KUBERAILS || echo $COMMAND | eval $KUBERAILS
1512
- }
1513
-
1514
1610
  # Interactive console on an new pod. See also run_ruby_k8s
1515
1611
  # Ex :
1516
1612
  # railsc_k8s production
1613
+ # railsc_k8s production "User.where(email:'toni@colisweb.com')"
1517
1614
  railsc_k8s() {
1518
1615
  ENV=$1
1616
+ COMMAND=$2
1519
1617
  [[ $ENV = "production" || $ENV = "staging" ]] && default_tag="master-latest" || default_tag="${ENV}-latest"
1520
1618
  local image_tag=${5:-$default_tag}
1521
1619
  local IMAGE="949316342391.dkr.ecr.eu-west-1.amazonaws.com/colisweb-api:$image_tag"
@@ -1565,7 +1663,8 @@ railsc_k8s() {
1565
1663
  '
1566
1664
 
1567
1665
  sleep 5
1568
- kubectl -n $ENV exec -it $POD_NAME -- /usr/src/app/bin/rails c
1666
+ KUBERAILS="kubectl -n $ENV exec -ti $POD_NAME -- /usr/src/app/bin/rails c"
1667
+ [ -z "$COMMAND" ] && eval $KUBERAILS || echo $COMMAND | eval $KUBERAILS
1569
1668
 
1570
1669
  print "End of $POD_NAME "
1571
1670
  kubectl -n $ENV delete pods $POD_NAME
@@ -1809,11 +1908,11 @@ datadog_schedule_downtime_single() {
1809
1908
  {
1810
1909
  "active": true,
1811
1910
  "downtime_type": 0,
1812
- "start": $START,
1813
- "end": $END,
1814
- "message": "CA Deployment - performance for $SERVICE may be lower for next $DOWNTIME_MINUTES min",
1911
+ "start": '$START',
1912
+ "end": '$END',
1913
+ "message": "CA Deployment - performance for '$SERVICE' may be lower for next '$DOWNTIME_MINUTES' min",
1815
1914
  "monitor_tags": [
1816
- "service:$SERVICE",
1915
+ "service:'$SERVICE'",
1817
1916
  "performance"
1818
1917
  ],
1819
1918
  "scope": [
@@ -1823,6 +1922,7 @@ datadog_schedule_downtime_single() {
1823
1922
  }
1824
1923
  '
1825
1924
  }
1925
+
1826
1926
  #!/usr/bin/env bash
1827
1927
 
1828
1928
  docker_build_push() {
@@ -1835,11 +1935,18 @@ docker_build_push() {
1835
1935
 
1836
1936
  if ! image_exists $DOCKER_REGISTRY_ID $APPLICATION $CI_COMMIT_SHORT_SHA ; then
1837
1937
  docker pull $DOCKER_IMAGE || true
1838
- docker build $DOCKER_BUILD_ARGS -t $DOCKER_IMAGE_SHA --cache-from $DOCKER_IMAGE $DOCKER_STAGE_PATH
1938
+ SOURCE_URL=${CI_PROJECT_URL:8} # without "https://" protocol, like gitlab.com/colisweb-idl/colisweb/back/packing
1939
+ docker build $DOCKER_BUILD_ARGS \
1940
+ -t $DOCKER_IMAGE_SHA \
1941
+ --label org.opencontainers.image.revision=$(git rev-parse HEAD) \
1942
+ --label org.opencontainers.image.source=$SOURCE_URL \
1943
+ --cache-from $DOCKER_IMAGE \
1944
+ $DOCKER_STAGE_PATH
1839
1945
  docker push $DOCKER_IMAGE_SHA
1840
1946
  fi
1841
1947
  }
1842
1948
 
1949
+
1843
1950
  docker_promote() {
1844
1951
  # inspired by https://dille.name/blog/2018/09/20/how-to-tag-docker-images-without-pulling-them/
1845
1952
  OLD_TAG=${1//[^0-9a-zA-Z-.]/_}
@@ -1866,6 +1973,7 @@ docker_promote() {
1866
1973
  image_exists ${DOCKER_REGISTRY_ID} ${IMAGE_TO_CHECK} ${VERSION} || return 1
1867
1974
  done
1868
1975
  }
1976
+
1869
1977
  #!/usr/bin/env bash
1870
1978
 
1871
1979
  extract_yaml_config_variable() {
@@ -1942,7 +2050,7 @@ flyway_clean() {
1942
2050
 
1943
2051
  #!/usr/bin/env bash
1944
2052
 
1945
- FLYWAY_VERSION="5.2.4"
2053
+ FLYWAY_VERSION="7.4.0"
1946
2054
 
1947
2055
 
1948
2056
  get_yaml_variable() {
@@ -2028,7 +2136,7 @@ flyway_migrate() {
2028
2136
  "containers":[
2029
2137
  {
2030
2138
  "name":"'$POD_NAME'",
2031
- "image":"boxfuse/flyway:'$flyway_version'",
2139
+ "image":"flyway/flyway:'$flyway_version'",
2032
2140
  "command":["flyway", "-url='$db_url'", "-user='$db_user'", "-password='$db_password'", "migrate"],
2033
2141
  "volumeMounts":[
2034
2142
  {
@@ -2053,6 +2161,63 @@ flyway_migrate() {
2053
2161
  kubectl -n $namespace delete configmap $CONFIGMAP_NAME
2054
2162
  }
2055
2163
 
2164
+ #!/usr/bin/env bash
2165
+ flyway_repair() {
2166
+ set -e
2167
+ check_env_vars 4 "APPLICATION" "ENVIRONMENT" "FLYWAY_VERSION" "MIGRATION_SQL_PATH"
2168
+
2169
+ PG_YAML_PATH=".${APPLICATION}config.postgres"
2170
+
2171
+ DB_PORT="5432"
2172
+ DB_HOST=$(get_yaml_variable "${PG_YAML_PATH}.host")
2173
+ DB_DATABASE=$(get_yaml_variable "${PG_YAML_PATH}.database")
2174
+ DB_USER=$(get_yaml_variable "${PG_YAML_PATH}.user")
2175
+ DB_PASSWORD=$(get_yaml_variable "${PG_YAML_PATH}.password")
2176
+ DB_URL="jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_DATABASE}"
2177
+
2178
+ flyway_sql_folder=$(pwd)/${MIGRATION_SQL_PATH}
2179
+
2180
+ configure_kubectl_for_ci "${ENVIRONMENT}"
2181
+ POD_NAME="${APPLICATION}-flyway-repair"
2182
+ CONFIGMAP_NAME="${APPLICATION}-flyway-repair-sql"
2183
+
2184
+ kubectl -n "${ENVIRONMENT}" delete configmap $CONFIGMAP_NAME --ignore-not-found
2185
+ kubectl -n "${ENVIRONMENT}" delete pod $POD_NAME --ignore-not-found
2186
+ kubectl -n "${ENVIRONMENT}" create configmap $CONFIGMAP_NAME --from-file="${flyway_sql_folder}"
2187
+
2188
+ kubectl -n "${ENVIRONMENT}" run --rm -it "${POD_NAME}" \
2189
+ --image=flyway/flyway \
2190
+ --restart=Never \
2191
+ --overrides='
2192
+ {
2193
+ "spec":{
2194
+ "containers":[
2195
+ {
2196
+ "name":"'$POD_NAME'",
2197
+ "image":"flyway/flyway:'${FLYWAY_VERSION}'",
2198
+ "command":["flyway", "-url='$DB_URL'", "-user='$DB_USER'", "-password='$DB_PASSWORD'", "repair"],
2199
+ "volumeMounts":[
2200
+ {
2201
+ "name":"sql",
2202
+ "mountPath":"/flyway/sql"
2203
+ }
2204
+ ]
2205
+ }
2206
+ ],
2207
+ "volumes":[
2208
+ {
2209
+ "name":"sql",
2210
+ "configMap":{
2211
+ "name":"'$CONFIGMAP_NAME'"
2212
+ }
2213
+ }
2214
+ ]
2215
+ }
2216
+ }
2217
+ '
2218
+ kubectl -n "${ENVIRONMENT}" delete configmap $CONFIGMAP_NAME
2219
+ }
2220
+
2056
2221
  #!/usr/bin/env bash
2057
2222
 
2058
2223
  record_git_commit() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "4.29.1",
3
+ "version": "4.29.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -152,6 +152,8 @@ module FormData = {
152
152
  @new external create: unit => t = "FormData"
153
153
 
154
154
  @send external append: (t, string, 'a) => unit = "append"
155
+ // append(formData, fieldName(string), file, fileName(string))
156
+ @send external appendWithFileName: (t, string, 'a, string) => unit = "append"
155
157
  @send external get: (t, string) => Js.Nullable.t<'a> = "get"
156
158
  @send external getAll: (t, string) => Js.Nullable.t<array<'a>> = "getAll"
157
159
  @send external has: (t, string) => bool = "has"