manifests file updated

This commit is contained in:
sumedh
2024-11-08 16:42:51 +05:30
parent d4e0270536
commit 26bb57cf63
2 changed files with 107 additions and 80 deletions

View File

@@ -1,87 +1,114 @@
# 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' # Replace with your Docker image name
shortCommitSha: '' # Initialize variable for short commit SHA
- master
resources:
repositories:
- repository: olympus-common # Alias for the first repository
type: git
name: Olympus/olympus-common # Project and repository name
ref: master
steps:
- checkout: self # Check out the pipeline repository (optional)
- checkout: olympus-common # Check out the first repository
# 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 olympus-common'
- task: Maven@3
inputs:
mavenPomFile: 'olympus-common/pom.xml'
goals: 'install'
# options: '-s $(mvnSettings.secureFilePath)'
#mavenAuthenticateFeed: true
#publishJUnitResults: true
#testResultsFiles: '**/TEST-*.xml'
#javaHomeOption: 'JDKVersion'
#jdkVersionOption: '1.21'
#mavenVersionOption: 'Default'
displayName: 'Build olympus-common'
- task: Maven@3
inputs:
mavenPomFile: 'hermione/pom.xml'
goals: 'install -DskipTests'
# options: '-s $(mvnSettings.secureFilePath)'
#mavenAuthenticateFeed: true
#publishJUnitResults: true
#testResultsFiles: '**/TEST-*.xml'
#javaHomeOption: 'JDKVersion'
#jdkVersionOption: '1.21'
#mavenVersionOption: 'Default'
displayName: 'Build hermione'
- script: |
echo "Listing the docker images..."
docker images
displayName: 'List docker images1'
- task: Docker@2
inputs:
command: 'buildAndPush'
containerRegistry: $(dockerRegistryServiceConnection)
repository: '$(imageName)'
tags: '$(shortCommitSha)'
Dockerfile: 'hermione/Dockerfile'
- script: |
echo "Listing the docker images..."
docker images
displayName: 'List docker images'
- script: |
echo "Updating imageName in dpeloyment.yaml"
echo "Before Substitution"
cat hermione/hermione-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/hermione-deployment.yaml
echo "After Substitution"
cat hermione/hermione-deployment.yaml
displayName: 'Update ImageName in YAML file'
- script: |
echo "deployment using kubectl"
kubectl apply -f hermione/hermione-deployment.yaml
displayName: 'deployment using kubectl'
- script: |
echo "remove the docker images..."
docker rmi $(docker images -q)
displayName: 'remove docker images'
variables:
dockerRegistryServiceConnection: 'docker-registry-olympus'
imageName: 'hermione'
shortCommitSha: ''
envName: 'aks-olympus'
azurecontainerRegistry: 'olympusreg.azurecr.io'
resourceName: 'olympus'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: "Build & push to ACR"
pool:
name: azureselfhosted
steps:
- checkout: self
- checkout: olympus-common
- 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 files'
- task: Maven@3
inputs:
mavenPomFile: 'olympus-common/pom.xml'
goals: 'install'
displayName: 'Build olympus-common'
- task: Maven@3
inputs:
mavenPomFile: 'hermione/pom.xml'
goals: 'install -DskipTests'
displayName: 'Build hermione'
- script: |
echo "Listing the docker images..."
docker images
displayName: 'list docker images'
- task: Docker@2
inputs:
command: 'buildAndPush'
repository: '$(imageName)'
Dockerfile: 'hermione/Dockerfile'
containerRegistry: $(dockerRegistryServiceConnection)
tags: '$(shortCommitSha)'
displayName: 'Build and push an image to container registry'
- script: |
echo "Listing the docker images..."
docker images
displayName: 'List docker images'
- upload: hermione/manifests
artifact: manifests
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
jobs:
- deployment: Deploy
condition: succeeded()
displayName: "Deploy to ${{variables.envName}}"
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'
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
manifests: |
$(Pipeline.Workspace)/manifests/hermione-deployment.yaml
containers: |
$(azurecontainerRegistry)/$(imageName):$(shortCommitSha)
- script: |
echo "Removing Docker images to clean up..."
docker rmi $(docker images -q)
displayName: 'Clean up Docker Images'
continueOnError: true
condition: always()