Skip to content

Commit

Permalink
feat(contenus): ajout d'une date (#1458)
Browse files Browse the repository at this point in the history
* fix: ajout des modif

* fix: tests

* fix: code

* fix: hasura

* fix: hasura

* fix: hasura

* empty

* feat: add code

* feat: add code

* fix: date

* fix: date

* fix: merge date

* fix: build

* fix: tests
  • Loading branch information
maxgfr authored Aug 22, 2024
1 parent 6081104 commit 05a90c9
Show file tree
Hide file tree
Showing 67 changed files with 839 additions and 472 deletions.
13 changes: 3 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,24 @@ services:
HASURA_GRAPHQL_ENDPOINT: "http://hasura:8080/v1/graphql"

minio:
image: "minio/minio:latest"
image: minio/minio
ports:
- "9000:9000"
- "8900:8900"
environment:
MINIO_ROOT_USER: MINIO_ACCESS_KEY
MINIO_ROOT_PASSWORD: MINIO_SECRET_KEY
volumes:
- minio_data:/data/minio
- minio_data:/data
command: 'minio server /data/minio --console-address ":8900"'
healthcheck:
test:
- CMD
- curl
- "-f"
- "http://localhost:9000/minio/health/live"
retries: 3
timeout: 5s

createbuckets:
image: minio/mc
depends_on:
- minio
entrypoint: >
/bin/sh -c "
sleep 5;
/usr/bin/mc alias set myminio http://minio:9000 MINIO_ACCESS_KEY MINIO_SECRET_KEY;
/usr/bin/mc mb myminio/cdtn;
/usr/bin/mc anonymous set public myminio/cdtn;
Expand Down
117 changes: 60 additions & 57 deletions scripts/connect_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

if ! command -v kubectl &> /dev/null; then
echo "${RED}Error : kubectl is not installed.${NC}"
exit 1
if ! command -v kubectl &>/dev/null; then
echo "${RED}Error : kubectl is not installed.${NC}"
exit 1
fi

write_mode=false
port=5435
namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}'; echo)
namespace=$(
kubectl config view --minify --output 'jsonpath={..namespace}'
echo
)

function usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -h, --help Display this help message"
echo " -n, --namespace Set a specific namespace (run on the current otherwise)"
echo " -p, --port Set a specific port for the postgres connexion (5435 by default)"
echo " -w, --write-mode Connect to the primary (read/write) pg instance. Connect to a replica (read only) by default"
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -h, --help Display this help message"
echo " -n, --namespace Set a specific namespace (run on the current otherwise)"
echo " -p, --port Set a specific port for the postgres connexion (5435 by default)"
echo " -w, --write-mode Connect to the primary (read/write) pg instance. Connect to a replica (read only) by default"
}

has_argument() {
[[ ("$1" == *=* && -n ${1#*=}) || ( ! -z "$2" && "$2" != -*) ]];
[[ ("$1" == *=* && -n ${1#*=}) || (! -z "$2" && "$2" != -*) ]]
}

extract_argument() {
Expand All @@ -34,46 +37,46 @@ extract_argument() {
handle_options() {
while [ $# -gt 0 ]; do
case $1 in
-h | --help)
-h | --help)
usage
exit 0
;;
-w | --write-mode)
write_mode=true
;;
-n | --namespace*)
if ! has_argument $@; then
echo -e "${RED}Namespace manquant.${NC}" >&2
usage
exit 1
fi

namespace=$(extract_argument $@)

shift
;;
-p | --port*)
if ! has_argument $@; then
echo -e "${RED}Port manquant.${NC}" >&2
usage
exit 0
;;
-w | --write-mode)
write_mode=true
;;
-n | --namespace*)
if ! has_argument $@; then
echo -e "${RED}Namespace manquant.${NC}" >&2
usage
exit 1
fi

namespace=$(extract_argument $@)

shift
;;
-p | --port*)
if ! has_argument $@; then
echo -e "${RED}Port manquant.${NC}" >&2
usage
exit 1
fi

port=$(extract_argument $@)

if [[ ! $port =~ ^[0-9]+$ ]]; then
echo -e "${RED}Le port doit être composé de chiffre uniquement.${NC}" >&2
usage
exit 1
fi

shift
;;
*)
echo "Invalid option: $1" >&2
exit 1
fi

port=$(extract_argument $@)

if [[ ! $port =~ ^[0-9]+$ ]]; then
echo -e "${RED}Le port doit être composé de chiffre uniquement.${NC}" >&2
usage
exit 1
;;
fi

shift
;;
*)
echo "Invalid option: $1" >&2
usage
exit 1
;;
esac
shift
done
Expand All @@ -86,20 +89,20 @@ environment=$(kubectl config current-context)
current_context=$(kubectl config current-context)

if [[ $write_mode == "true" ]]; then
echo -e "Connection à la base de données de $namespace en mode ${RED}lecture et écriture${NC} (cluster: ${YELLOW}$environment${NC})."
echo -e "Connection à la base de données de $namespace en mode ${RED}lecture et écriture${NC} (cluster: ${YELLOW}$environment${NC})."
else
echo -e "Connection à la base de données de $namespace en mode lecture seule (cluster: ${YELLOW}$environment${NC})."
echo -e "Connection à la base de données de $namespace en mode lecture seule (cluster: ${YELLOW}$environment${NC})."
fi

if [[ $write_mode == "true" && $current_context == *"prod"* ]]; then
echo -e "${RED}Attention ! Connection sur l'environnement de production en mode écriture. Il est recommandé de ne pas écrire directement sur une base de données en prod.${NC}"
echo -e "${RED}Attention ! Connection sur l'environnement de production en mode écriture. Il est recommandé de ne pas écrire directement sur une base de données en prod.${NC}"
fi

# Get the pg instance
if [[ $write_mode == "true" ]]; then
pg_type="primary"
pg_type="primary"
else
pg_type="replica"
pg_type="replica"
fi

pg_pods=$(kubectl -n $namespace get po --selector=cnpg.io/podRole=instance -o=custom-columns="NAME:.metadata.name,ROLE:.metadata.labels.role")
Expand All @@ -126,7 +129,7 @@ local_connection_ssl_disabled=$(echo "$local_connection" | sed 's/?sslmode=requi
local_connection_without_ssl=$(echo "$local_connection" | sed 's/?sslmode=require//')

echo -e "Activation du port forwarding..."
kubectl port-forward -n $namespace $pod $port:5432 > /dev/null 2>&1 &
kubectl port-forward -n $namespace $pod $port:5432 >/dev/null 2>&1 &
pid=$!

# kill the port-forward regardless of how this script exits
Expand All @@ -136,8 +139,8 @@ trap '{
}' EXIT

# wait for $port to become available
while ! nc -vz localhost $port > /dev/null 2>&1 ; do
sleep 0.1
while ! nc -vz localhost $port >/dev/null 2>&1; do
sleep 0.1
done
echo -e "Port forwarding : ${GREEN}OK${NC}"
echo -e "${GREEN}Adresse de connexion pour se connecter à la BDD depuis votre poste :\n$local_connection_ssl_disabled${NC}"
Expand All @@ -148,5 +151,5 @@ echo -e "${GREEN}jdbc:$local_connection_without_ssl ${GREEN}"

echo -e "Appuyez sur Ctrl+C pour quitter."
while true; do
sleep 1
sleep 1
done
29 changes: 15 additions & 14 deletions scripts/dump_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,23 @@ kubectl exec -n $namespace $pod -c postgres -- pg_dump -Fc -d $database >${folde
echo -e "${GREEN}Dump terminé : ${folder}/${output}${NC}"

confirm() {
while true; do
read -p "Voulez-vous relancer votre environnement avec ce dump ? (Y/n) " answer
case $answer in
[Yy]* ) break;;
[Nn]* ) echo -e ""
echo -e "Commande pour restaurer la BDD en local :"
echo -e "docker compose exec -T postgres pg_restore \\"
echo -e " --dbname postgres --clean --if-exists --user postgres \\"
echo -e " --no-owner --no-acl --verbose < ${folder}/${output} "
exit;;
* ) echo "Veuillez répondre par Y (oui) ou n (non).";;
esac
done
while true; do
read -p "Voulez-vous relancer votre environnement avec ce dump ? (Y/n) " answer
case $answer in
[Yy]*) break ;;
[Nn]*)
echo -e ""
echo -e "Commande pour restaurer la BDD en local :"
echo -e "docker compose exec -T postgres pg_restore \\"
echo -e " --dbname postgres --clean --if-exists --user postgres \\"
echo -e " --no-owner --no-acl --verbose < ${folder}/${output} "
exit
;;
*) echo "Veuillez répondre par Y (oui) ou n (non)." ;;
esac
done
}

confirm

./scripts/reset_from_dump.sh "${folder}/${output}"

48 changes: 24 additions & 24 deletions scripts/reset_from_dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

if ! command -v docker &> /dev/null; then
echo "${RED}Error : docker is not installed.${NC}"
exit 1
if ! command -v docker &>/dev/null; then
echo "${RED}Error : docker is not installed.${NC}"
exit 1
fi

function usage() {
echo "Usage: $0 [OPTIONS] dump"
echo "Options:"
echo " -h, --help Display this help message"
echo "Usage: $0 [OPTIONS] dump"
echo "Options:"
echo " -h, --help Display this help message"
}

handle_options() {
while [ $# -gt 0 ]; do
case $1 in
-h | --help)
-h | --help)
usage
exit 0
;;
*)
if [ -z "$dump_file" ]; then
dump_file=$1
else
echo -e "${RED}Invalid option: $1${NC}" >&2
usage
exit 0
;;
*)
if [ -z "$dump_file" ]; then
dump_file=$1
else
echo -e "${RED}Invalid option: $1${NC}" >&2
usage
exit 1
fi
;;
exit 1
fi
;;
esac
shift
done
Expand All @@ -43,8 +43,8 @@ handle_options "$@"
dump_file=$1

if [ ! -f "$dump_file" ]; then
echo -e "${RED}Erreur : Le fichier '$dump_file' n'existe pas.${NC}"
exit 1
echo -e "${RED}Erreur : Le fichier '$dump_file' n'existe pas.${NC}"
exit 1
fi

echo -e "${YELLOW}Suppression de l'environnement...${NC}"
Expand All @@ -60,15 +60,15 @@ echo -e "${YELLOW}Restore de la base de données...${NC}"

docker compose exec -T postgres pg_restore \
--dbname postgres --clean --if-exists --user postgres \
--no-owner --no-acl --verbose < $dump_file
--no-owner --no-acl --verbose <$dump_file

echo -e "${YELLOW}Clean de la base de données...${NC}"

docker compose exec -T postgres psql \
--dbname postgres --user postgres < .kontinuous/sql/post-restore.sql
--dbname postgres --user postgres <.kontinuous/sql/post-restore.sql

echo -e "${YELLOW}Lancement d'hasura et d'elasticsearch...${NC}"
echo -e "${YELLOW}Lancement d'hasura, d'elasticsearch et de minio...${NC}"

docker compose up --wait -d hasura elasticsearch
docker compose up --wait -d hasura elasticsearch minio createbuckets

echo -e "${GREEN}Environnement prêt \o/${NC}"
1 change: 1 addition & 0 deletions shared/types/src/hasura/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ContributionsAnswers = {
agreement: ContributionAgreement;
updatedAt: string;
statuses?: ContributionStatus[];
display_date: string;
};

export type ContributionQuestion = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const contributionMock: ContributionsAnswers = {
order: 1,
},
statuses: [],
display_date: "2024-03-25",
};

const doc: DocumentElasticWithSource<ContributionDocumentJson> = {
Expand Down
1 change: 1 addition & 0 deletions targets/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@hookform/resolvers": "^3.3.1",
"@mui/icons-material": "5.11.16",
"@mui/material": "5.14.11",
"@mui/x-date-pickers": "^7.13.0",
"@reach/accordion": "^0.16.1",
"@reach/dialog": "^0.16.0",
"@reach/menu-button": "^0.16.1",
Expand Down
Loading

0 comments on commit 05a90c9

Please sign in to comment.