Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bsr rework pc backend #14938

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions infra/pc_scripts/start_backend.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
#!/bin/bash

function start_backend {
docker_compose_major=$(docker compose -v 2>&1 | sed "s/.*version v*\([0-9]\).\([0-9]*\).\([0-9]*\).*/\1/");
docker_compose_minor=$(docker compose -v 2>&1 | sed "s/.*version v*\([0-9]\).\([0-9]*\).\([0-9]*\).*/\2/");
if [ "$docker_compose_major" -le "1" ] && [ "$docker_compose_minor" -le "23" ]; then
echo "This script requires docker compose 1.24 or greater"
exit 1
function concat_command {
if [[ "$RUN" != "" ]] && [[ "$RUN" != *\&\& ]]; then
RUN="$RUN &&"
fi
}

function move {
concat_command
RUN="$RUN cd '$ROOT_PATH'"
}

function build_backend {
concat_command
move
concat_command
if [[ $FAST != true ]];then
RUN="$RUN docker compose -f '$ROOT_PATH/docker-compose-backend.yml' build"
fi
RUN='cd $ROOT_PATH && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml build && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml up'
}

function start_proxy_backend {
RUN='cd $ROOT_PATH && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml build --build-arg="network_mode=proxy" && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml up'
function build_proxy_backend {
concat_command
move
concat_command
if [[ $FAST != true ]];then
RUN="$RUN docker compose -f '$ROOT_PATH/docker-compose-backend.yml' build --build-arg=\"network_mode=proxy\""
fi
}

function restart_proxy_backend {
RUN='sudo rm -rf "$ROOT_PATH"/api/static/object_store_data;
docker compose -f "$ROOT_PATH"/docker-compose-backend.yml down --volumes;
cd "$ROOT_PATH" && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml build --build-arg="network_mode=proxy" && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml up --force-recreate'
function start_backend {
concat_command
RUN="$RUN docker compose -f $ROOT_PATH/docker-compose-backend.yml up"
if [[ $SLOW == true ]];then
RUN="$RUN --force-recreate"
fi
}

function restart_backend {
RUN='sudo rm -rf "$ROOT_PATH"/api/static/object_store_data;
docker compose -f "$ROOT_PATH"/docker-compose-backend.yml down --volumes;
cd "$ROOT_PATH" && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml build && docker compose -f "$ROOT_PATH"/docker-compose-backend.yml up --force-recreate'
function drop_data {
concat_command
RUN="$RUN sudo rm -rf '$ROOT_PATH/api/static/object_store_data' && docker compose -f '$ROOT_PATH/docker-compose-backend.yml' down --volumes"
}

function rebuild_backend {
Expand All @@ -32,6 +48,3 @@ function rebuild_backend {
docker compose -f "$ROOT_PATH"/docker-compose-backend.yml down --volumes'
}

function up_backend {
RUN='docker compose -f "$ROOT_PATH"/docker-compose-backend.yml up'
}
36 changes: 30 additions & 6 deletions pc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ set -o nounset
# =============================================

if [[ $# -eq 0 ]] || [[ "$1" == "-h" ]]; then
echo "$(basename "$0") [-h] [-e env -b backend -f file c] -- program to deal with Pass Culture ecosystem
echo "$(basename "$0") [-h] [-e env -b backend -f file] c [--fast --force-recreate]
program to deal with Pass Culture ecosystem
where:
-h show this help text
-e specify environment to target (default: development)
-b specify backend to connect with local app (default: localhost)
-f file to upload to pod
-t specify version you want to deploy (create tag with this name)
--fast avoid rebuilding the docker images
--force-recreate force recreation of the docker images
c command that you want to run

Commands:
Expand Down Expand Up @@ -80,13 +83,25 @@ else
FILE_TO_UPLOAD=${FILE_TO_UPLOAD:-'none'}
fi

if [[ $# -gt 1 ]] && [[ "$2" == '--fast' ]]; then
FAST=true
else
FAST=false
fi

if [[ $# -gt 1 ]] && [[ "$2" == '--force-recreate' ]]; then
SLOW=true
else
SLOW=false
fi

CMD="$1"
shift

# =============================================
# Utilities functions
# =============================================

RUN=""
PRG="$BASH_SOURCE"

while [ -h "$PRG" ]; do
Expand Down Expand Up @@ -191,11 +206,18 @@ elif [[ "$CMD" == "psql-file" ]]; then
# Restart API after removing the database and files
elif [[ "$CMD" == "restart-backend" ]]; then
source "$INFRA_SCRIPTS_PATH"/start_backend.sh
restart_backend
SLOW=true
drop_data
build_backend
start_backend


elif [[ "$CMD" == "restart-proxy-backend" ]]; then
source "$INFRA_SCRIPTS_PATH"/start_backend.sh
restart_proxy_backend
SLOW=true
drop_data
build_proxy_backend
start_backend

# Clear all data in postgresql database
elif [[ "$CMD" == "reset-all-db" ]]; then
Expand All @@ -222,16 +244,18 @@ elif [[ "$CMD" == "restore-db" ]]; then
# Start API server with database and nginx server (builds the images first)
elif [[ "$CMD" == "start-backend" ]]; then
source "$INFRA_SCRIPTS_PATH"/start_backend.sh
build_backend
start_backend

elif [[ "$CMD" == "start-proxy-backend" ]]; then
source "$INFRA_SCRIPTS_PATH"/start_backend.sh
start_proxy_backend
build_proxy_backend
start_backend

# Start API server with database and nginx server (without building the images)
elif [[ "$CMD" == "up-backend" ]]; then
source "$INFRA_SCRIPTS_PATH"/start_backend.sh
up_backend
start_backend

# Commands to start API & Backoffice without docker
elif [[ "$CMD" == "setup-no-docker" ]]; then
Expand Down