From a64e499281eebfcf34021a2500724e9a4ddc0f87 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Fri, 22 Jul 2022 14:58:42 +0300 Subject: [PATCH 01/12] setup and configure deployment --- .deployment | 2 +- deploy.sh | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 deploy.sh diff --git a/.deployment b/.deployment index 46fe3b00..1e42f16c 100644 --- a/.deployment +++ b/.deployment @@ -1,2 +1,2 @@ [config] -SCM_DO_BUILD_DURING_DEPLOYMENT=false +command = bash deploy.sh \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..64f6db26 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# ---------------------- +# KUDU Deployment Script +# Version: 1.0.17 +# ---------------------- + +# Helpers +# ------- + +exitWithMessageOnError () { + if [ ! $? -eq 0 ]; then + echo "An error has occurred during web site deployment." + echo $1 + exit 1 + fi +} + +# Prerequisites +# ------------- + +# Verify node.js installed +hash node 2>/dev/null +exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment." + +# Setup +# ----- + +SCRIPT_DIR="${BASH_SOURCE[0]%\\*}" +SCRIPT_DIR="${SCRIPT_DIR%/*}" +ARTIFACTS=$SCRIPT_DIR/../artifacts +KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"} + +if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then + DEPLOYMENT_SOURCE=$SCRIPT_DIR +fi + +if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then + NEXT_MANIFEST_PATH=$ARTIFACTS/manifest + + if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then + PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH + fi +fi + +if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then + DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot +else + KUDU_SERVICE=true +fi + +if [[ ! -n "$KUDU_SYNC_CMD" ]]; then + # Install kudu sync + echo Installing Kudu Sync + npm install kudusync -g --silent + exitWithMessageOnError "npm failed" + + if [[ ! -n "$KUDU_SERVICE" ]]; then + # In case we are running locally this is the correct location of kuduSync + KUDU_SYNC_CMD=kuduSync + else + # In case we are running on kudu service this is the correct location of kuduSync + KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync + fi +fi + +# Node Helpers +# ------------ + +selectNodeVersion () { + if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then + SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\"" + eval $SELECT_NODE_VERSION + exitWithMessageOnError "select node version failed" + + if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then + NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"` + exitWithMessageOnError "getting node version failed" + fi + + if [[ -e "$DEPLOYMENT_TEMP/__npmVersion.tmp" ]]; then + NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"` + exitWithMessageOnError "getting npm version failed" + fi + + if [[ ! -n "$NODE_EXE" ]]; then + NODE_EXE=node + fi + + NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\"" + else + NPM_CMD=npm + NODE_EXE=node + fi +} + +################################################################################################################################## +# Deployment +# ---------- + +echo Handling node.js deployment. + +# 1. KuduSync +if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then + "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" + exitWithMessageOnError "Kudu Sync failed" +fi + +# 2. Select node version +selectNodeVersion + +# 3. Install npm packages +if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then + cd "$DEPLOYMENT_TARGET" + echo "Running yarn install --network-timeout 30000 --production" + eval yarn install --network-timeout 30000 --production + exitWithMessageOnError "yarn failed" + cd - > /dev/null +fi + +################################################################################################################################## +echo "Finished successfully." From 5e28bb1030c42aab8b18809041bfd0f41d6c2650 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Fri, 22 Jul 2022 14:59:36 +0300 Subject: [PATCH 02/12] update pipeline --- .../workflows/features-deployment_occdevvsfla.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/features-deployment_occdevvsfla.yml b/.github/workflows/features-deployment_occdevvsfla.yml index a6b6f65b..eb2c7e1f 100644 --- a/.github/workflows/features-deployment_occdevvsfla.yml +++ b/.github/workflows/features-deployment_occdevvsfla.yml @@ -7,7 +7,7 @@ on: push: branches: - develop - - features/deployment + - features/63792-pwa-deployment workflow_dispatch: jobs: @@ -27,15 +27,14 @@ jobs: yarn install --network-timeout=30000 yarn run build yarn run test - - - name: Zip artifact for deployment - run: zip release.zip ./ -r -x '*.git*' - name: Upload artifact for deployment job uses: actions/upload-artifact@v2 with: name: node-app - path: release.zip + path: | + . + !./node_modules deploy: runs-on: ubuntu-latest @@ -49,9 +48,6 @@ jobs: uses: actions/download-artifact@v2 with: name: node-app - - - name: unzip artifact for deployment - run: unzip release.zip - name: 'Deploy to Azure Web App' id: deploy-to-webapp From 2b077b59471ed32924c8876e280189f28e950e10 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Fri, 22 Jul 2022 15:34:24 +0300 Subject: [PATCH 03/12] try to setup node version --- .github/workflows/features-deployment_occdevvsfla.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/features-deployment_occdevvsfla.yml b/.github/workflows/features-deployment_occdevvsfla.yml index eb2c7e1f..e3e4e027 100644 --- a/.github/workflows/features-deployment_occdevvsfla.yml +++ b/.github/workflows/features-deployment_occdevvsfla.yml @@ -49,6 +49,11 @@ jobs: with: name: node-app + - name: Set up Node.js version + uses: actions/setup-node@v1 + with: + node-version: '16.x' + - name: 'Deploy to Azure Web App' id: deploy-to-webapp uses: azure/webapps-deploy@v2 From 9f6fdb3bc6a3d1632499dc843d82692e8c94218f Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Fri, 22 Jul 2022 16:30:00 +0300 Subject: [PATCH 04/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d01cfd6b..6ec0cf3a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "license": "MIT", "engines": { - "node": "16.x" + "node": "14.x" }, "scripts": { "build": "yarn build:api-client && yarn build:composables && yarn build:theme", From 15289abbdb9f872cad8c77109fafd7b9beefff5f Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Fri, 22 Jul 2022 16:30:29 +0300 Subject: [PATCH 05/12] Update features-deployment_occdevvsfla.yml --- .github/workflows/features-deployment_occdevvsfla.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/features-deployment_occdevvsfla.yml b/.github/workflows/features-deployment_occdevvsfla.yml index e3e4e027..553eb339 100644 --- a/.github/workflows/features-deployment_occdevvsfla.yml +++ b/.github/workflows/features-deployment_occdevvsfla.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Node.js version uses: actions/setup-node@v1 with: - node-version: '16.x' + node-version: '14.x' - name: yarn install, build, and test run: | @@ -49,11 +49,6 @@ jobs: with: name: node-app - - name: Set up Node.js version - uses: actions/setup-node@v1 - with: - node-version: '16.x' - - name: 'Deploy to Azure Web App' id: deploy-to-webapp uses: azure/webapps-deploy@v2 From f74d360e1f5f7f975aa1e5d9ac5b6c297995e399 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 10:20:32 +0300 Subject: [PATCH 06/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6ec0cf3a..d01cfd6b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "license": "MIT", "engines": { - "node": "14.x" + "node": "16.x" }, "scripts": { "build": "yarn build:api-client && yarn build:composables && yarn build:theme", From 8086632a0646db4b987c35a9fbef86cd01f4952d Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 10:26:15 +0300 Subject: [PATCH 07/12] Update features-deployment_occdevvsfla.yml --- .github/workflows/features-deployment_occdevvsfla.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/features-deployment_occdevvsfla.yml b/.github/workflows/features-deployment_occdevvsfla.yml index 553eb339..eb2c7e1f 100644 --- a/.github/workflows/features-deployment_occdevvsfla.yml +++ b/.github/workflows/features-deployment_occdevvsfla.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Node.js version uses: actions/setup-node@v1 with: - node-version: '14.x' + node-version: '16.x' - name: yarn install, build, and test run: | From 7305a945cc2c4e8859bc6a565b341add952c92ff Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 10:42:42 +0300 Subject: [PATCH 08/12] Update deploy.sh --- deploy.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 64f6db26..97a9c453 100644 --- a/deploy.sh +++ b/deploy.sh @@ -100,14 +100,18 @@ selectNodeVersion () { echo Handling node.js deployment. +## Force NPM Version +NPM_CMD="node /opt/nodejs/16.16.0/bin/npm" + # 1. KuduSync if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh" exitWithMessageOnError "Kudu Sync failed" fi +# disable selectNodeVersion # 2. Select node version -selectNodeVersion +#selectNodeVersion # 3. Install npm packages if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then From 3de8a8cc346cf8ba1abd5d92391529d6de9f80f4 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 11:07:24 +0300 Subject: [PATCH 09/12] Update deploy.sh --- deploy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 97a9c453..90956bf5 100644 --- a/deploy.sh +++ b/deploy.sh @@ -101,7 +101,8 @@ selectNodeVersion () { echo Handling node.js deployment. ## Force NPM Version -NPM_CMD="node /opt/nodejs/16.16.0/bin/npm" +NPM_CMD="node /opt/nodejs/16.13.1/bin/npm" +eval node -v # 1. KuduSync if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then From 96e88850e84b02c33d8049fac6be34aab5fda931 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 11:14:32 +0300 Subject: [PATCH 10/12] Update deploy.sh --- deploy.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy.sh b/deploy.sh index 90956bf5..e1efe5f9 100644 --- a/deploy.sh +++ b/deploy.sh @@ -103,6 +103,8 @@ echo Handling node.js deployment. ## Force NPM Version NPM_CMD="node /opt/nodejs/16.13.1/bin/npm" eval node -v +echo NODE_EXE +echo NPM_CMD # 1. KuduSync if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then From f9478d4d5a6baba3effe93401be1f8f384a00b62 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 11:37:03 +0300 Subject: [PATCH 11/12] Update deploy.sh --- deploy.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deploy.sh b/deploy.sh index e1efe5f9..de0ff7fb 100644 --- a/deploy.sh +++ b/deploy.sh @@ -103,8 +103,8 @@ echo Handling node.js deployment. ## Force NPM Version NPM_CMD="node /opt/nodejs/16.13.1/bin/npm" eval node -v -echo NODE_EXE -echo NPM_CMD +echo $NODE_EXE +echo $NPM_CMD # 1. KuduSync if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then @@ -116,7 +116,11 @@ fi # 2. Select node version #selectNodeVersion -# 3. Install npm packages +# 3. Install Yarn +echo Verifying Yarn Install. +eval $NPM_CMD install yarn -g + +# 4. Install yarn packages if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then cd "$DEPLOYMENT_TARGET" echo "Running yarn install --network-timeout 30000 --production" From 8ffc80a6c190a54d273578ac0c075b0bb6874554 Mon Sep 17 00:00:00 2001 From: Taras Nakonechnyi Date: Mon, 25 Jul 2022 11:46:20 +0300 Subject: [PATCH 12/12] Update deploy.sh --- deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy.sh b/deploy.sh index de0ff7fb..ab1c4cde 100644 --- a/deploy.sh +++ b/deploy.sh @@ -105,6 +105,7 @@ NPM_CMD="node /opt/nodejs/16.13.1/bin/npm" eval node -v echo $NODE_EXE echo $NPM_CMD +eval ls /opt/nodejs/ # 1. KuduSync if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then