Commit fdb59959 authored by Egor Kremnev's avatar Egor Kremnev

add scripts

parent c61e88ee
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env bash
# shellcheck disable=SC2086
set -e
INSTANCE_NAME=${1}
LATEST_ARTIFACT_NAME=${2}
APPLICATION_ROOT_PATH=${3}
VERSION=$(cat ${APPLICATION_ROOT_PATH}/VERSION)
PROJECT_ROOT=${APPLICATION_ROOT_PATH}/application
BACKUP_DIR=/application_backups
# Create backup directory if not exist
mkdir -p ${BACKUP_DIR}
BACKUP_DATE=$(date +"%Y_%m_%d__%H_%M")
BACKUP_DIR_PATH=${BACKUP_DIR}/${PROJECT_ROOT}_backup_${BACKUP_DATE}_v${VERSION}
DB_PATH=${PROJECT_ROOT}/database/database.${INSTANCE_NAME}.sqlite
STASH_DB_DIR=/tmp/db/
STASH_DB_PATH=${STASH_DB_DIR}database.${INSTANCE_NAME}.sqlite
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)"
}
success() {
echo -e "\e[32m[Success] \e[32m $1 \e[39m $(for i in {12..21} ; do echo -en "\e[32;1;${i}m.\e[0m" ; done ; echo)"
}
if [[ "$(id -u)" != "0" ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
cd ${APPLICATION_ROOT_PATH}
mkdir -p ${STASH_DB_DIR}
info "# Creating backup"
if [[ -f ${DB_PATH} ]]; then
info "# Put db to temporary stash"
cp ${DB_PATH} ${STASH_DB_PATH}
fi
mkdir -p ${BACKUP_DIR_PATH}
mv ${PROJECT_ROOT} ${BACKUP_DIR_PATH}
info "# Extracting app package"
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 "# Setup permission for cache dir and storage"
chmod -R 777 ${PROJECT_ROOT}/storage/
chmod -R 777 ${PROJECT_ROOT}/bootstrap/cache
info "# Set user to .env file"
chown root: ${PROJECT_ROOT}/.env
info "# Set application key"
cd ${PROJECT_ROOT}
php artisan key:generate
info "# Optimizing Configuration Loading..."
php artisan config:cache
info "# Optimizing Route Loading"
php artisan route:cache
info "# Optimizing View Loading"
php artisan view:cache
info "# Database folder permission"
chmod -R 775 database
chown -R $(whoami) database
info "# Restart nginx server"
service nginx restart
cd ${APPLICATION_ROOT_PATH}
info "# Destroy archive ${LATEST_ARTIFACT_NAME}"
rm ${LATEST_ARTIFACT_NAME}
info "# Destroy VERSION file"
rm VERSION
info "# Destroy script"
rm apply-update.sh
success "Update successfully!"
#!/usr/bin/env bash
set -e
info() {
echo -e "\e[33m [Info] \e[33m$1 \e[39m"
}
success() {
echo -e "\e[32m [Success] \e[32m $1 \e[39m"
}
info "build started under user $(whoami)"
info "Install environment for unit tests"
cp .env.unit .env
info "Install requirements >>>>> "
composer install --no-interaction --prefer-dist
info "Generate application key >>>>>> "
php artisan key:generate
info "Start unit test >>>>> "
php artisan test
info "Setup environment for dusk test"
cp .env.dusk .env
info "Make database for testing"
touch database/database.unit.sqlite
touch database/database.dusk.sqlite
php artisan key:generate
php artisan dusk:chrome-driver
nohup bash -c "php artisan serve --env=dusk --port=4343 2>&1 &" && sleep 5
php artisan dusk
success "Completed testing!"
#!/usr/bin/env bash
set -e
BRANCH=${1}
VERSION=${2}
ENV_NAME=.env.${BRANCH}
info() {
echo -e "\e[33m[Info] \e[33m$1 \e[39m"
}
success() {
echo -e "\e[32m[Success] \e[32m $1 \e[39m"
}
info "./build.sh starts here..."
info "build started under user $(whoami)"
info "Clear all cache"
php artisan cache:clear
php artisan view:clear
php artisan config:clear
info "Install environment for server ${BRANCH}"
cp ${ENV_NAME} .env
info "Install requirements"
composer install --no-interaction --prefer-dist
info "Generate application key"
php artisan key:generate
info "Create directory 'artifacts' if not exists"
mkdir -p ${HOME}/artifacts
info "Create application artifact for version: ${VERSION}"
tar -czf ${HOME}/artifacts/application-${VERSION}.tar.gz \
--exclude=README.md \
--exclude=tests \
.
ls ${HOME}/artifacts/
success "Create package completed!"
#!/usr/bin/env bash
# shellcheck disable=SC2086
set -e
# IP or hostname, example: root@82.196.9.144 or root@example.com
HOST=${1}
# production, demo or staging etc...
INSTANCE_NAME=${2}
# Stable version
VERSION=${3}
PATH_TO_SCRIPTS_DIR=${4}/scripts
PATH_TO_NGINX_CONFIG_FILE=${PATH_TO_SCRIPTS_DIR}/nginx/default.conf
APPLICATION_ROOT_PATH=/home/deploy
# Archive name
LATEST_ARTIFACT_NAME=application-${VERSION}.tar.gz
# Path to archive
LATEST_ARTIFACT_PATH=${HOME}/artifacts/${LATEST_ARTIFACT_NAME}
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)"
}
success() {
echo -e "\e[32m[Success] \e[32m $1 \e[39m $(for i in {12..21} ; do echo -en "\e[32;1;${i}m>\e[0m" ; done ; echo)"
}
script_execution_dir=$(pwd)
info "Scripts run under ${script_execution_dir} directory"
scp ${PATH_TO_SCRIPTS_DIR}/apply-update.sh ${HOST}:${APPLICATION_ROOT_PATH}
scp ${PATH_TO_NGINX_CONFIG_FILE} ${HOST}:/etc/nginx/sites-available/default
scp ${LATEST_ARTIFACT_PATH} ${HOST}:${APPLICATION_ROOT_PATH}
echo ${VERSION} > VERSION
scp VERSION ${HOST}:${APPLICATION_ROOT_PATH}
# shellcheck disable=SC2087
ssh ${HOST} <<EOL
chmod +x apply-update.sh
${APPLICATION_ROOT_PATH}/apply-update.sh ${INSTANCE_NAME} ${LATEST_ARTIFACT_NAME} ${APPLICATION_ROOT_PATH}
EOL
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