generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SBERDOMA-211 add --import flag to import db dump from another app name
- Loading branch information
Showing
2 changed files
with
25 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,15 @@ | |
set -eo pipefail | ||
|
||
function escape { | ||
echo "$1" | tr A-Z a-z | sed "s/[^a-z0-9]/-/g" | sed "s/^-+\|-+$//g" | ||
echo "$1" | tr A-Z a-z | sed "s/[^a-z0-9]/-/g" | sed "s/^-+\|-+$//g" | ||
} | ||
|
||
function action { | ||
echo "!!===> $1" | ||
echo "!!===> $1" | ||
} | ||
|
||
function info { | ||
echo " $1" | ||
echo " $1" | ||
} | ||
|
||
function rollback { | ||
|
@@ -33,28 +33,32 @@ VERSION=$(escape $3) | |
BY_KEYWORD=$4 | ||
DOCKER_IMAGE=$5 | ||
|
||
if [[ "$6" == "--import" ]]; then | ||
IMPORT_DB_FROM_APP="$7" | ||
fi | ||
|
||
DOMAIN=${APP}.dev.doma.ai | ||
DESTROY_SCRIPT_PATH="~/do.${APP}.destroy.sh" | ||
RUN_AFTER_DEPLOY=false | ||
|
||
source .env | ||
|
||
if [[ -z "${DOCKER_COMPOSE_START_APP_COMMAND}" ]]; then | ||
echo "NO: DOCKER_COMPOSE_START_APP_COMMAND check .env" | ||
exit 1 | ||
echo "NO: DOCKER_COMPOSE_START_APP_COMMAND check .env" | ||
exit 1 | ||
fi | ||
if [[ -z "${DOCKER_COMPOSE_START_WORKER_COMMAND}" ]]; then | ||
echo "NO: DOCKER_COMPOSE_START_WORKER_COMMAND check .env" | ||
exit 1 | ||
echo "NO: DOCKER_COMPOSE_START_WORKER_COMMAND check .env" | ||
exit 1 | ||
fi | ||
if [[ -z "${DOCKER_COMPOSE_MIGRATION_COMMAND}" ]]; then | ||
echo "NO: DOCKER_COMPOSE_MIGRATION_COMMAND check .env" | ||
exit 1 | ||
echo "NO: DOCKER_COMPOSE_MIGRATION_COMMAND check .env" | ||
exit 1 | ||
fi | ||
if [[ -z "${SSH_DESTINATION}" ]] || [[ -z "${APP}" ]] || [[ "${BY_KEYWORD}" != "by" ]] || [[ -z "${DOCKER_IMAGE}" ]]; then | ||
echo "Use: $0 <SSH_DESTINATION> <APP-NAME> <APP-VERSION-NAME> by <DOCKER-IMAGE>" | ||
echo "Example: $0 [email protected] demo v1 by apps:demo" | ||
exit 1 | ||
echo "Use: $0 <SSH_DESTINATION> <APP-NAME> <APP-VERSION-NAME> by <DOCKER-IMAGE>" | ||
echo "Example: $0 [email protected] demo v1 by apps:demo" | ||
exit 1 | ||
fi | ||
|
||
echo "$(date +%Y-%m-%d-%H-%M-%S) - deploy.dev.sh $@ (APP=${APP}; VERSION=${VERSION})" | ||
|
@@ -99,6 +103,14 @@ fi | |
action "Deploy app ${APP} by ${DOCKER_IMAGE}" | ||
run "docker tag ${DOCKER_IMAGE} dokku/${APP}:${VERSION}" | ||
run "dokku tags:deploy ${APP} ${VERSION}" | ||
|
||
if [[ ! -z "${IMPORT_DB_FROM_APP}" ]]; then | ||
action "Import database from ${IMPORT_DB_FROM_APP}" | ||
run "dokku postgres:export ${IMPORT_DB_FROM_APP} > /tmp/temp.dump" || echo 'export error!' | ||
run "dokku postgres:import ${APP} < /tmp/temp.dump" || echo 'import error!' | ||
fi | ||
|
||
action "Run migrations" | ||
run "docker exec -u root ${APP}.web.1 ${DOCKER_COMPOSE_MIGRATION_COMMAND}" | ||
|
||
if [[ "$RUN_AFTER_DEPLOY" == "true" ]]; then | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,4 @@ jobs: | |
docker save apps:$SUBDOMAIN | bzip2 | pv | ssh [email protected] 'bunzip2 | docker load' | ||
# deploy by image | ||
bash ./.github/workflows/deploy.dev.sh [email protected] $SUBDOMAIN $VERSION by apps:$SUBDOMAIN | ||
# import database from condo app | ||
ssh [email protected] "dokku postgres:export condo > condo.dump" | ||
ssh [email protected] "dokku postgres:import $SUBDOMAIN < condo.dump" | ||
bash ./.github/workflows/deploy.dev.sh [email protected] $SUBDOMAIN $VERSION by apps:$SUBDOMAIN --import condo |