From 0a0b84a957a26b6bca65210b2b2ab081942ebd40 Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 14:49:26 -0500 Subject: [PATCH 1/7] Add preliminary CICD configuration for app service --- .github/workflows/cicd.yml | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..8cc5246 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,62 @@ +name: Deployments + +on: + push: + branches: + - dev + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14.x' + + - name: Install dependencies + run: npm install + + - name: Build the app + run: npm run build + + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: project-ricotta + slot-name: development + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: . + + build-and-deploy-to-production: + runs-on: ubuntu-latest + needs: build-and-deploy + if: github.ref == 'refs/heads/main' + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14.x' + + - name: Install dependencies + run: npm install + + - name: Build the app + run: npm run build + + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: project-ricotta + slot-name: production + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: . \ No newline at end of file From 98d0410e3c38b61c16086fd5c5dc355ced70f001 Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 15:10:25 -0500 Subject: [PATCH 2/7] Minor documentation fixes --- DEVELOPMENT.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index f7882a6..ca138a6 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -53,6 +53,7 @@ You can use Visual Studio Code or other tools to debug when developing locally w ### Execute commands inside the container If you need to execute a command inside the application's environment (such as for debugging): + 1. Start the app (see above). 2. `docker compose exec frontend /bin/sh` at the root of the repository. @@ -72,16 +73,16 @@ and your own: 1. Obtain the Super Linter Docker container: - `docker pull github/super-linter:latest` +`docker pull github/super-linter:latest` 2. Invoke Docker to run the Super Linter against your project directory with the included environment variables: - `docker run --env-file super-linter.env -v [path-to-project]:/tmp/lint github/super-linter` +`docker run --env-file super-linter.env -v [path-to-project]:/tmp/lint github/super-linter` -Where [path-to-project] is the path to your project. This can be a full or relative path. +Where `[path-to-project]` is the path to your project. This can be a full or relative path. For example, if you're currently in the top level project-ricotta directory you can run the linter with: - `docker run --env-file super-linter.env -v .:/tmp/lint github/super-linter` +`docker run --env-file super-linter.env -e FILTER_REGEX_INCLUDE=DEVELOPMENT.md -v .:/tmp/lint github/super-linter` To narrow the files to lint, pass the file(s) to run as a regular expression in the environment variable `FILTER_REGEX_INCLUDE`. To exclude file(s) pass an appropriate addition to the @@ -90,7 +91,7 @@ or supply the regular expression for the files you wish to include on the comman For example, to only lint the file DEVELOPMENT.md in the top level directory: - `docker run --env-file super-linter.env -e FILTER_REGEX_INCLUDE=DEVELOPMENT.md -v .:/tmp/lint github/super-linter` +`docker run --env-file super-linter.env -e FILTER_REGEX_INCLUDE=DEVELOPMENT.md -v .:/tmp/lint github/super-linter` Use UNIX-style paths with forward-slash \/ characters as path separators. See the [super-linter GitHub repository](https://github.com/github/super-linter/blob/main/README.md#filter-linted-files) @@ -99,6 +100,7 @@ for more information on how to specify files for super-linter runs. ## Architecture Software Stack: + - next.js - React - TypeScript From 404034310bee743d2e3826eb9473c486c37ca9da Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 15:12:01 -0500 Subject: [PATCH 3/7] Linter issues --- .github/workflows/cicd.yml | 79 +++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 8cc5246..a94f3d6 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -1,6 +1,7 @@ name: Deployments -on: +# For override below, see https://github.com/adrienverge/yamllint/issues/430 +on: # yamllint disable-line rule:truthy push: branches: - dev @@ -11,27 +12,27 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '14.x' + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14.x' - - name: Install dependencies - run: npm install + - name: Install dependencies + run: npm install - - name: Build the app - run: npm run build + - name: Build the app + run: npm run build - - name: Deploy to Azure App Service - uses: azure/webapps-deploy@v2 - with: - app-name: project-ricotta - slot-name: development - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - package: . + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: project-ricotta + slot-name: development + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: . build-and-deploy-to-production: runs-on: ubuntu-latest @@ -39,24 +40,24 @@ jobs: if: github.ref == 'refs/heads/main' steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '14.x' - - - name: Install dependencies - run: npm install - - - name: Build the app - run: npm run build - - - name: Deploy to Azure App Service - uses: azure/webapps-deploy@v2 - with: - app-name: project-ricotta - slot-name: production - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - package: . \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14.x' + + - name: Install dependencies + run: npm install + + - name: Build the app + run: npm run build + + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: project-ricotta + slot-name: production + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: . From e7d9d916420254e3c3d4f6875f1940492b8f4b41 Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 15:22:18 -0500 Subject: [PATCH 4/7] Further linting fixes --- .github/linters/.jscpd.json | 9 +++++++++ .github/workflows/cicd.yml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .github/linters/.jscpd.json diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json new file mode 100644 index 0000000..446e398 --- /dev/null +++ b/.github/linters/.jscpd.json @@ -0,0 +1,9 @@ +{ + "threshold": 0, + "reporters": ["html", "markdown"], + "ignore": [ + "**/.git/**", + "**/*.md", + "**/.github/**" + ] +} diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index a94f3d6..6212fcc 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -1,7 +1,7 @@ name: Deployments # For override below, see https://github.com/adrienverge/yamllint/issues/430 -on: # yamllint disable-line rule:truthy +on: # yamllint disable-line rule:truthy push: branches: - dev From 1132f95aa7a28519f01377a628007c85bb90c5cb Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 15:46:52 -0500 Subject: [PATCH 5/7] Update node version to app service supported ver --- .github/workflows/cicd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 6212fcc..0931a86 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: '14.x' + node-version: '18.x' - name: Install dependencies run: npm install @@ -46,7 +46,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: '14.x' + node-version: '18.x' - name: Install dependencies run: npm install From c4c333249dd822d57e2a099a94bb91b2d697313f Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 15:50:49 -0500 Subject: [PATCH 6/7] Update with Azure-provided deploy config --- .github/workflows/cicd.yml | 70 +++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 0931a86..e39600d 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -1,63 +1,57 @@ -name: Deployments +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions -# For override below, see https://github.com/adrienverge/yamllint/issues/430 +name: Build and deploy Node.js app to Azure Web App - projectricotta + + # For override below, see https://github.com/adrienverge/yamllint/issues/430 on: # yamllint disable-line rule:truthy push: branches: - - dev - main + workflow_dispatch: jobs: - build-and-deploy: + build: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Set up Node.js - uses: actions/setup-node@v2 + - name: Set up Node.js version + uses: actions/setup-node@v1 with: node-version: '18.x' - - name: Install dependencies - run: npm install - - - name: Build the app - run: npm run build + - name: npm install, build, and test + run: | + npm install + npm run build --if-present + npm run test --if-present - - name: Deploy to Azure App Service - uses: azure/webapps-deploy@v2 + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v2 with: - app-name: project-ricotta - slot-name: development - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - package: . + name: node-app + path: . - build-and-deploy-to-production: + deploy: runs-on: ubuntu-latest - needs: build-and-deploy - if: github.ref == 'refs/heads/main' + needs: build + environment: + name: 'production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v2 + - name: Download artifact from build job + uses: actions/download-artifact@v2 with: - node-version: '18.x' - - - name: Install dependencies - run: npm install - - - name: Build the app - run: npm run build + name: node-app - - name: Deploy to Azure App Service + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp uses: azure/webapps-deploy@v2 with: - app-name: project-ricotta - slot-name: production - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + app-name: 'projectricotta' + slot-name: 'production' + publish-profile: ${{ secrets.AzureAppService_PublishProfile_1234 }} package: . From 22138d42a9f4240826ba20375e848350c40e2108 Mon Sep 17 00:00:00 2001 From: Jonathan Roemer Date: Thu, 13 Jul 2023 15:57:02 -0500 Subject: [PATCH 7/7] Add development and production slot deploys --- .github/workflows/dev.yml | 54 ++++++++++++++++++++++++ .github/workflows/{cicd.yml => prod.yml} | 4 +- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/dev.yml rename .github/workflows/{cicd.yml => prod.yml} (95%) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..d44f903 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,54 @@ +name: Build and deploy Node.js app to Azure Web App - projectricotta(dev) + + # For override below, see https://github.com/adrienverge/yamllint/issues/430 +on: # yamllint disable-line rule:truthy + push: + branches: + - dev + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js version + uses: actions/setup-node@v1 + with: + node-version: '18.x' + + - name: npm install, build, and test + run: | + npm install + npm run build --if-present + npm run test --if-present + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v2 + with: + name: node-app + path: . + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'projectricotta-dev' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v2 + with: + name: node-app + + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'projectricotta-dev' + slot-name: 'projectricotta-dev' + publish-profile: ${{ secrets.AzureAppService_PublishProfile_f2f5546ef3b74ad88fb8ac0c8872bc6e }} + package: . diff --git a/.github/workflows/cicd.yml b/.github/workflows/prod.yml similarity index 95% rename from .github/workflows/cicd.yml rename to .github/workflows/prod.yml index e39600d..9a5db8f 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/prod.yml @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest needs: build environment: - name: 'production' + name: 'projectricotta' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: @@ -52,6 +52,6 @@ jobs: uses: azure/webapps-deploy@v2 with: app-name: 'projectricotta' - slot-name: 'production' + slot-name: 'projectricotta' publish-profile: ${{ secrets.AzureAppService_PublishProfile_1234 }} package: .