Skip to content

Commit

Permalink
ci: init deployment using blue-green
Browse files Browse the repository at this point in the history
  • Loading branch information
wildan3105 committed Nov 18, 2024
1 parent ce304bc commit a75ecb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/deploy-blue-green.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,28 @@ jobs:
echo "Cloning the repository..."
rm -rf $TARGET_DIR
mkdir -p $TARGET_DIR
git clone ${{ env.PROJECT_REPO }} $TARGET_DIR
git clone -b chore/blue-green-deployment ${{ env.PROJECT_REPO }} $TARGET_DIR
echo "Repository cloned"
echo "Writing to environment variables..."
echo "ELASTIC_API_KEY=${{ secrets.ELASTIC_API_KEY }}" >> $TARGET_DIR/.env
echo "ELASTIC_BASE_URL=${{ secrets.ELASTIC_BASE_URL }}" >> $TARGET_DIR/.env
echo "TO_EMAIL=${{ secrets.TO_EMAIL }}" >> $TARGET_DIR/.env
echo "ENV=${{ secrets.ENV }}" >> $TARGET_DIR/.env
echo "TOKEN=${{ secrets.TOKEN }}" >> $TARGET_DIR/.env
echo "PORT=${{ secrets.PORT }}" >> $TARGET_DIR/.env
echo "Environment variables written"
echo "Install and build application..."
cd $TARGET_DIR
npm install
npm run build
echo "Dependencies installed and app built"
echo "Reading from env variables..."
if [ -f ".env" ]; then
export $(grep -v '^#' .env | xargs)
else
echo "Error: .env file not found!"
exit 1
fi
echo "Start or restart application via PM2..."
if pm2 list | grep -q "$TARGET_ENV"; then
echo "App detected. Restarting the app..."
Expand All @@ -99,6 +106,6 @@ jobs:
echo "Delay finished"
echo "Update nginx port..."
sudo sed -i "s|proxy_pass http://localhost:[0-9]*;|proxy_pass http://localhost:$TARGET_PORT;|" "${{ env.NGINX_CONF }}"
sudo nginx -s reload
# sudo sed -i "s|proxy_pass http://localhost:[0-9]*;|proxy_pass http://localhost:$TARGET_PORT;|" "${{ env.NGINX_CONF }}"
# sudo nginx -s reload
echo "Nginx updated"
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
},
"main": "index.js",
"scripts": {
"start-dev": "node_modules/.bin/pm2 start src/index.js --watch --name githublangs | gulp",
"start-prod": "node_modules/.bin/pm2 stop githublangs || true && node_modules/.bin/pm2 start -f src/index.js --name githublangs | gulp",
"start": "node src/index.js | gulp",
"lint": "eslint '**/*.js' --ignore-pattern node_modules/",
"lint:fix": "eslint --fix '**/*.js' --ignore-pattern node_modules/",
"mocha": "mocha",
Expand Down

0 comments on commit a75ecb3

Please sign in to comment.