CI/CD drafting.

This commit is contained in:
Florian THIERRY
2024-09-19 18:03:23 +02:00
parent 0e2fb945a4
commit 610723c561
7 changed files with 173 additions and 4 deletions

95
ci.bash Normal file
View File

@@ -0,0 +1,95 @@
#!/bin/bash
SERVER_CODIKI_ROOT_FOLDER='/home/florian/codiki-hexagonal'
SERVER_ADDRESS='192.168.0.153'
SERVER_USER='florian'
SERVER_PORT='22'
function handle_error() {
local resultCode=$1
if [[ $resultCode -ne 0 ]]
then
echo "$errorMessage"
echo
exit 1
else
echo 'Operation succeded.'
echo
fi
}
function change_configuration_files() {
echo 'Copy production configuration file of backend...'
cp ./ci/configuration/backend/application-prod.yml ./backend/codiki-launcher/src/main/resources/application-prod.yml
handle_error $?
}
function build_backend() {
echo 'Backend docker image building...'
docker build -t codiki-backend -f ./Dockerfile-backend . --no-cache
handle_error $?
}
function build_frontend() {
echo 'Frontend docker image building...'
docker build -t codiki-frontend -f ./Dockerfile-frontend . --no-cache
handle_error $?
}
function extract_docker_images() {
echo 'Extraction of backend docker image into an archive...'
docker save codiki-backend:latest -o ./ci/bin/codiki-backend.tar
handle_error $?
echo 'Extraction of frontend docker image into an archive...'
docker save codiki-frontend:latest -o ./ci/bin/codiki-frontend.tar
handle_error $?
}
function copy_docker_compose_file_in_bin_folder() {
echo 'Copy of docker compose file in bin folder...'
cp ./docker-compose.yml ./ci/bin/docker-compose.yml
handle_error $?
}
function upload_files_on_server() {
echo 'Sending of docker images on server'
scp -P $SERVER_PORT ./ci/bin/* $SERVER_USER@$SERVER_ADDRESS:$SERVER_CODIKI_ROOT_FOLDER/
handle_error $?
}
# execute_remote_command_on_server
function ercos() {
local command=$1
ssh -p $SERVER_PORT -l $SERVER_USER $SERVER_ADDRESS $command
handle_error $1
}
function deploy_docker_images_on_server() {
echo 'Import backend docker image archive on server...'
ercos "docker load < $SERVER_CODIKI_ROOT_FOLDER/codiki-backend.tar"
echo 'Import frontend docker image archive on server...'
ercos "docker load < $SERVER_CODIKI_ROOT_FOLDER/codiki-frontend.tar"
}
function restart_services() {
echo 'Stop services on server...'
ercos "cd $SERVER_CODIKI_ROOT_FOLDER && docker compose down"
echo 'Start services on server...'
ercos "cd $SERVER_CODIKI_ROOT_FOLDER && docker compose up --detach"
}
function main() {
change_configuration_files
build_backend
build_frontend
extract_docker_images
copy_docker_compose_file_in_bin_folder
upload_files_on_server
deploy_docker_images_on_server
restart_services
}
main