Commit 44a170c1 authored by Egor Kremnev's avatar Egor Kremnev

fix scripts

parent 8e2cf8cd
......@@ -27,7 +27,8 @@ mkdir -p ${BACKUP_DIR}
BACKUP_DATE=$(date +"%Y_%m_%d__%H_%M")
BACKUP_DIR_PATH=${BACKUP_DIR}/${PROJECT_ROOT}_backup_${BACKUP_DATE}_v${VERSION}
# sudo mysqldump -u [user] -p [database_name] > [filename].sql
DB_DUMP_DIR=${APPLICATION_ROOT_PATH}/dumps/
DB_DUMP_PATH=${DB_DUMP_DIR}backup_${BACKUP_DATE}_v${VERSION}.sql
info() {
echo -e "\e[33m[Info] \e[33m$1 \e[39m $(for i in {12..21} ; do echo -en "\e[33;1;${i}m.\e[0m" ; done ; echo)"
......@@ -39,7 +40,7 @@ success() {
cd ${APPLICATION_ROOT_PATH}
mkdir -p ${STASH_DB_DIR}
mkdir -p ${DB_DUMP_DIR}
info "# Creating backup"
if [[ -f ${DB_PATH} ]]; then
......@@ -55,10 +56,27 @@ fi
info "# Extracting app package to ${PROJECT_ROOT}"
mkdir -p ${PROJECT_ROOT}
tar -xzf ${LATEST_ARTIFACT_NAME} -C ${PROJECT_ROOT}
if [[ -f ${STASH_DB_PATH} ]]; then
info "# Restore DB from stash"
mv ${STASH_DB_PATH} ${DB_PATH}
fi
info "# Set environments"
env
sed -i '' 's/^#DB_HOST=/DB_HOST=/g' ".env"
sed -i '' 's/^\(DB_HOST=\).*/\1'$([ -n "$DB_HOST_ENV" ] && echo "$DB_HOST_ENV" || echo "$DB_HOST")'/' ".env"
sed -i '' 's/^#DB_PORT=/DB_PORT=/g' ".env"
sed -i '' 's/^\(DB_PORT=\).*/\1'$([ -n "$DB_PORT_ENV" ] && echo "$DB_PORT_ENV" || echo "$DB_PORT")'/' ".env"
sed -i '' 's/^#DB_DATABASE=/DB_DATABASE=/g' ".env"
sed -i '' 's/^\(DB_DATABASE=\).*/\1'$([ -n "$DB_DATABASE_ENV" ] && echo "$DB_DATABASE_ENV" || echo "$DB_DATABASE")'/' ".env"
sed -i '' 's/^#DB_USERNAME=/DB_USERNAME=/g' ".env"
sed -i '' 's/^\(DB_USERNAME=\).*/\1'$([ -n "$DB_USERNAME_ENV" ] && echo "$DB_USERNAME_ENV" || echo "$DB_USERNAME")'/' ".env"
sed -i '' 's/^#DB_PASSWORD=/DB_PASSWORD=/g' ".env"
sed -i '' 's/^\(DB_PASSWORD=\).*/\1'$([ -n "$DB_PASSWORD_ENV" ] && echo "$DB_PASSWORD_ENV" || echo "$DB_PASSWORD")'/' ".env"
info "# Create database backup"
mysqldump -u $([ -n "$DB_DATABASE_ENV" ] && echo "$DB_DATABASE_ENV" || echo "$DB_DATABASE") > DB_DUMP_PATH
info "# Setup permission for cache dir and storage"
chmod -R 777 ${PROJECT_ROOT}/storage/
......@@ -80,27 +98,6 @@ php artisan route:cache
info "# Optimizing View Loading"
php artisan view:cache
info "# Database folder permission"
chmod -R 775 database
chown -R $(whoami) database
env
sed -i '' 's/^#DB_HOST=/DB_HOST=/g' ".env"
sed -i '' 's/^\(DB_HOST=\).*/\1'$([ -n "$DB_HOST_ENV" ] && echo "$DB_HOST_ENV" || echo "$DB_HOST")'/' ".env"
sed -i '' 's/^#DB_PORT=/DB_PORT=/g' ".env"
sed -i '' 's/^\(DB_PORT=\).*/\1'$([ -n "$DB_PORT_ENV" ] && echo "$DB_PORT_ENV" || echo "$DB_PORT")'/' ".env"
sed -i '' 's/^#DB_DATABASE=/DB_DATABASE=/g' ".env"
sed -i '' 's/^\(DB_DATABASE=\).*/\1'$([ -n "$DB_DATABASE_ENV" ] && echo "$DB_DATABASE_ENV" || echo "$DB_DATABASE")'/' ".env"
sed -i '' 's/^#DB_USERNAME=/DB_USERNAME=/g' ".env"
sed -i '' 's/^\(DB_USERNAME=\).*/\1'$([ -n "$DB_USERNAME_ENV" ] && echo "$DB_USERNAME_ENV" || echo "$DB_USERNAME")'/' ".env"
sed -i '' 's/^#DB_PASSWORD=/DB_PASSWORD=/g' ".env"
sed -i '' 's/^\(DB_PASSWORD=\).*/\1'$([ -n "$DB_PASSWORD_ENV" ] && echo "$DB_PASSWORD_ENV" || echo "$DB_PASSWORD")'/' ".env"
php artisan migrate --seed # Выполним посев
info "# Restart nginx server"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment