@colisweb/rescript-toolkit 4.26.3 → 4.26.4
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.
- package/.secure_files/{ci-functions-v17.0.5 → ci-functions-v17.8.6} +348 -78
- package/.secure_files/{ci-functions-v17.0.6 → ci-functions-v17.9.0} +348 -78
- package/.secure_files/{ci-functions-v17.0.7 → ci-functions-v17.9.1} +348 -78
- package/.secure_files/{ci-functions-v17.0.8 → ci-functions-v17.9.2} +348 -78
- package/package.json +1 -1
- package/src/intl/Toolkit__Intl.res +7 -5
- package/src/intl/Toolkit__Intl.resi +1 -2
|
@@ -100,17 +100,16 @@ delete_images() {
|
|
|
100
100
|
REPO=$1
|
|
101
101
|
WEEKS=${2:-16}
|
|
102
102
|
|
|
103
|
-
WEEKS_AGO=$(date -
|
|
103
|
+
WEEKS_AGO=$(date -v-${WEEKS}w +%F)
|
|
104
104
|
|
|
105
105
|
#Get all ecr images
|
|
106
106
|
IMAGES=$(aws ecr describe-images --repository-name $REPO --output json)
|
|
107
107
|
|
|
108
108
|
#Filter unnecessary values and map `imagePushedAt` to EPOCH
|
|
109
|
-
|
|
109
|
+
NON_LATEST_IMAGES=$(echo $IMAGES | jq '[.imageDetails[] | select(.imageTags | any(endswith("latest")) | not)]')
|
|
110
110
|
|
|
111
111
|
#Filter on EPOCH
|
|
112
|
-
OLD_IMAGES=$(echo $
|
|
113
|
-
|
|
112
|
+
OLD_IMAGES=$(echo $NON_LATEST_IMAGES | jq --arg date $WEEKS_AGO '.[] | select(.imagePushedAt[0:10] < $date).imageDigest')
|
|
114
113
|
while IFS= read -r IMAGE; do
|
|
115
114
|
if [ "$IMAGE" != "" ]; then
|
|
116
115
|
echo "Deleting $IMAGE from $REPO"
|
|
@@ -130,6 +129,27 @@ delete_images_all_repos() {
|
|
|
130
129
|
done <<< "$REPOSITORIES"
|
|
131
130
|
}
|
|
132
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
|
+
|
|
133
153
|
#!/usr/bin/env bash
|
|
134
154
|
|
|
135
155
|
# If gitlab is down or pipeline are stuck, hotfixes need to be available
|
|
@@ -515,28 +535,29 @@ database_k8s() {
|
|
|
515
535
|
HostName 127.0.0.1
|
|
516
536
|
Port 2225
|
|
517
537
|
LocalForward 24441 toutatis-testing-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
|
|
518
|
-
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
|
|
519
540
|
Host bastion_staging
|
|
520
541
|
HostName 127.0.0.1
|
|
521
542
|
Port 2226
|
|
522
543
|
LocalForward 24442 toutatis-staging-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
|
|
523
|
-
LocalForward 25432
|
|
544
|
+
LocalForward 25432 toutatis-staging-mysql-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
|
|
524
545
|
Host bastion_recette
|
|
525
546
|
HostName 127.0.0.1
|
|
526
547
|
Port 2228
|
|
527
548
|
LocalForward 24446 toutatis-recette-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
|
|
528
|
-
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
|
|
529
551
|
Host bastion_production
|
|
530
552
|
HostName 127.0.0.1
|
|
531
553
|
Port 2227
|
|
532
554
|
LocalForward 24443 toutatis-production-db-replica.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
|
|
533
|
-
LocalForward 25433
|
|
534
|
-
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
|
|
535
556
|
EOF
|
|
536
557
|
if [ "$MODE" = "production_rw" ] ; then
|
|
537
558
|
cat >> "$bastion_config" <<EOF
|
|
538
559
|
LocalForward 24444 toutatis-production-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:5432
|
|
539
|
-
LocalForward 25434
|
|
560
|
+
LocalForward 25434 toutatis-production-mysql-db.ca0rjdmnxf1x.eu-west-1.rds.amazonaws.com:3306
|
|
540
561
|
EOF
|
|
541
562
|
fi
|
|
542
563
|
|
|
@@ -556,7 +577,7 @@ psql_on_k8() {
|
|
|
556
577
|
CONNECTION=$3
|
|
557
578
|
shift 3
|
|
558
579
|
|
|
559
|
-
kubectl -n $NAMESPACE run ${SERVICE}-
|
|
580
|
+
kubectl -n $NAMESPACE run ${SERVICE}-postgres-init \
|
|
560
581
|
--image jbergknoff/postgresql-client \
|
|
561
582
|
--restart=Never \
|
|
562
583
|
--attach --rm \
|
|
@@ -567,14 +588,15 @@ psql_on_k8() {
|
|
|
567
588
|
|
|
568
589
|
mysql_on_k8() {
|
|
569
590
|
local namespace=$1
|
|
570
|
-
local
|
|
571
|
-
local
|
|
572
|
-
local
|
|
573
|
-
local
|
|
574
|
-
local
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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 \
|
|
578
600
|
--restart=Never \
|
|
579
601
|
--attach --rm \
|
|
580
602
|
-- \
|
|
@@ -654,14 +676,14 @@ kube_init_datadog_in_database() {
|
|
|
654
676
|
extract_args 8 namespace db_host db_port db_init_username db_init_password db_datadog_username db_datadog_password db_datadog_schema $*
|
|
655
677
|
|
|
656
678
|
echo "======================="
|
|
657
|
-
echo " Initializing Datadog Agent
|
|
679
|
+
echo " Initializing Datadog Agent Requirement for namespace $namespace"
|
|
658
680
|
echo "======================="
|
|
659
681
|
|
|
660
|
-
set -x
|
|
661
|
-
|
|
662
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;')
|
|
663
685
|
set +e
|
|
664
|
-
|
|
686
|
+
echo "$found_db_users" | grep "^$db_datadog_username$"
|
|
665
687
|
return_code=$?
|
|
666
688
|
set -e
|
|
667
689
|
|
|
@@ -672,29 +694,29 @@ kube_init_datadog_in_database() {
|
|
|
672
694
|
|
|
673
695
|
# All the query come from this docs : https://docs.datadoghq.com/fr/database_monitoring/setup_mysql/selfhosted/?tab=mysql56
|
|
674
696
|
|
|
675
|
-
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'"';'
|
|
676
698
|
echo "USER created $db_datadog_username"
|
|
677
699
|
|
|
678
|
-
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;'
|
|
679
701
|
echo "ALTER USER $db_datadog_username"
|
|
680
702
|
|
|
681
|
-
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"'@"%";'
|
|
682
704
|
echo "Granted PROCESS for $db_datadog_username"
|
|
683
705
|
|
|
684
|
-
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"'@"%";'
|
|
685
707
|
echo "Granted SELECT on performance_schema for $db_datadog_username"
|
|
686
708
|
|
|
687
|
-
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;'
|
|
688
710
|
echo "CREATE SCHEMA datadog"
|
|
689
711
|
|
|
690
|
-
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"'@"%";'
|
|
691
713
|
echo "Granted 'GRANT EXECUTE for $db_datadog_username on datadog"
|
|
692
714
|
|
|
693
|
-
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"'@"%";'
|
|
694
716
|
echo "Granted CREATE TEMPORARY TABLES for $db_datadog_username"
|
|
695
717
|
|
|
696
718
|
|
|
697
|
-
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;
|
|
698
720
|
DELIMITER $$
|
|
699
721
|
CREATE PROCEDURE datadog.explain_statement(IN query TEXT)
|
|
700
722
|
SQL SECURITY DEFINER
|
|
@@ -707,7 +729,7 @@ kube_init_datadog_in_database() {
|
|
|
707
729
|
DELIMITER ;'
|
|
708
730
|
echo "CREATE PROCEDURE PROCEDURE datadog.explain_statement"
|
|
709
731
|
|
|
710
|
-
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;
|
|
711
733
|
DELIMITER $$
|
|
712
734
|
CREATE PROCEDURE '"$db_datadog_username"'.explain_statement(IN query TEXT)
|
|
713
735
|
SQL SECURITY DEFINER
|
|
@@ -721,7 +743,7 @@ kube_init_datadog_in_database() {
|
|
|
721
743
|
GRANT EXECUTE ON PROCEDURE '"$db_datadog_username"'.explain_statement TO datadog@"%";'
|
|
722
744
|
echo "CREATE PROCEDURE on SCHEMA $db_datadog_schema for $db_datadog_username"
|
|
723
745
|
|
|
724
|
-
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;
|
|
725
747
|
DELIMITER $$
|
|
726
748
|
CREATE PROCEDURE datadog.enable_events_statements_consumers()
|
|
727
749
|
SQL SECURITY DEFINER
|
|
@@ -739,6 +761,82 @@ kube_init_datadog_in_database() {
|
|
|
739
761
|
echo "======================="
|
|
740
762
|
}
|
|
741
763
|
|
|
764
|
+
kube_init_datadog_in_postgres_database() {
|
|
765
|
+
extract_args 7 namespace db_host db_port db_init_username db_init_password db_datadog_username db_datadog_password $*
|
|
766
|
+
|
|
767
|
+
local service="datadog"
|
|
768
|
+
local db_connection="$db_init_username:$db_init_password@$db_host:$db_port"
|
|
769
|
+
|
|
770
|
+
echo "======================="
|
|
771
|
+
echo " Initializing $service Agent On PostgresSQL Database Requirement for namespace $namespace"
|
|
772
|
+
echo "======================="
|
|
773
|
+
|
|
774
|
+
echo "Checking if User '$db_datadog_username' exists"
|
|
775
|
+
|
|
776
|
+
set +e
|
|
777
|
+
if psql_on_k8 $namespace $service $db_connection -qtAc 'SELECT usename FROM pg_catalog.pg_user;' | grep "^$db_datadog_username$";
|
|
778
|
+
then
|
|
779
|
+
echo "User $db_datadog_username already exists - nothing to do"
|
|
780
|
+
else
|
|
781
|
+
echo "User $db_datadog_username does not exist - initializing"
|
|
782
|
+
|
|
783
|
+
set -e
|
|
784
|
+
psql_on_k8 $namespace $service $db_connection -qc 'CREATE USER '"$db_datadog_username"' WITH password '"'$db_datadog_password'"';'
|
|
785
|
+
echo "User created $db_datadog_username"
|
|
786
|
+
|
|
787
|
+
psql_on_k8 $namespace $service $db_connection -qc 'CREATE SCHEMA datadog;'
|
|
788
|
+
echo "Schema datadog created"
|
|
789
|
+
|
|
790
|
+
psql_on_k8 $namespace $service $db_connection -qc 'GRANT USAGE ON SCHEMA datadog TO datadog;'
|
|
791
|
+
echo "Granted usage for datadog schema to datadog"
|
|
792
|
+
|
|
793
|
+
psql_on_k8 $namespace $service $db_connection -qc 'GRANT USAGE ON SCHEMA public TO datadog;'
|
|
794
|
+
echo "Granted usage for public schema to datadog"
|
|
795
|
+
|
|
796
|
+
psql_on_k8 $namespace $service $db_connection -qc 'GRANT pg_monitor TO datadog;'
|
|
797
|
+
echo "Granted pg_monitor to datadog"
|
|
798
|
+
|
|
799
|
+
psql_on_k8 $namespace $service $db_connection -qc 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements schema public;'
|
|
800
|
+
echo "Extension pg_stat_statements created"
|
|
801
|
+
|
|
802
|
+
local datadog_function_path="/tmp/datatog-explain-statement-function.sql"
|
|
803
|
+
local datadog_function="CREATE OR REPLACE FUNCTION datadog.explain_statement(
|
|
804
|
+
l_query TEXT,
|
|
805
|
+
OUT explain JSON
|
|
806
|
+
)
|
|
807
|
+
RETURNS SETOF JSON AS
|
|
808
|
+
\\$\\$
|
|
809
|
+
DECLARE
|
|
810
|
+
curs REFCURSOR;
|
|
811
|
+
plan JSON;
|
|
812
|
+
|
|
813
|
+
BEGIN
|
|
814
|
+
OPEN curs FOR EXECUTE pg_catalog.concat('EXPLAIN (FORMAT JSON) ', l_query);
|
|
815
|
+
FETCH curs INTO plan;
|
|
816
|
+
CLOSE curs;
|
|
817
|
+
RETURN QUERY SELECT plan;
|
|
818
|
+
END;
|
|
819
|
+
\\$\\$
|
|
820
|
+
LANGUAGE 'plpgsql'
|
|
821
|
+
RETURNS NULL ON NULL INPUT
|
|
822
|
+
SECURITY DEFINER;"
|
|
823
|
+
|
|
824
|
+
kubectl -n $namespace run $service-postgres-init \
|
|
825
|
+
--image jbergknoff/postgresql-client \
|
|
826
|
+
--restart=Never \
|
|
827
|
+
--attach --rm \
|
|
828
|
+
--command \
|
|
829
|
+
-- \
|
|
830
|
+
/bin/sh -c "echo -e \"$datadog_function\" > $datadog_function_path; psql postgresql://$db_connection -qf $datadog_function_path"
|
|
831
|
+
|
|
832
|
+
echo "Function datadog.explain_statement created"
|
|
833
|
+
fi
|
|
834
|
+
|
|
835
|
+
echo "======================="
|
|
836
|
+
echo " Database $service Initialization complete for namespace $namespace"
|
|
837
|
+
echo "======================="
|
|
838
|
+
}
|
|
839
|
+
|
|
742
840
|
kube_init_service_database() {
|
|
743
841
|
|
|
744
842
|
extract_args 9 namespace service db_host db_port db_init_username db_init_password db_database db_username db_password $*
|
|
@@ -761,17 +859,69 @@ kube_init_service_database() {
|
|
|
761
859
|
psql_on_k8 $namespace $service $db_connection -c 'CREATE DATABASE '"$db_database"';'
|
|
762
860
|
echo "DB created $db_database"
|
|
763
861
|
|
|
764
|
-
psql_on_k8 $namespace $service $db_connection -c 'CREATE USER '"$
|
|
765
|
-
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"
|
|
766
864
|
|
|
767
|
-
psql_on_k8 $namespace $service $db_connection -c 'GRANT ALL PRIVILEGES ON DATABASE '"$db_database"' TO '"$
|
|
768
|
-
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"
|
|
769
867
|
fi
|
|
770
868
|
|
|
771
869
|
echo "======================="
|
|
772
|
-
echo " Database '$db_database' Initialization complete for
|
|
870
|
+
echo " Database '$db_database' Initialization complete for namespace $namespace"
|
|
773
871
|
echo "======================="
|
|
774
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
|
+
|
|
775
925
|
#!/usr/bin/env bash
|
|
776
926
|
|
|
777
927
|
# Port forward on the first matching pod
|
|
@@ -851,12 +1001,58 @@ pick_pod() {
|
|
|
851
1001
|
|
|
852
1002
|
#!/usr/bin/env bash
|
|
853
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
|
+
|
|
854
1047
|
redis_k8s() {
|
|
855
1048
|
MODE=$1
|
|
1049
|
+
REDIS_INSTANCE=${2:-ca}
|
|
856
1050
|
case $MODE in
|
|
1051
|
+
"tests") SSH_LOCAL_PORT=2224;REDIS_LOCAL_PORT=63790;ENV="tests";;
|
|
857
1052
|
"testing") SSH_LOCAL_PORT=2225;REDIS_LOCAL_PORT=63791;ENV="testing";;
|
|
858
|
-
"
|
|
859
|
-
"
|
|
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";;
|
|
860
1056
|
*) echo "Unsupported ENV : $MODE"; return 1 ;;
|
|
861
1057
|
esac
|
|
862
1058
|
|
|
@@ -865,23 +1061,11 @@ redis_k8s() {
|
|
|
865
1061
|
lsof -ti tcp:$REDIS_LOCAL_PORT | xargs kill
|
|
866
1062
|
|
|
867
1063
|
bastion_config=$(mktemp)
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
HostName 127.0.0.1
|
|
874
|
-
Port 2225
|
|
875
|
-
LocalForward 63791 redis-testing.xufte6.0001.euw1.cache.amazonaws.com:6379
|
|
876
|
-
Host bastion_staging
|
|
877
|
-
HostName 127.0.0.1
|
|
878
|
-
Port 2226
|
|
879
|
-
LocalForward 63792 redis-sandbox.xufte6.0001.euw1.cache.amazonaws.com:6379
|
|
880
|
-
Host bastion_production
|
|
881
|
-
HostName 127.0.0.1
|
|
882
|
-
Port 2227
|
|
883
|
-
LocalForward 63793 redis-prod.xufte6.0001.euw1.cache.amazonaws.com:6379
|
|
884
|
-
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
|
|
885
1069
|
|
|
886
1070
|
ssh -f -N \
|
|
887
1071
|
-F "$bastion_config" \
|
|
@@ -1289,6 +1473,36 @@ search_business() {
|
|
|
1289
1473
|
curl $URL
|
|
1290
1474
|
}
|
|
1291
1475
|
|
|
1476
|
+
#!/bin/bash
|
|
1477
|
+
|
|
1478
|
+
# source tolls.sh ; tolls antoine.thomas@colisweb.com
|
|
1479
|
+
function tolls() {
|
|
1480
|
+
USER=${1:-first.last@colisweb.com}
|
|
1481
|
+
FROM_DATE=${2:-"2023-02-01"}
|
|
1482
|
+
TO_DATE=${3:-"2023-02-28"}
|
|
1483
|
+
|
|
1484
|
+
USER=$(gum input --prompt "username : " --value $USER)
|
|
1485
|
+
TOKEN=$(./tour_details.sc login --user $USER --password $(gum input --password --placeholder password))
|
|
1486
|
+
[ "$TOKEN" != "" ] && echo "connected" || return 1
|
|
1487
|
+
|
|
1488
|
+
FROM_DATE=$(gum input --prompt "Date start : " --value $FROM_DATE)
|
|
1489
|
+
TO_DATE=$(gum input --prompt "Date end : " --value $TO_DATE)
|
|
1490
|
+
FILENAME="tours-${FROM_DATE}-TO-${TO_DATE}.json"
|
|
1491
|
+
curl --cookie "session=$TOKEN" "https://api.production.colisweb.com/api/v6/routes-plans/external?from=${FROM_DATE}&to=${TO_DATE}" > ~/Downloads/$FILENAME
|
|
1492
|
+
echo "Tournées téléchargées"
|
|
1493
|
+
|
|
1494
|
+
projectIds=$(./tour_details.sc allProjects --file ~/Downloads/$FILENAME | gum choose --no-limit | cut -d "," -f 2)
|
|
1495
|
+
echo "projets sélectionnés : $projectIds"
|
|
1496
|
+
tourIds=$(./tour_details.sc allTours --file ~/Downloads/$FILENAME --projectIds "$projectIds")
|
|
1497
|
+
echo "tournées sélectionnées : $tourIds"
|
|
1498
|
+
|
|
1499
|
+
TARGET="${FROM_DATE}-TO-${TO_DATE}.csv"
|
|
1500
|
+
echo "appels à HERE, écriture dans $TARGET"
|
|
1501
|
+
./tour_details.sc allToursDetails --token $TOKEN --hereApiKey $HERE_API_KEY --routeIds "$tourIds" > "$TARGET"
|
|
1502
|
+
|
|
1503
|
+
echo "terminé"
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1292
1506
|
#!/usr/bin/env bash
|
|
1293
1507
|
|
|
1294
1508
|
# possible syntax:
|
|
@@ -1393,24 +1607,13 @@ jconsole_k8s() {
|
|
|
1393
1607
|
|
|
1394
1608
|
#!/usr/bin/env bash
|
|
1395
1609
|
|
|
1396
|
-
# Interactive console on an existing pod. See also run_ruby_k8s
|
|
1397
|
-
# Ex :
|
|
1398
|
-
# railsc_k8s_old production
|
|
1399
|
-
# railsc_k8s_old production "User.where(email:'toni@colisweb.com')"
|
|
1400
|
-
railsc_k8s_old() {
|
|
1401
|
-
ENV=$1
|
|
1402
|
-
COMMAND=$2
|
|
1403
|
-
configure_kubectl_for $ENV
|
|
1404
|
-
POD=$(kubectl -n $ENV get pods -o=name | grep colisweb-api-web | head -1 | sed -e 's/pod\///')
|
|
1405
|
-
KUBERAILS="kubectl -n $ENV exec -ti $POD -- /usr/src/app/bin/rails c"
|
|
1406
|
-
[ -z "$COMMAND" ] && eval $KUBERAILS || echo $COMMAND | eval $KUBERAILS
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
1610
|
# Interactive console on an new pod. See also run_ruby_k8s
|
|
1410
1611
|
# Ex :
|
|
1411
1612
|
# railsc_k8s production
|
|
1613
|
+
# railsc_k8s production "User.where(email:'toni@colisweb.com')"
|
|
1412
1614
|
railsc_k8s() {
|
|
1413
1615
|
ENV=$1
|
|
1616
|
+
COMMAND=$2
|
|
1414
1617
|
[[ $ENV = "production" || $ENV = "staging" ]] && default_tag="master-latest" || default_tag="${ENV}-latest"
|
|
1415
1618
|
local image_tag=${5:-$default_tag}
|
|
1416
1619
|
local IMAGE="949316342391.dkr.ecr.eu-west-1.amazonaws.com/colisweb-api:$image_tag"
|
|
@@ -1460,7 +1663,8 @@ railsc_k8s() {
|
|
|
1460
1663
|
'
|
|
1461
1664
|
|
|
1462
1665
|
sleep 5
|
|
1463
|
-
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
|
|
1464
1668
|
|
|
1465
1669
|
print "End of $POD_NAME "
|
|
1466
1670
|
kubectl -n $ENV delete pods $POD_NAME
|
|
@@ -1704,11 +1908,11 @@ datadog_schedule_downtime_single() {
|
|
|
1704
1908
|
{
|
|
1705
1909
|
"active": true,
|
|
1706
1910
|
"downtime_type": 0,
|
|
1707
|
-
"start": $START,
|
|
1708
|
-
"end": $END,
|
|
1709
|
-
"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",
|
|
1710
1914
|
"monitor_tags": [
|
|
1711
|
-
"service
|
|
1915
|
+
"service:'$SERVICE'",
|
|
1712
1916
|
"performance"
|
|
1713
1917
|
],
|
|
1714
1918
|
"scope": [
|
|
@@ -1718,6 +1922,7 @@ datadog_schedule_downtime_single() {
|
|
|
1718
1922
|
}
|
|
1719
1923
|
'
|
|
1720
1924
|
}
|
|
1925
|
+
|
|
1721
1926
|
#!/usr/bin/env bash
|
|
1722
1927
|
|
|
1723
1928
|
docker_build_push() {
|
|
@@ -1730,11 +1935,18 @@ docker_build_push() {
|
|
|
1730
1935
|
|
|
1731
1936
|
if ! image_exists $DOCKER_REGISTRY_ID $APPLICATION $CI_COMMIT_SHORT_SHA ; then
|
|
1732
1937
|
docker pull $DOCKER_IMAGE || true
|
|
1733
|
-
|
|
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
|
|
1734
1945
|
docker push $DOCKER_IMAGE_SHA
|
|
1735
1946
|
fi
|
|
1736
1947
|
}
|
|
1737
1948
|
|
|
1949
|
+
|
|
1738
1950
|
docker_promote() {
|
|
1739
1951
|
# inspired by https://dille.name/blog/2018/09/20/how-to-tag-docker-images-without-pulling-them/
|
|
1740
1952
|
OLD_TAG=${1//[^0-9a-zA-Z-.]/_}
|
|
@@ -1761,6 +1973,7 @@ docker_promote() {
|
|
|
1761
1973
|
image_exists ${DOCKER_REGISTRY_ID} ${IMAGE_TO_CHECK} ${VERSION} || return 1
|
|
1762
1974
|
done
|
|
1763
1975
|
}
|
|
1976
|
+
|
|
1764
1977
|
#!/usr/bin/env bash
|
|
1765
1978
|
|
|
1766
1979
|
extract_yaml_config_variable() {
|
|
@@ -1837,7 +2050,7 @@ flyway_clean() {
|
|
|
1837
2050
|
|
|
1838
2051
|
#!/usr/bin/env bash
|
|
1839
2052
|
|
|
1840
|
-
FLYWAY_VERSION="
|
|
2053
|
+
FLYWAY_VERSION="7.4.0"
|
|
1841
2054
|
|
|
1842
2055
|
|
|
1843
2056
|
get_yaml_variable() {
|
|
@@ -1923,7 +2136,7 @@ flyway_migrate() {
|
|
|
1923
2136
|
"containers":[
|
|
1924
2137
|
{
|
|
1925
2138
|
"name":"'$POD_NAME'",
|
|
1926
|
-
"image":"
|
|
2139
|
+
"image":"flyway/flyway:'$flyway_version'",
|
|
1927
2140
|
"command":["flyway", "-url='$db_url'", "-user='$db_user'", "-password='$db_password'", "migrate"],
|
|
1928
2141
|
"volumeMounts":[
|
|
1929
2142
|
{
|
|
@@ -1948,6 +2161,63 @@ flyway_migrate() {
|
|
|
1948
2161
|
kubectl -n $namespace delete configmap $CONFIGMAP_NAME
|
|
1949
2162
|
}
|
|
1950
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
|
+
|
|
1951
2221
|
#!/usr/bin/env bash
|
|
1952
2222
|
|
|
1953
2223
|
record_git_commit() {
|