@colisweb/rescript-toolkit 5.5.0 → 5.5.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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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}-
|
|
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
|
|
570
|
-
local
|
|
571
|
-
local
|
|
572
|
-
local
|
|
573
|
-
local
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
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,12 +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
|
|
679
|
+
echo " Initializing Datadog Agent Requirement for namespace $namespace"
|
|
657
680
|
echo "======================="
|
|
658
681
|
|
|
659
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;')
|
|
660
685
|
set +e
|
|
661
|
-
|
|
686
|
+
echo "$found_db_users" | grep "^$db_datadog_username$"
|
|
662
687
|
return_code=$?
|
|
663
688
|
set -e
|
|
664
689
|
|
|
@@ -669,29 +694,29 @@ kube_init_datadog_in_database() {
|
|
|
669
694
|
|
|
670
695
|
# All the query come from this docs : https://docs.datadoghq.com/fr/database_monitoring/setup_mysql/selfhosted/?tab=mysql56
|
|
671
696
|
|
|
672
|
-
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'"';'
|
|
673
698
|
echo "USER created $db_datadog_username"
|
|
674
699
|
|
|
675
|
-
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;'
|
|
676
701
|
echo "ALTER USER $db_datadog_username"
|
|
677
702
|
|
|
678
|
-
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"'@"%";'
|
|
679
704
|
echo "Granted PROCESS for $db_datadog_username"
|
|
680
705
|
|
|
681
|
-
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"'@"%";'
|
|
682
707
|
echo "Granted SELECT on performance_schema for $db_datadog_username"
|
|
683
708
|
|
|
684
|
-
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;'
|
|
685
710
|
echo "CREATE SCHEMA datadog"
|
|
686
711
|
|
|
687
|
-
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"'@"%";'
|
|
688
713
|
echo "Granted 'GRANT EXECUTE for $db_datadog_username on datadog"
|
|
689
714
|
|
|
690
|
-
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"'@"%";'
|
|
691
716
|
echo "Granted CREATE TEMPORARY TABLES for $db_datadog_username"
|
|
692
717
|
|
|
693
718
|
|
|
694
|
-
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;
|
|
695
720
|
DELIMITER $$
|
|
696
721
|
CREATE PROCEDURE datadog.explain_statement(IN query TEXT)
|
|
697
722
|
SQL SECURITY DEFINER
|
|
@@ -704,7 +729,7 @@ kube_init_datadog_in_database() {
|
|
|
704
729
|
DELIMITER ;'
|
|
705
730
|
echo "CREATE PROCEDURE PROCEDURE datadog.explain_statement"
|
|
706
731
|
|
|
707
|
-
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;
|
|
708
733
|
DELIMITER $$
|
|
709
734
|
CREATE PROCEDURE '"$db_datadog_username"'.explain_statement(IN query TEXT)
|
|
710
735
|
SQL SECURITY DEFINER
|
|
@@ -718,7 +743,7 @@ kube_init_datadog_in_database() {
|
|
|
718
743
|
GRANT EXECUTE ON PROCEDURE '"$db_datadog_username"'.explain_statement TO datadog@"%";'
|
|
719
744
|
echo "CREATE PROCEDURE on SCHEMA $db_datadog_schema for $db_datadog_username"
|
|
720
745
|
|
|
721
|
-
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;
|
|
722
747
|
DELIMITER $$
|
|
723
748
|
CREATE PROCEDURE datadog.enable_events_statements_consumers()
|
|
724
749
|
SQL SECURITY DEFINER
|
|
@@ -796,7 +821,7 @@ kube_init_datadog_in_postgres_database() {
|
|
|
796
821
|
RETURNS NULL ON NULL INPUT
|
|
797
822
|
SECURITY DEFINER;"
|
|
798
823
|
|
|
799
|
-
kubectl -n $namespace run $service-
|
|
824
|
+
kubectl -n $namespace run $service-postgres-init \
|
|
800
825
|
--image jbergknoff/postgresql-client \
|
|
801
826
|
--restart=Never \
|
|
802
827
|
--attach --rm \
|
|
@@ -834,17 +859,69 @@ kube_init_service_database() {
|
|
|
834
859
|
psql_on_k8 $namespace $service $db_connection -c 'CREATE DATABASE '"$db_database"';'
|
|
835
860
|
echo "DB created $db_database"
|
|
836
861
|
|
|
837
|
-
psql_on_k8 $namespace $service $db_connection -c 'CREATE USER '"$
|
|
838
|
-
echo "USER created $
|
|
862
|
+
psql_on_k8 $namespace $service $db_connection -c 'CREATE USER '"$db_username"' WITH ENCRYPTED PASSWORD '"'$db_password'"';'
|
|
863
|
+
echo "USER created $db_username"
|
|
839
864
|
|
|
840
|
-
psql_on_k8 $namespace $service $db_connection -c 'GRANT ALL PRIVILEGES ON DATABASE '"$db_database"' TO '"$
|
|
841
|
-
echo "Granted all privileges for $
|
|
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"
|
|
842
867
|
fi
|
|
843
868
|
|
|
844
869
|
echo "======================="
|
|
845
|
-
echo " Database '$db_database' Initialization complete for
|
|
870
|
+
echo " Database '$db_database' Initialization complete for namespace $namespace"
|
|
846
871
|
echo "======================="
|
|
847
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
|
+
|
|
848
925
|
#!/usr/bin/env bash
|
|
849
926
|
|
|
850
927
|
# Port forward on the first matching pod
|
|
@@ -924,12 +1001,58 @@ pick_pod() {
|
|
|
924
1001
|
|
|
925
1002
|
#!/usr/bin/env bash
|
|
926
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
|
+
|
|
927
1047
|
redis_k8s() {
|
|
928
1048
|
MODE=$1
|
|
1049
|
+
REDIS_INSTANCE=${2:-ca}
|
|
929
1050
|
case $MODE in
|
|
1051
|
+
"tests") SSH_LOCAL_PORT=2224;REDIS_LOCAL_PORT=63790;ENV="tests";;
|
|
930
1052
|
"testing") SSH_LOCAL_PORT=2225;REDIS_LOCAL_PORT=63791;ENV="testing";;
|
|
931
|
-
"
|
|
932
|
-
"
|
|
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";;
|
|
933
1056
|
*) echo "Unsupported ENV : $MODE"; return 1 ;;
|
|
934
1057
|
esac
|
|
935
1058
|
|
|
@@ -938,23 +1061,11 @@ redis_k8s() {
|
|
|
938
1061
|
lsof -ti tcp:$REDIS_LOCAL_PORT | xargs kill
|
|
939
1062
|
|
|
940
1063
|
bastion_config=$(mktemp)
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
HostName 127.0.0.1
|
|
947
|
-
Port 2225
|
|
948
|
-
LocalForward 63791 redis-testing.xufte6.0001.euw1.cache.amazonaws.com:6379
|
|
949
|
-
Host bastion_staging
|
|
950
|
-
HostName 127.0.0.1
|
|
951
|
-
Port 2226
|
|
952
|
-
LocalForward 63792 redis-sandbox.xufte6.0001.euw1.cache.amazonaws.com:6379
|
|
953
|
-
Host bastion_production
|
|
954
|
-
HostName 127.0.0.1
|
|
955
|
-
Port 2227
|
|
956
|
-
LocalForward 63793 redis-prod.xufte6.0001.euw1.cache.amazonaws.com:6379
|
|
957
|
-
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
|
|
958
1069
|
|
|
959
1070
|
ssh -f -N \
|
|
960
1071
|
-F "$bastion_config" \
|
|
@@ -1496,24 +1607,13 @@ jconsole_k8s() {
|
|
|
1496
1607
|
|
|
1497
1608
|
#!/usr/bin/env bash
|
|
1498
1609
|
|
|
1499
|
-
# Interactive console on an existing pod. See also run_ruby_k8s
|
|
1500
|
-
# Ex :
|
|
1501
|
-
# railsc_k8s_old production
|
|
1502
|
-
# railsc_k8s_old production "User.where(email:'toni@colisweb.com')"
|
|
1503
|
-
railsc_k8s_old() {
|
|
1504
|
-
ENV=$1
|
|
1505
|
-
COMMAND=$2
|
|
1506
|
-
configure_kubectl_for $ENV
|
|
1507
|
-
POD=$(kubectl -n $ENV get pods -o=name | grep colisweb-api-web | head -1 | sed -e 's/pod\///')
|
|
1508
|
-
KUBERAILS="kubectl -n $ENV exec -ti $POD -- /usr/src/app/bin/rails c"
|
|
1509
|
-
[ -z "$COMMAND" ] && eval $KUBERAILS || echo $COMMAND | eval $KUBERAILS
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
1610
|
# Interactive console on an new pod. See also run_ruby_k8s
|
|
1513
1611
|
# Ex :
|
|
1514
1612
|
# railsc_k8s production
|
|
1613
|
+
# railsc_k8s production "User.where(email:'toni@colisweb.com')"
|
|
1515
1614
|
railsc_k8s() {
|
|
1516
1615
|
ENV=$1
|
|
1616
|
+
COMMAND=$2
|
|
1517
1617
|
[[ $ENV = "production" || $ENV = "staging" ]] && default_tag="master-latest" || default_tag="${ENV}-latest"
|
|
1518
1618
|
local image_tag=${5:-$default_tag}
|
|
1519
1619
|
local IMAGE="949316342391.dkr.ecr.eu-west-1.amazonaws.com/colisweb-api:$image_tag"
|
|
@@ -1563,7 +1663,8 @@ railsc_k8s() {
|
|
|
1563
1663
|
'
|
|
1564
1664
|
|
|
1565
1665
|
sleep 5
|
|
1566
|
-
kubectl -n $ENV exec -
|
|
1666
|
+
KUBERAILS="kubectl -n $ENV exec -ti $POD_NAME -- /usr/src/app/bin/rails c"
|
|
1667
|
+
[ -z "$COMMAND" ] && eval $KUBERAILS || echo $COMMAND | eval $KUBERAILS
|
|
1567
1668
|
|
|
1568
1669
|
print "End of $POD_NAME "
|
|
1569
1670
|
kubectl -n $ENV delete pods $POD_NAME
|
|
@@ -1807,11 +1908,11 @@ datadog_schedule_downtime_single() {
|
|
|
1807
1908
|
{
|
|
1808
1909
|
"active": true,
|
|
1809
1910
|
"downtime_type": 0,
|
|
1810
|
-
"start": $START,
|
|
1811
|
-
"end": $END,
|
|
1812
|
-
"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",
|
|
1813
1914
|
"monitor_tags": [
|
|
1814
|
-
"service
|
|
1915
|
+
"service:'$SERVICE'",
|
|
1815
1916
|
"performance"
|
|
1816
1917
|
],
|
|
1817
1918
|
"scope": [
|
|
@@ -1821,6 +1922,7 @@ datadog_schedule_downtime_single() {
|
|
|
1821
1922
|
}
|
|
1822
1923
|
'
|
|
1823
1924
|
}
|
|
1925
|
+
|
|
1824
1926
|
#!/usr/bin/env bash
|
|
1825
1927
|
|
|
1826
1928
|
docker_build_push() {
|
|
@@ -1833,11 +1935,18 @@ docker_build_push() {
|
|
|
1833
1935
|
|
|
1834
1936
|
if ! image_exists $DOCKER_REGISTRY_ID $APPLICATION $CI_COMMIT_SHORT_SHA ; then
|
|
1835
1937
|
docker pull $DOCKER_IMAGE || true
|
|
1836
|
-
|
|
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
|
|
1837
1945
|
docker push $DOCKER_IMAGE_SHA
|
|
1838
1946
|
fi
|
|
1839
1947
|
}
|
|
1840
1948
|
|
|
1949
|
+
|
|
1841
1950
|
docker_promote() {
|
|
1842
1951
|
# inspired by https://dille.name/blog/2018/09/20/how-to-tag-docker-images-without-pulling-them/
|
|
1843
1952
|
OLD_TAG=${1//[^0-9a-zA-Z-.]/_}
|
|
@@ -1864,6 +1973,7 @@ docker_promote() {
|
|
|
1864
1973
|
image_exists ${DOCKER_REGISTRY_ID} ${IMAGE_TO_CHECK} ${VERSION} || return 1
|
|
1865
1974
|
done
|
|
1866
1975
|
}
|
|
1976
|
+
|
|
1867
1977
|
#!/usr/bin/env bash
|
|
1868
1978
|
|
|
1869
1979
|
extract_yaml_config_variable() {
|
|
@@ -1940,7 +2050,7 @@ flyway_clean() {
|
|
|
1940
2050
|
|
|
1941
2051
|
#!/usr/bin/env bash
|
|
1942
2052
|
|
|
1943
|
-
FLYWAY_VERSION="
|
|
2053
|
+
FLYWAY_VERSION="7.4.0"
|
|
1944
2054
|
|
|
1945
2055
|
|
|
1946
2056
|
get_yaml_variable() {
|
|
@@ -2026,7 +2136,7 @@ flyway_migrate() {
|
|
|
2026
2136
|
"containers":[
|
|
2027
2137
|
{
|
|
2028
2138
|
"name":"'$POD_NAME'",
|
|
2029
|
-
"image":"
|
|
2139
|
+
"image":"flyway/flyway:'$flyway_version'",
|
|
2030
2140
|
"command":["flyway", "-url='$db_url'", "-user='$db_user'", "-password='$db_password'", "migrate"],
|
|
2031
2141
|
"volumeMounts":[
|
|
2032
2142
|
{
|
|
@@ -2051,6 +2161,63 @@ flyway_migrate() {
|
|
|
2051
2161
|
kubectl -n $namespace delete configmap $CONFIGMAP_NAME
|
|
2052
2162
|
}
|
|
2053
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
|
+
|
|
2054
2221
|
#!/usr/bin/env bash
|
|
2055
2222
|
|
|
2056
2223
|
record_git_commit() {
|
package/package.json
CHANGED
package/src/request/Request.res
CHANGED
|
@@ -4,6 +4,7 @@ type error<'apiError> =
|
|
|
4
4
|
| Custom('apiError)
|
|
5
5
|
|
|
6
6
|
type requestConfig<'apiError, 'response> = {
|
|
7
|
+
kyInstance?: Ky.Instance.t,
|
|
7
8
|
path: string,
|
|
8
9
|
requestOptions: Ky.requestOptions<Js.Json.t, Js.Json.t, Js.Json.t, 'response>,
|
|
9
10
|
key?: array<string>,
|
|
@@ -11,9 +12,18 @@ type requestConfig<'apiError, 'response> = {
|
|
|
11
12
|
mapPromise?: Js.Json.t => result<'response, error<'apiError>>,
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
type requestWithFetcherConfig<'apiError, 'response> = {
|
|
16
|
+
kyInstance?: Ky.Instance.t,
|
|
17
|
+
path: string,
|
|
18
|
+
requestOptions: Ky.requestOptions<Js.Json.t, Js.Json.t, Js.Json.t, 'response>,
|
|
19
|
+
key: array<string>,
|
|
20
|
+
customError?: Ky.error<Js.Json.t> => Promise.t<error<'apiError>>,
|
|
21
|
+
mapPromise?: Js.Json.t => result<'response, error<'apiError>>,
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
%%private(
|
|
15
25
|
let fetch = (
|
|
16
|
-
~instance
|
|
26
|
+
~instance=?,
|
|
17
27
|
~path,
|
|
18
28
|
~requestOptions,
|
|
19
29
|
~mapPromise=?,
|
|
@@ -23,7 +33,11 @@ type requestConfig<'apiError, 'response> = {
|
|
|
23
33
|
// TODO :
|
|
24
34
|
// - parseJson
|
|
25
35
|
// - abort controller signal
|
|
26
|
-
|
|
36
|
+
|
|
37
|
+
instance
|
|
38
|
+
->Option.mapWithDefault(Ky.fetch(path, requestOptions), instance => {
|
|
39
|
+
(instance->Ky.Instance.asCallable)(path, ~options=requestOptions)
|
|
40
|
+
})
|
|
27
41
|
->Ky.Response.json()
|
|
28
42
|
->Promise.Js.fromBsPromise
|
|
29
43
|
->Promise.Js.toResult
|
|
@@ -54,7 +68,6 @@ module type Config = {
|
|
|
54
68
|
type argument
|
|
55
69
|
type response
|
|
56
70
|
type error
|
|
57
|
-
let instance: Ky.Instance.t
|
|
58
71
|
let response_decode: Js.Json.t => result<response, Spice.decodeError>
|
|
59
72
|
let config: argument => requestConfig<error, response>
|
|
60
73
|
}
|
|
@@ -72,7 +85,7 @@ let fetchAPI = (
|
|
|
72
85
|
let requestConfig = C.config(argument)
|
|
73
86
|
|
|
74
87
|
fetch(
|
|
75
|
-
~instance
|
|
88
|
+
~instance=?requestConfig.kyInstance,
|
|
76
89
|
~path=requestConfig.path,
|
|
77
90
|
~response_decode=C.response_decode,
|
|
78
91
|
~requestOptions=requestConfig.requestOptions,
|
package/src/vendors/Swr.res
CHANGED
|
@@ -63,6 +63,11 @@ type mutationFetcher<'params, 'data, 'error> = {
|
|
|
63
63
|
|
|
64
64
|
module SwrKey = Toolkit__Identifier.MakeString()
|
|
65
65
|
|
|
66
|
+
@unboxed
|
|
67
|
+
type key =
|
|
68
|
+
| String(string)
|
|
69
|
+
| Array(array<string>)
|
|
70
|
+
|
|
66
71
|
@module("swr")
|
|
67
72
|
external useSwr: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<'data> = "default"
|
|
68
73
|
|
|
@@ -88,6 +93,8 @@ module SwrConfig = {
|
|
|
88
93
|
|
|
89
94
|
@send
|
|
90
95
|
external mutate0: (t, SwrKey.t) => unit = "mutate"
|
|
96
|
+
@send
|
|
97
|
+
external mutateByKey: (t, key) => unit = "mutate"
|
|
91
98
|
|
|
92
99
|
@send
|
|
93
100
|
external mutate: (t, SwrKey.t, 'data, bool) => unit = "mutate"
|