From 2d8c7fba90ff555014fa59ab388d5abc2f4dd4b6 Mon Sep 17 00:00:00 2001 From: sumedh Date: Thu, 7 Nov 2024 18:33:56 +0530 Subject: [PATCH 1/5] hermione deployment file added --- hermione-deployment.yaml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 hermione-deployment.yaml diff --git a/hermione-deployment.yaml b/hermione-deployment.yaml new file mode 100644 index 0000000..96a7de7 --- /dev/null +++ b/hermione-deployment.yaml @@ -0,0 +1,31 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + name: hermione + namespace: olympus +spec: + replicas: 1 + selector: + matchLabels: + app: hermione + template: + metadata: + labels: + app: hermione + spec: + containers: + - name: hermione + image: olympusreg.azurecr.io/hermione:a843dee4 + envFrom: + - configMapRef: + name: olympus-db-shared-cfg + env: + - name: HERMIONE_FE_URL + value: http://hermione-aks.olympusai.live + - name: ARIADNE_FE_URL + value: http://ariadne-aks.olympusai.live + - name: EUREKA_URI + value: >- + http://eureka-server-service.olympus.svc.cluster.local:8761/eureka + resources: {} + imagePullPolicy: Always \ No newline at end of file From d8731181f19f470107311206c4302a247d9324a4 Mon Sep 17 00:00:00 2001 From: "shamrao shinde, sumedh" Date: Thu, 7 Nov 2024 13:07:27 +0000 Subject: [PATCH 2/5] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..b914b59 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,70 @@ +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java +trigger: +- master +pool: + name: azureselfhosted +variables: + dockerRegistryServiceConnection: 'docker-registry-olympus' + imageName: 'hermione-fe' # Replace with your Docker image name + shortCommitSha: '' # Initialize variable for short commit SHA +steps: +- checkout: self # Check out the pipeline repository (optional) + +# Extract the short commit SHA +- script: | + echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)" + displayName: 'Set Short Commit SHA' +- script: | + echo "Building the first repository..." + ls -lrth + displayName: 'List hermione-fe directory' + +- script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images1' + +- task: Docker@2 + displayName: Build + inputs: + command: build + containerRegistry: $(dockerRegistryServiceConnection) + repository: '$(imageName)' + tags: '$(shortCommitSha)' + Dockerfile: 'Dockerfile' + arguments: '--build-arg VITE_BACKEND_URL=http://olympus-api-gateway-aks.olympusai.live/hermione' + +- task: Docker@2 + displayName: Push + inputs: + command: push + containerRegistry: $(dockerRegistryServiceConnection) + repository: '$(imageName)' + tags: '$(shortCommitSha)' + +- script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images' +- script: | + echo "Updating imageName in dpeloyment.yaml" + echo "Before Substitution" + cat hermione-fe-deployment.yaml + echo "###############################################" + echo "current shell: $SHELL" + echo "imagename bracket : $(imageName)" + echo "###############################################" + sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" hermione-fe-deployment.yaml + echo "After Substitution" + cat hermione-fe-deployment.yaml + displayName: 'Update ImageName in YAML file' +- script: | + echo "deployment using kubectl" + kubectl apply -f hermione-fe-deployment.yaml + displayName: 'deployment using kubectl' +- script: | + echo "remove the docker images..." + docker rmi $(docker images -q) + displayName: 'remove docker images' \ No newline at end of file From 47d7b1676d2bc7796ad304dd2738f13d239e85f1 Mon Sep 17 00:00:00 2001 From: sumedh Date: Thu, 7 Nov 2024 18:43:07 +0530 Subject: [PATCH 3/5] deployment file modified --- hermione-deployment.yaml | 31 ------------------------------- hermione-fe-deployment.yaml | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 hermione-deployment.yaml create mode 100644 hermione-fe-deployment.yaml diff --git a/hermione-deployment.yaml b/hermione-deployment.yaml deleted file mode 100644 index 96a7de7..0000000 --- a/hermione-deployment.yaml +++ /dev/null @@ -1,31 +0,0 @@ -kind: Deployment -apiVersion: apps/v1 -metadata: - name: hermione - namespace: olympus -spec: - replicas: 1 - selector: - matchLabels: - app: hermione - template: - metadata: - labels: - app: hermione - spec: - containers: - - name: hermione - image: olympusreg.azurecr.io/hermione:a843dee4 - envFrom: - - configMapRef: - name: olympus-db-shared-cfg - env: - - name: HERMIONE_FE_URL - value: http://hermione-aks.olympusai.live - - name: ARIADNE_FE_URL - value: http://ariadne-aks.olympusai.live - - name: EUREKA_URI - value: >- - http://eureka-server-service.olympus.svc.cluster.local:8761/eureka - resources: {} - imagePullPolicy: Always \ No newline at end of file diff --git a/hermione-fe-deployment.yaml b/hermione-fe-deployment.yaml new file mode 100644 index 0000000..bb3dd68 --- /dev/null +++ b/hermione-fe-deployment.yaml @@ -0,0 +1,20 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + name: hermione-fe + namespace: olympus +spec: + replicas: 1 + selector: + matchLabels: + app: hermione-fe + template: + metadata: + labels: + app: hermione-fe + spec: + containers: + - name: hermione-fe + image: olympusreg.azurecr.io/hermione-fe:10edf802 + resources: {} + imagePullPolicy: Always \ No newline at end of file From c84980e65ab543d8694529958718138434f9fa43 Mon Sep 17 00:00:00 2001 From: sumedh Date: Fri, 8 Nov 2024 16:53:38 +0530 Subject: [PATCH 4/5] manifests pipeline updated --- azure-pipelines.yml | 160 +++++++++++------- .../hermione-fe-deployment.yaml | 0 2 files changed, 100 insertions(+), 60 deletions(-) rename hermione-fe-deployment.yaml => manifests/hermione-fe-deployment.yaml (100%) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b914b59..939f652 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,70 +1,110 @@ -# Build your Java project and run tests with Apache Maven. -# Add steps that analyze code, save build artifacts, deploy, and more: -# https://docs.microsoft.com/azure/devops/pipelines/languages/java trigger: - master -pool: - name: azureselfhosted + variables: dockerRegistryServiceConnection: 'docker-registry-olympus' - imageName: 'hermione-fe' # Replace with your Docker image name + imageName: 'ariadne-fe' # Replace with your Docker image name shortCommitSha: '' # Initialize variable for short commit SHA -steps: -- checkout: self # Check out the pipeline repository (optional) + envName: 'aks-olympus' + azurecontainerRegistry: 'olympusreg.azurecr.io' + resourceName: 'olympus' + VITE_BACKEND_URL: 'http://olympus-api-gateway-aks.olympusai.live/hermione' -# Extract the short commit SHA -- script: | - echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)" - displayName: 'Set Short Commit SHA' -- script: | - echo "Building the first repository..." - ls -lrth - displayName: 'List hermione-fe directory' +stages: + - stage: Build + displayName: Build stage + jobs: + - job: Build + displayName: "Build & push to ACR" + pool: + name: azureselfhosted + steps: + - checkout: self # Check out the pipeline repository (optional) + + # Extract the short commit SHA + - script: | + echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)" + displayName: 'Set Short Commit SHA' -- script: | - echo "Listing the docker images..." - docker images - displayName: 'List docker images1' + - script: | + echo "Building the first repository..." + ls -lrth + displayName: 'list files' + + - script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images' -- task: Docker@2 - displayName: Build - inputs: - command: build - containerRegistry: $(dockerRegistryServiceConnection) - repository: '$(imageName)' - tags: '$(shortCommitSha)' - Dockerfile: 'Dockerfile' - arguments: '--build-arg VITE_BACKEND_URL=http://olympus-api-gateway-aks.olympusai.live/hermione' + - task: Docker@2 + inputs: + command: build + repository: '$(imageName)' + Dockerfile: 'Dockerfile' + containerRegistry: $(dockerRegistryServiceConnection) + tags: '$(shortCommitSha)' + arguments: '--build-arg VITE_BACKEND_URL=$(VITE_BACKEND_URL)' + displayName: 'Build an image for container registry' + + - task: Docker@2 + inputs: + command: push + containerRegistry: $(dockerRegistryServiceConnection) + repository: '$(imageName)' + tags: '$(shortCommitSha)' + displayName: 'push an image to container registry' + + - script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images' + + - script: | + echo "Removing Docker images to clean up..." + docker rmi $(docker images -q) + displayName: 'Clean up Docker Images' + continueOnError: true + condition: always() + + - script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images after removal' + + - upload: manifests + artifact: manifests + + - stage: Deploy + displayName: Deploy stage + dependsOn: Build -- task: Docker@2 - displayName: Push - inputs: - command: push - containerRegistry: $(dockerRegistryServiceConnection) - repository: '$(imageName)' - tags: '$(shortCommitSha)' + jobs: + - deployment: Deploy + condition: succeeded() + displayName: "Deploy to ${{variables.envName}} environment" + pool: + name: azureselfhosted + environment: + name: $(envName).$(resourceName) + resourceType: Kubernetes + strategy: + runOnce: + deploy: + steps: + - script: | + echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)" + displayName: 'Set Short Commit SHA' + + - script: | + echo "########################################################################" + echo "Short Commit SHA: $(shortCommitSha)" + displayName: 'Echo short commit SHA' -- script: | - echo "Listing the docker images..." - docker images - displayName: 'List docker images' -- script: | - echo "Updating imageName in dpeloyment.yaml" - echo "Before Substitution" - cat hermione-fe-deployment.yaml - echo "###############################################" - echo "current shell: $SHELL" - echo "imagename bracket : $(imageName)" - echo "###############################################" - sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" hermione-fe-deployment.yaml - echo "After Substitution" - cat hermione-fe-deployment.yaml - displayName: 'Update ImageName in YAML file' -- script: | - echo "deployment using kubectl" - kubectl apply -f hermione-fe-deployment.yaml - displayName: 'deployment using kubectl' -- script: | - echo "remove the docker images..." - docker rmi $(docker images -q) - displayName: 'remove docker images' \ No newline at end of file + - task: KubernetesManifest@0 + displayName: Deploy to Kubernetes cluster + inputs: + action: deploy + manifests: | + $(Pipeline.Workspace)/manifests/hermione-fe-deployment.yaml + containers: | + $(azurecontainerRegistry)/$(imageName):$(shortCommitSha) \ No newline at end of file diff --git a/hermione-fe-deployment.yaml b/manifests/hermione-fe-deployment.yaml similarity index 100% rename from hermione-fe-deployment.yaml rename to manifests/hermione-fe-deployment.yaml From 32159964f7c8c449a385baee99bb5544936238fb Mon Sep 17 00:00:00 2001 From: sumedh Date: Fri, 8 Nov 2024 17:03:28 +0530 Subject: [PATCH 5/5] azure pipeline modified --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 939f652..2318be5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,7 +3,7 @@ trigger: variables: dockerRegistryServiceConnection: 'docker-registry-olympus' - imageName: 'ariadne-fe' # Replace with your Docker image name + imageName: 'hermione-fe' # Replace with your Docker image name shortCommitSha: '' # Initialize variable for short commit SHA envName: 'aks-olympus' azurecontainerRegistry: 'olympusreg.azurecr.io'