|
| 1 | +# Deploy to Azure Kubernetes Service |
| 2 | +# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service |
| 3 | +# https://docs.microsoft.com/azure/devops/pipelines/languages/docker |
| 4 | + |
| 5 | +trigger: |
| 6 | + - main |
| 7 | + |
| 8 | +resources: |
| 9 | + - repo: self |
| 10 | + |
| 11 | +variables: |
| 12 | + |
| 13 | + # Container registry service connection established during pipeline creation |
| 14 | + dockerRegistryServiceConnection: 'ba554595-2da8-4cf6-88c4-a57c75966491' |
| 15 | + imageRepository: 'multicloudapp' |
| 16 | + containerRegistry: 'multicloud.azurecr.io' |
| 17 | + dockerfilePath: '**/Dockerfile' |
| 18 | + tag: '$(Build.BuildId)' |
| 19 | + imagePullSecret: 'multicloud2012b828-auth' |
| 20 | + |
| 21 | + # Agent VM image name |
| 22 | + vmImageName: 'ubuntu-latest' |
| 23 | + |
| 24 | + # Name of the new namespace being created to deploy the PR changes. |
| 25 | + k8sNamespaceForPR: 'review-app-$(System.PullRequest.PullRequestId)' |
| 26 | + |
| 27 | +stages: |
| 28 | + - stage: Build |
| 29 | + displayName: Build stage |
| 30 | + jobs: |
| 31 | + - job: Build |
| 32 | + displayName: Build |
| 33 | + pool: |
| 34 | + vmImage: $(vmImageName) |
| 35 | + steps: |
| 36 | + - task: JavaToolInstaller@0 |
| 37 | + inputs: |
| 38 | + versionSpec: '17' |
| 39 | + jdkArchitectureOption: 'x64' |
| 40 | + jdkSourceOption: 'PreInstalled' |
| 41 | + - task: Maven@4 |
| 42 | + inputs: |
| 43 | + mavenPomFile: 'pom.xml' |
| 44 | + publishJUnitResults: true |
| 45 | + testResultsFiles: '**/surefire-reports/TEST-*.xml' |
| 46 | + javaHomeOption: 'JDKVersion' |
| 47 | + mavenVersionOption: '1.17' |
| 48 | + mavenAuthenticateFeed: false |
| 49 | + effectivePomSkip: false |
| 50 | + sonarQubeRunAnalysis: false |
| 51 | + - task: Docker@2 |
| 52 | + displayName: Build and push an image to container registry |
| 53 | + inputs: |
| 54 | + command: buildAndPush |
| 55 | + repository: $(imageRepository) |
| 56 | + dockerfile: $(dockerfilePath) |
| 57 | + containerRegistry: $(dockerRegistryServiceConnection) |
| 58 | + tags: | |
| 59 | + $(tag) |
| 60 | +
|
| 61 | + - upload: manifests |
| 62 | + artifact: manifests |
| 63 | + - script: | |
| 64 | + - script: | |
| 65 | + echo Downloading Liquibase and Oracle JDBC driver |
| 66 | + wget https://github.com/liquibase/liquibase/releases/download/v4.4.3/liquibase-4.4.3.tar.gz |
| 67 | + tar -xzf liquibase-4.4.3.tar.gz |
| 68 | + wget https://path/to/ojdbc8.jar |
| 69 | + displayName: 'Install Liquibase and Oracle JDBC' |
| 70 | +
|
| 71 | +
|
| 72 | + - stage: Deploy |
| 73 | + displayName: Deploy stage |
| 74 | + dependsOn: Build |
| 75 | + |
| 76 | + jobs: |
| 77 | + |
| 78 | + - deployment: Deploy |
| 79 | + condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/'))) |
| 80 | + displayName: Deploy |
| 81 | + pool: |
| 82 | + vmImage: $(vmImageName) |
| 83 | + environment: 'paulparkinsonazuredevopsoracledatabase-8684.default' |
| 84 | + strategy: |
| 85 | + runOnce: |
| 86 | + deploy: |
| 87 | + steps: |
| 88 | + - task: KubernetesManifest@0 |
| 89 | + displayName: Create imagePullSecret |
| 90 | + inputs: |
| 91 | + action: createSecret |
| 92 | + secretName: $(imagePullSecret) |
| 93 | + dockerRegistryEndpoint: $(dockerRegistryServiceConnection) |
| 94 | + |
| 95 | + - script: | |
| 96 | + yq eval '.spec.template.spec.containers[0].env += [{"name": "AZURE_LOG_LEVEL", "value": "verbose"}, {"name": "AZURE_CLIENT_ID", "value": "$(AZURE_CLIENT_ID)"}, {"name": "AZURE_CLIENT_SECRET", "value": "$(AZURE_CLIENT_SECRET)"}, {"name": "AZURE_TENANT_ID", "value": "$(AZURE_TENANT_ID)"}]' -i $(Pipeline.Workspace)/manifests/deployment.yml |
| 97 | + displayName: 'Add Environment Variable with yq' |
| 98 | + - task: KubernetesManifest@0 |
| 99 | + displayName: Deploy to Kubernetes cluster |
| 100 | + inputs: |
| 101 | + action: deploy |
| 102 | + manifests: | |
| 103 | + $(Pipeline.Workspace)/manifests/deployment.yml |
| 104 | + $(Pipeline.Workspace)/manifests/service.yml |
| 105 | + imagePullSecrets: | |
| 106 | + $(imagePullSecret) |
| 107 | + containers: | |
| 108 | + $(containerRegistry)/$(imageRepository):$(tag) |
| 109 | + - script: | |
| 110 | + echo Setting up environment variables |
| 111 | + export DB_HOST=$(DB_HOST) |
| 112 | + export DB_PORT=$(DB_PORT) |
| 113 | + export DB_SERVICE_NAME=$(DB_SERVICE_NAME) |
| 114 | + export DB_USERNAME=$(DB_USERNAME) |
| 115 | + export DB_PASSWORD=$(DB_PASSWORD) |
| 116 | + |
| 117 | + echo Running Liquibase update |
| 118 | + ./liquibase --defaultsFile=path/to/liquibase.properties update |
| 119 | + displayName: 'Run Liquibase Update' |
| 120 | + env: |
| 121 | + DB_HOST: $(DB_HOST) |
| 122 | + DB_PORT: $(DB_PORT) |
| 123 | + DB_SERVICE_NAME: $(DB_SERVICE_NAME) |
| 124 | + DB_USERNAME: $(DB_USERNAME) |
| 125 | + DB_PASSWORD: $(DB_PASSWORD) |
| 126 | + |
0 commit comments