Skip to content

Commit

Permalink
feat: add platform_build_and_push to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidZORO committed Jun 26, 2020
1 parent f3ac5e0 commit 0a0dc2b
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/leaa-api/ecosystem.config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ module.exports = {
env: { NODE_ENV: 'production' },
path: '/var/www/leaa-api',
'pre-setup': `
echo ----PRE---- &&
echo ----PRE---- &&
echo ----PRE---- &&
echo ----PRE---- &&
echo ----API-PRE---- &&
echo ----API-PRE---- &&
echo ----API-PRE---- &&
echo ----API-PRE---- &&
pwd &&
ls -la &&
echo ----PRE---- &&
echo ----PRE---- &&
echo ----PRE---- &&
echo ----PRE----
echo ----API-PRE---- &&
echo ----API-PRE---- &&
echo ----API-PRE---- &&
echo ----API-PRE----
`,
'post-deploy': `
echo -------- &&
Expand Down
61 changes: 57 additions & 4 deletions packages/leaa-dashboard/deploy-dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

cd "$(dirname "$0")" || exit

__DEPLOY__="./_deploy"
__DEPLOY_GIT_BRANCH__="dashboard"

__ABS_PATH__="$(cd "$(dirname "$0")";pwd)" || exit
__DEPLOY__="$__ABS_PATH__/_deploy"

unset PLATFORM SKIP_BUILD

usage() {
# -p = platform
# -i = ignore yarn build
# -S = Setup (pm2)

# shellcheck disable=SC2028
echo "\n\n
🔰 Usage: $0 -p (local_test | only_build | vercel) [-i] [-S]
🔰 Usage: $0 -p (local_test | only_build | build_and_push | vercel) [-i] [-S]
\n
-p platform
-i skip yarn build
-y skip confirm
-S Setup (init PM2 deploy)
\n
e.g. sh $0 -p vercel
\n\n"
Expand All @@ -28,7 +37,7 @@ set_var() {

if [ -z "${!arg_name}" ]; then
if [ "$arg_name" = "PLATFORM" ]; then
if echo "$*" | grep -Eq '^local_test|only_build|vercel$'; then
if echo "$*" | grep -Eq '^local_test|only_build|build_and_push|vercel$'; then
eval "$arg_name=\"$*\""
else
usage
Expand All @@ -43,15 +52,58 @@ set_var() {
eval "$arg_name=\"$*\""
fi

if [ "$arg_name" = "PM2_SETUP" ]; then
eval "$arg_name=\"$*\""
fi

else
echo "Error: $arg_name already set"
usage
fi
}

__cd_deploy() {
pwd
cd ${__DEPLOY__} || exit
}

__init_config_file() {
DEPLOY_DOTENV_FILE="$__DEPLOY__/_env.js"
if [ -f $DEPLOY_DOTENV_FILE ]; then
# shellcheck disable=SC2028
printf "\n👌 Already %s, do NOT Copy :)\n\n" $DEPLOY_DOTENV_FILE
else
cp -f ./_env.js $DEPLOY_DOTENV_FILE
fi

if [ -f "./ecosystem.config.js" ]; then
cp -f ./ecosystem.config.js ${__DEPLOY__}
else
printf '⚠️ Please rename ecosystem.config.js.example to ecosystem.config.js first \n'
fi
}

platform_build_and_push() {
__cd_deploy

pwd
GIT_MESSAGE_STR=$(cat <./version.txt | sed 's/["{}]//g' | sed 's/[,]/ /g')
# GIT_MESSAGE_HASH=$(head /dev/urandom | tr -dc A-Z0-9 | head -c 4 ; echo '')
GIT_MESSAGE_HASH=$(openssl rand -hex 2 | awk '{print toupper($0)}')
GIT_MESSAGE="$GIT_MESSAGE_STR <$GIT_MESSAGE_HASH>"

git status
git add -A
git commit -m "ci: $GIT_MESSAGE"
git checkout -b $__DEPLOY_GIT_BRANCH__
git push -u origin $__DEPLOY_GIT_BRANCH__ -f

printf "\n\n\n📮 Push To Deploy Repo <%s> Completed!\n\n\n" $__DEPLOY_GIT_BRANCH__
}

platform_vercel() {
cp -fr ./tools/deploy-config/vercel/* ${__DEPLOY__}
cd ${__DEPLOY__} || exit
__cd_deploy
mv robots.example.txt robots.txt

vercel --prod -c
Expand Down Expand Up @@ -127,6 +179,7 @@ case "$SKIP_CONFIRM" in
case $PLATFORM in
local_test) platform_local_test ;;
only_build) platform_only_build ;;
build_and_push) platform_build_and_push ;;
vercel) platform_vercel ;;
*) usage ;; esac
fi
Expand Down
38 changes: 38 additions & 0 deletions packages/leaa-dashboard/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
// for pm2 deploy (remote server exec pull and deploy)
// https://pm2.keymetrics.io/docs/usage/deployment/
deploy: {
dashboard: {
host: '47.90.57.225',
port: '22',
user: 'www-data',
ref: 'origin/dashboard',
repo: 'git@code.aliyun.com:solidzoro/deploy-leaa.git',
env: { NODE_ENV: 'production' },
path: '/var/www/leaa-dashboard',
'pre-setup': `
echo ----DASHBOARD-PRE---- &&
echo ----DASHBOARD-PRE---- &&
echo ----DASHBOARD-PRE---- &&
echo ----DASHBOARD-PRE---- &&
pwd &&
ls -la &&
echo ----DASHBOARD-PRE---- &&
echo ----DASHBOARD-PRE---- &&
echo ----DASHBOARD-PRE---- &&
echo ----DASHBOARD-PRE----
`,
'post-deploy': `
echo -------- &&
pwd &&
echo - &&
ls -la &&
echo --------
`,
},
},
};

// &&
// docker-compose down &&
// docker-compose up
34 changes: 34 additions & 0 deletions packages/leaa-dashboard/ecosystem.config.js.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
// for pm2 deploy (remote server exec pull and deploy)
// https://pm2.keymetrics.io/docs/usage/deployment/
deploy: {
api: {
host: '111.111.111.111',
port: '22',
user: 'www-data',
ref: 'origin/dashboard',
repo: 'git@xxxxxxxx.com:aaaa/bbbb.git',
env: { NODE_ENV: 'production' },
path: '/var/www/leaa-dashboard',
'pre-setup': `
echo ----DASHBOARD---- &&
echo ----DASHBOARD---- &&
echo ----DASHBOARD---- &&
echo ----DASHBOARD---- &&
pwd &&
ls -la &&
echo ----DASHBOARD---- &&
echo ----DASHBOARD---- &&
echo ----DASHBOARD---- &&
echo ----DASHBOARD----
`,
'post-deploy': `
echo -------- &&
pwd &&
echo - &&
ls -la &&
echo --------
`,
},
},
};
1 change: 1 addition & 0 deletions packages/leaa-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dev": "NODE_ENV=development yarn dev-server",
"clear": "cross-env rimraf _dist",
"---------------------------------------------------------------------- PROD ----": "----",
"postbuild": "node ./tools/cli/gen-version.js",
"build": "yarn clear && NODE_ENV=production cross-env webpack --config ./tools/webpack/webpack.config.js --progress --release",
"---------------------------------------------------------------------- ALIAS ----": "----",
"commit": "git-cz",
Expand Down
29 changes: 29 additions & 0 deletions packages/leaa-dashboard/tools/cli/gen-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const moment = require('moment');
const childProcess = require('child_process');

const pkg = require('../../package.json');

const getGitVersion = (childProcess.execSync('git rev-parse HEAD') || '').toString().substr(0, 4);
const getProjectVersion = pkg.version;
const getVersion = `v${getProjectVersion} (${getGitVersion})`;

const DIST_PUBLIC_DIR = path.resolve(__dirname, '../../_dist');
const DIST_FILE_PATH = `${DIST_PUBLIC_DIR}/version.txt`;

const buildInfo = {
VERSION: getVersion,
BUILDTIME: moment().format('YYYYMMDD-HHmmss'),
};

if (!fs.existsSync(DIST_PUBLIC_DIR)) {
console.log(`NEED mkdirp ----> ${DIST_PUBLIC_DIR}`);

mkdirp(DIST_PUBLIC_DIR, (err) => err && console.log(JSON.stringify(err)));
}

console.log('\n\n🌈 DONE-GEN-VERSION-FILE', '\n\n');

fs.writeFileSync(DIST_FILE_PATH, JSON.stringify(buildInfo));

0 comments on commit 0a0dc2b

Please sign in to comment.