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: trigger:
- master - master
pool:
name: azureselfhosted
variables:
dockerRegistryServiceConnection: 'docker-registry-olympus'
imageName: 'hermione' # Replace with your Docker image name
shortCommitSha: '' # Initialize variable for short commit SHA
resources: resources:
repositories: repositories:
- repository: olympus-common # Alias for the first repository - repository: olympus-common # Alias for the first repository
type: git type: git
name: Olympus/olympus-common # Project and repository name name: Olympus/olympus-common # Project and repository name
ref: master ref: master
steps:
- checkout: self # Check out the pipeline repository (optional) variables:
- checkout: olympus-common # Check out the first repository dockerRegistryServiceConnection: 'docker-registry-olympus'
# Extract the short commit SHA imageName: 'hermione'
- script: | shortCommitSha: ''
echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)" envName: 'aks-olympus'
displayName: 'Set Short Commit SHA' azurecontainerRegistry: 'olympusreg.azurecr.io'
- script: | resourceName: 'olympus'
echo "Building the first repository..."
ls -lrth stages:
displayName: 'List olympus-common' - stage: Build
- task: Maven@3 displayName: Build stage
inputs: jobs:
mavenPomFile: 'olympus-common/pom.xml' - job: Build
goals: 'install' displayName: "Build & push to ACR"
# options: '-s $(mvnSettings.secureFilePath)' pool:
#mavenAuthenticateFeed: true name: azureselfhosted
#publishJUnitResults: true steps:
#testResultsFiles: '**/TEST-*.xml' - checkout: self
#javaHomeOption: 'JDKVersion' - checkout: olympus-common
#jdkVersionOption: '1.21'
#mavenVersionOption: 'Default' - script: |
displayName: 'Build olympus-common' echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)"
- task: Maven@3 displayName: 'Set Short Commit SHA'
inputs:
mavenPomFile: 'hermione/pom.xml' - script: |
goals: 'install -DskipTests' echo "Building the first repository..."
# options: '-s $(mvnSettings.secureFilePath)' ls -lrth
#mavenAuthenticateFeed: true displayName: 'list files'
#publishJUnitResults: true
#testResultsFiles: '**/TEST-*.xml' - task: Maven@3
#javaHomeOption: 'JDKVersion' inputs:
#jdkVersionOption: '1.21' mavenPomFile: 'olympus-common/pom.xml'
#mavenVersionOption: 'Default' goals: 'install'
displayName: 'Build hermione' displayName: 'Build olympus-common'
- script: |
echo "Listing the docker images..." - task: Maven@3
docker images inputs:
displayName: 'List docker images1' mavenPomFile: 'hermione/pom.xml'
- task: Docker@2 goals: 'install -DskipTests'
inputs: displayName: 'Build hermione'
command: 'buildAndPush'
containerRegistry: $(dockerRegistryServiceConnection) - script: |
repository: '$(imageName)' echo "Listing the docker images..."
tags: '$(shortCommitSha)' docker images
Dockerfile: 'hermione/Dockerfile' displayName: 'list docker images'
- script: |
echo "Listing the docker images..." - task: Docker@2
docker images inputs:
displayName: 'List docker images' command: 'buildAndPush'
- script: | repository: '$(imageName)'
echo "Updating imageName in dpeloyment.yaml" Dockerfile: 'hermione/Dockerfile'
echo "Before Substitution" containerRegistry: $(dockerRegistryServiceConnection)
cat hermione/hermione-deployment.yaml tags: '$(shortCommitSha)'
echo "###############################################" displayName: 'Build and push an image to container registry'
echo "current shell: $SHELL"
echo "imagename bracket : $(imageName)" - script: |
echo "###############################################" echo "Listing the docker images..."
sed -i "s|image: olympusreg.azurecr.io/$(imageName):.*|image: olympusreg.azurecr.io/$(imageName):$(shortCommitSha)|" hermione/hermione-deployment.yaml docker images
echo "After Substitution" displayName: 'List docker images'
cat hermione/hermione-deployment.yaml
displayName: 'Update ImageName in YAML file' - upload: hermione/manifests
- script: | artifact: manifests
echo "deployment using kubectl"
kubectl apply -f hermione/hermione-deployment.yaml - stage: Deploy
displayName: 'deployment using kubectl' displayName: Deploy stage
- script: | dependsOn: Build
echo "remove the docker images..."
docker rmi $(docker images -q) jobs:
displayName: 'remove docker images' - 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()