From 444a90b5c97c44c12345a9a8621f2e841d810751 Mon Sep 17 00:00:00 2001 From: "andrea.terzani" Date: Wed, 16 Apr 2025 19:38:29 +0200 Subject: [PATCH] add pipleines --- .azure.pipelines.yaml | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 .azure.pipelines.yaml diff --git a/.azure.pipelines.yaml b/.azure.pipelines.yaml new file mode 100644 index 0000000..97fb54a --- /dev/null +++ b/.azure.pipelines.yaml @@ -0,0 +1,114 @@ +trigger: +- master + +variables: + dockerRegistryServiceConnection: 'docker-registry-olympus' + imageName: 'hermione-fe' # Replace with your Docker image name + shortCommitSha: '' # Initialize variable for short commit SHA + envName: 'aks-olympus' + azurecontainerRegistry: 'olympusreg.azurecr.io' + resourceName: 'olympus' + VITE_BACKEND_URL: 'https://olympus-api-gateway.olympus-wizardai.com/hermione' + +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 "Building the first repository..." + pwd + ls -lrth + displayName: 'list files' + + - script: | + echo "Listing the docker images..." + docker images + displayName: 'List docker images' + + - 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 + + jobs: + - deployment: Deploy + condition: succeeded() + displayName: "Deploy to ${{variables.envName}} environment" + pool: + name: azureselfhosted + environment: + name: $(envName).$(resourceName) + resourceType: Kubernetes + strategy: + runOnce: + deploy: + steps: + - checkout: self # Check out the pipeline repository (optional) + + - 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@1 + displayName: Deploy to Kubernetes cluster + inputs: + action: deploy + namespace: olympus + manifests: | + $(Pipeline.Workspace)/manifests/hermione-fe-deployment.yaml + containers: | + $(azurecontainerRegistry)/$(imageName):$(shortCommitSha) \ No newline at end of file