This commit is contained in:
Florinda
2024-11-12 16:39:32 +01:00
2 changed files with 142 additions and 25 deletions

View File

@@ -1,28 +1,114 @@
# Maven
# 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
- master
pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: olympus-common # Alias for the first repository
type: git
name: Olympus/olympus-common # Project and repository name
ref: master
steps:
- task: DownloadSecureFile@1
name: mvnSettings
displayName: 'Download Maven settings'
inputs:
secureFile: 'maven-azuredevops-settings.xml'
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'deploy'
options: '-s $(mvnSettings.secureFilePath)'
mavenAuthenticateFeed: true
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.21'
mavenVersionOption: 'Default'
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()

View File

@@ -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