From 24b59d1bbd1f1f48da72f3275338350c584f72e6 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:29:40 +0300 Subject: [PATCH 1/5] fix deploy staging --- .github/workflows/main_syncrow(staging).yml | 76 ++++++++++----------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main_syncrow(staging).yml b/.github/workflows/main_syncrow(staging).yml index 952632a..c926795 100644 --- a/.github/workflows/main_syncrow(staging).yml +++ b/.github/workflows/main_syncrow(staging).yml @@ -1,4 +1,7 @@ -name: Backend deployment to Azure App Service +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy container app to Azure Web App - syncrow(test) on: push: @@ -6,50 +9,43 @@ on: - main workflow_dispatch: -env: - AZURE_WEB_APP_NAME: 'syncrow' - AZURE_WEB_APP_SLOT_NAME: 'staging' - ACR_REGISTRY: 'syncrow.azurecr.io' - IMAGE_NAME: 'backend' - IMAGE_TAG: 'latest' - jobs: - build_and_deploy: - runs-on: ubuntu-latest + build: + runs-on: 'ubuntu-latest' steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v2 - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Install dependencies and build project - run: | - npm install - npm run build + - name: Log in to registry + uses: docker/login-action@v2 + with: + registry: https://syncrow.azurecr.io/ + username: ${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }} + password: ${{ secrets.AzureAppService_ContainerPassword_3cfcef3755ed46eda766dfc7059dcf5e }} - - name: Log in to Azure - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Build and push container image to registry + uses: docker/build-push-action@v3 + with: + push: true + tags: syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}/backend:${{ github.sha }} + file: ./Dockerfile - - name: Log in to Azure Container Registry - run: az acr login --name ${{ env.ACR_REGISTRY }} + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'test' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - name: List build output - run: ls -R dist/ - - - name: Build and push Docker image - run: | - docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} - docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} - - - name: Set Web App with Docker container - run: | - az webapp config container set \ - --name ${{ env.AZURE_WEB_APP_NAME }} \ - --resource-group backend \ - --docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \ - --docker-registry-server-url https://${{ env.ACR_REGISTRY }} + steps: + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'syncrow' + slot-name: 'main' + publish-profile: ${{ secrets.AzureAppService_PublishProfile_cfa029d9d3a84172a06cfe47c05c18ca }} + images: 'syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}/backend:${{ github.sha }}' \ No newline at end of file From e333a400198e4a308138f0eed90293817a42f11a Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:34:23 +0300 Subject: [PATCH 2/5] Refactor GitHub Actions workflow for backend deployment to Azure App Service --- .github/workflows/main_syncrow(staging).yml | 84 +++++++++++---------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main_syncrow(staging).yml b/.github/workflows/main_syncrow(staging).yml index c926795..952632a 100644 --- a/.github/workflows/main_syncrow(staging).yml +++ b/.github/workflows/main_syncrow(staging).yml @@ -1,7 +1,4 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy -# More GitHub Actions for Azure: https://github.com/Azure/actions - -name: Build and deploy container app to Azure Web App - syncrow(test) +name: Backend deployment to Azure App Service on: push: @@ -9,43 +6,50 @@ on: - main workflow_dispatch: +env: + AZURE_WEB_APP_NAME: 'syncrow' + AZURE_WEB_APP_SLOT_NAME: 'staging' + ACR_REGISTRY: 'syncrow.azurecr.io' + IMAGE_NAME: 'backend' + IMAGE_TAG: 'latest' + jobs: - build: - runs-on: 'ubuntu-latest' - - steps: - - uses: actions/checkout@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to registry - uses: docker/login-action@v2 - with: - registry: https://syncrow.azurecr.io/ - username: ${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }} - password: ${{ secrets.AzureAppService_ContainerPassword_3cfcef3755ed46eda766dfc7059dcf5e }} - - - name: Build and push container image to registry - uses: docker/build-push-action@v3 - with: - push: true - tags: syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}/backend:${{ github.sha }} - file: ./Dockerfile - - deploy: + build_and_deploy: runs-on: ubuntu-latest - needs: build - environment: - name: 'test' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v2 - with: - app-name: 'syncrow' - slot-name: 'main' - publish-profile: ${{ secrets.AzureAppService_PublishProfile_cfa029d9d3a84172a06cfe47c05c18ca }} - images: 'syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_e7578d2a094946609a4506f293c7c645 }}/backend:${{ github.sha }}' \ No newline at end of file + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies and build project + run: | + npm install + npm run build + + - name: Log in to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Log in to Azure Container Registry + run: az acr login --name ${{ env.ACR_REGISTRY }} + + - name: List build output + run: ls -R dist/ + + - name: Build and push Docker image + run: | + docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + + - name: Set Web App with Docker container + run: | + az webapp config container set \ + --name ${{ env.AZURE_WEB_APP_NAME }} \ + --resource-group backend \ + --docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \ + --docker-registry-server-url https://${{ env.ACR_REGISTRY }} From 5500910391421c0df962b438f14780b747d04439 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:48:09 +0300 Subject: [PATCH 3/5] Add or update the App Service deployment workflow configuration from Azure Portal. --- .github/workflows/main_syncrow(staging).yml | 76 ++++++++++----------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main_syncrow(staging).yml b/.github/workflows/main_syncrow(staging).yml index 952632a..0d29d1b 100644 --- a/.github/workflows/main_syncrow(staging).yml +++ b/.github/workflows/main_syncrow(staging).yml @@ -1,4 +1,7 @@ -name: Backend deployment to Azure App Service +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy container app to Azure Web App - syncrow(staging) on: push: @@ -6,50 +9,43 @@ on: - main workflow_dispatch: -env: - AZURE_WEB_APP_NAME: 'syncrow' - AZURE_WEB_APP_SLOT_NAME: 'staging' - ACR_REGISTRY: 'syncrow.azurecr.io' - IMAGE_NAME: 'backend' - IMAGE_TAG: 'latest' - jobs: - build_and_deploy: - runs-on: ubuntu-latest + build: + runs-on: 'ubuntu-latest' steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v2 - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Install dependencies and build project - run: | - npm install - npm run build + - name: Log in to registry + uses: docker/login-action@v2 + with: + registry: https://syncrow.azurecr.io/ + username: ${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }} + password: ${{ secrets.AzureAppService_ContainerPassword_e7b0ff54f54d44cba04a970a22384848 }} - - name: Log in to Azure - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Build and push container image to registry + uses: docker/build-push-action@v3 + with: + push: true + tags: syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}/syncrow/backend:${{ github.sha }} + file: ./Dockerfile - - name: Log in to Azure Container Registry - run: az acr login --name ${{ env.ACR_REGISTRY }} + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'staging' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - name: List build output - run: ls -R dist/ - - - name: Build and push Docker image - run: | - docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} - docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} - - - name: Set Web App with Docker container - run: | - az webapp config container set \ - --name ${{ env.AZURE_WEB_APP_NAME }} \ - --resource-group backend \ - --docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \ - --docker-registry-server-url https://${{ env.ACR_REGISTRY }} + steps: + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'syncrow' + slot-name: 'staging' + publish-profile: ${{ secrets.AzureAppService_PublishProfile_44f7766441ec4796b74789e9761ef589 }} + images: 'syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}/syncrow/backend:${{ github.sha }}' \ No newline at end of file From 2253be74d0f181be3c706cb282cf6852b69f0105 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:57:56 +0300 Subject: [PATCH 4/5] remove defaultProfilePicture --- libs/common/src/modules/user/entities/user.entity.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/common/src/modules/user/entities/user.entity.ts b/libs/common/src/modules/user/entities/user.entity.ts index 5b754e8..bab2420 100644 --- a/libs/common/src/modules/user/entities/user.entity.ts +++ b/libs/common/src/modules/user/entities/user.entity.ts @@ -7,7 +7,6 @@ import { UserRoleEntity } from '../../user-role/entities'; import { DeviceNotificationEntity } from '../../device-notification/entities'; import { UserNotificationEntity } from '../../user-notification/entities'; import { DeviceEntity } from '../../device/entities'; -import { defaultProfilePicture } from '@app/common/constants/default.profile.picture'; import { RegionEntity } from '../../region/entities'; import { TimeZoneEntity } from '../../timezone/entities'; @@ -23,7 +22,7 @@ export class UserEntity extends AbstractEntity { @Column({ nullable: true, type: 'text', - default: defaultProfilePicture, + default: '', }) public profilePicture: string; From c2a6260e25c198842ddee220feed08b8176a6cf6 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:04:19 +0300 Subject: [PATCH 5/5] Add default profile picture to UserEntity --- libs/common/src/modules/user/entities/user.entity.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/common/src/modules/user/entities/user.entity.ts b/libs/common/src/modules/user/entities/user.entity.ts index bab2420..5b754e8 100644 --- a/libs/common/src/modules/user/entities/user.entity.ts +++ b/libs/common/src/modules/user/entities/user.entity.ts @@ -7,6 +7,7 @@ import { UserRoleEntity } from '../../user-role/entities'; import { DeviceNotificationEntity } from '../../device-notification/entities'; import { UserNotificationEntity } from '../../user-notification/entities'; import { DeviceEntity } from '../../device/entities'; +import { defaultProfilePicture } from '@app/common/constants/default.profile.picture'; import { RegionEntity } from '../../region/entities'; import { TimeZoneEntity } from '../../timezone/entities'; @@ -22,7 +23,7 @@ export class UserEntity extends AbstractEntity { @Column({ nullable: true, type: 'text', - default: '', + default: defaultProfilePicture, }) public profilePicture: string;