diff --git a/src/main/resources/nubesgen/.github/workflows/gitops.yml.mustache b/src/main/resources/nubesgen/.github/workflows/gitops.yml.mustache index 61ef35e70..7e15bbd63 100644 --- a/src/main/resources/nubesgen/.github/workflows/gitops.yml.mustache +++ b/src/main/resources/nubesgen/.github/workflows/gitops.yml.mustache @@ -18,6 +18,12 @@ env: DOTNET_VERSION: '3.1' APP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root <%/runtimeDotnet%> +<%#runtimeNodejs%> + +env: + NODEJS_VERSION: '14' + APP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root +<%/runtimeNodejs%> <%#runtimeDocker%> env: @@ -321,16 +327,15 @@ jobs: <%/applicationTypeFunction%> <%/runtimeDotnet%> <%#runtimeNodejs%> - build-and-deploy: - needs: manage-infrastructure + build: runs-on: ubuntu-20.04 steps: - name: Checkout code uses: actions/checkout@v2 - - name: Use Node.js + - name: Use Node.js ${{ env.NODEJS_VERSION }} uses: actions/setup-node@v2 with: - node-version: '14' + node-version: ${{ env.NODEJS_VERSION }} - name: Cache NPM packages uses: actions/cache@v2 with: @@ -338,16 +343,39 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - - name: Install NPM + - name: Install NPM packages run: npm ci - name: Build the application - run: npm run build + run: npm run build --if-present - name: Run tests - run: npm run test + run: npm test --if-present + - name: Package application + run: | + PKG_FILE=$(npm pack ${{ env.APP_PACKAGE_PATH }} | tail -n1) + tar -xvf $PKG_FILE + cp -f ${{ env.APP_PACKAGE_PATH }}/package-lock.json package/ + cd package + npm ci --production + zip -r package.zip * + - name: Temporarily save package + uses: actions/upload-artifact@v2 + with: + name: package + path: './package' + retention-days: 1 + deploy: + needs: [manage-infrastructure, build] + runs-on: ubuntu-20.04 + steps: - name: Set environment variables run: | TAG_NAME=${GITHUB_REF#refs/*/} echo "ENVIRONMENT=${TAG_NAME:4}" >> $GITHUB_ENV + - name: Get built package + uses: actions/download-artifact@v2 + with: + name: package + path: ./package - name: Login to Azure uses: azure/login@v1 with: @@ -357,13 +385,13 @@ jobs: uses: azure/webapps-deploy@v2 with: app-name: app-<% applicationName %>-${{ env.ENVIRONMENT }}-001 - package: '.' + package: './package/package.zip' <%/applicationTypeAppService%> <%#applicationTypeFunction%> - name: 'Deploy to Azure Functions' uses: Azure/functions-action@v1 with: app-name: func-<% applicationName %>-${{ env.ENVIRONMENT }}-001 - package: '.' + package: './package/package.zip' <%/applicationTypeFunction%> <%/runtimeNodejs%> diff --git a/src/main/resources/nubesgen/terraform/modules/app-service/main.tf.mustache b/src/main/resources/nubesgen/terraform/modules/app-service/main.tf.mustache index f0244188e..9c4dc1d3f 100644 --- a/src/main/resources/nubesgen/terraform/modules/app-service/main.tf.mustache +++ b/src/main/resources/nubesgen/terraform/modules/app-service/main.tf.mustache @@ -99,6 +99,10 @@ resource "azurerm_app_service" "application" { app_settings = { "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" +{{#runtimeNodejs}} + "WEBSITE_RUN_FROM_PACKAGE" = "1" + "WEBSITE_NODE_DEFAULT_VERSION" = "~14" +{{/runtimeNodejs}} {{#runtimeDocker}} "DOCKER_REGISTRY_SERVER_URL" = "https://${azurerm_container_registry.container-registry.name}.azurecr.io" "DOCKER_REGISTRY_SERVER_USERNAME" = azurerm_container_registry.container-registry.admin_username diff --git a/src/test/resources/nubesgen/app-service-nodejs/.github/workflows/gitops.yml b/src/test/resources/nubesgen/app-service-nodejs/.github/workflows/gitops.yml index 8de5b918d..bfcdd5fae 100644 --- a/src/test/resources/nubesgen/app-service-nodejs/.github/workflows/gitops.yml +++ b/src/test/resources/nubesgen/app-service-nodejs/.github/workflows/gitops.yml @@ -12,6 +12,10 @@ on: branches: - 'env-*' +env: + NODEJS_VERSION: '14' + APP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root + jobs: manage-infrastructure: runs-on: ubuntu-20.04 @@ -53,16 +57,15 @@ jobs: -auto-approve \ -var="environment=$ENVIRONMENT" working-directory: '${{ github.workspace }}/terraform' - build-and-deploy: - needs: manage-infrastructure + build: runs-on: ubuntu-20.04 steps: - name: Checkout code uses: actions/checkout@v2 - - name: Use Node.js + - name: Use Node.js ${{ env.NODEJS_VERSION }} uses: actions/setup-node@v2 with: - node-version: '14' + node-version: ${{ env.NODEJS_VERSION }} - name: Cache NPM packages uses: actions/cache@v2 with: @@ -70,16 +73,39 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - - name: Install NPM + - name: Install NPM packages run: npm ci - name: Build the application - run: npm run build + run: npm run build --if-present - name: Run tests - run: npm run test + run: npm test --if-present + - name: Package application + run: | + PKG_FILE=$(npm pack ${{ env.APP_PACKAGE_PATH }} | tail -n1) + tar -xvf $PKG_FILE + cp -f ${{ env.APP_PACKAGE_PATH }}/package-lock.json package/ + cd package + npm ci --production + zip -r package.zip * + - name: Temporarily save package + uses: actions/upload-artifact@v2 + with: + name: package + path: './package' + retention-days: 1 + deploy: + needs: [manage-infrastructure, build] + runs-on: ubuntu-20.04 + steps: - name: Set environment variables run: | TAG_NAME=${GITHUB_REF#refs/*/} echo "ENVIRONMENT=${TAG_NAME:4}" >> $GITHUB_ENV + - name: Get built package + uses: actions/download-artifact@v2 + with: + name: package + path: ./package - name: Login to Azure uses: azure/login@v1 with: @@ -88,4 +114,4 @@ jobs: uses: azure/webapps-deploy@v2 with: app-name: app-nubesgen-testapp-app-service-nodejs-${{ env.ENVIRONMENT }}-001 - package: '.' + package: './package/package.zip' diff --git a/src/test/resources/nubesgen/app-service-nodejs/terraform/modules/app-service/main.tf b/src/test/resources/nubesgen/app-service-nodejs/terraform/modules/app-service/main.tf index a49b5e17b..887ad6942 100644 --- a/src/test/resources/nubesgen/app-service-nodejs/terraform/modules/app-service/main.tf +++ b/src/test/resources/nubesgen/app-service-nodejs/terraform/modules/app-service/main.tf @@ -40,6 +40,8 @@ resource "azurerm_app_service" "application" { app_settings = { "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" + "WEBSITE_RUN_FROM_PACKAGE" = "1" + "WEBSITE_NODE_DEFAULT_VERSION" = "~14" # These are app specific environment variables }