Skip to content

Commit

Permalink
Merge pull request #2 from paulparkinson/main
Browse files Browse the repository at this point in the history
init part2 includes liquibase
  • Loading branch information
enschilling authored Feb 29, 2024
2 parents b0c5e45 + 4adf99d commit 65dc943
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
126 changes: 126 additions & 0 deletions azure-pipelines-liquibase-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Deploy to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- main

resources:
- repo: self

variables:

# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'ba554595-2da8-4cf6-88c4-a57c75966491'
imageRepository: 'multicloudapp'
containerRegistry: 'multicloud.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Build.BuildId)'
imagePullSecret: 'multicloud2012b828-auth'

# Agent VM image name
vmImageName: 'ubuntu-latest'

# Name of the new namespace being created to deploy the PR changes.
k8sNamespaceForPR: 'review-app-$(System.PullRequest.PullRequestId)'

stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: JavaToolInstaller@0
inputs:
versionSpec: '17'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
- task: Maven@4
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
mavenVersionOption: '1.17'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- upload: manifests
artifact: manifests
- script: |
- script: |
echo Downloading Liquibase and Oracle JDBC driver
wget https://github.com/liquibase/liquibase/releases/download/v4.4.3/liquibase-4.4.3.tar.gz
tar -xzf liquibase-4.4.3.tar.gz
wget https://path/to/ojdbc8.jar
displayName: 'Install Liquibase and Oracle JDBC'
- stage: Deploy
displayName: Deploy stage
dependsOn: Build

jobs:

- deployment: Deploy
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'paulparkinsonazuredevopsoracledatabase-8684.default'
strategy:
runOnce:
deploy:
steps:
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)

- script: |
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
displayName: 'Add Environment Variable with yq'
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
manifests: |
$(Pipeline.Workspace)/manifests/deployment.yml
$(Pipeline.Workspace)/manifests/service.yml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)
- script: |
echo Setting up environment variables
export DB_HOST=$(DB_HOST)
export DB_PORT=$(DB_PORT)
export DB_SERVICE_NAME=$(DB_SERVICE_NAME)
export DB_USERNAME=$(DB_USERNAME)
export DB_PASSWORD=$(DB_PASSWORD)
echo Running Liquibase update
./liquibase --defaultsFile=path/to/liquibase.properties update
displayName: 'Run Liquibase Update'
env:
DB_HOST: $(DB_HOST)
DB_PORT: $(DB_PORT)
DB_SERVICE_NAME: $(DB_SERVICE_NAME)
DB_USERNAME: $(DB_USERNAME)
DB_PASSWORD: $(DB_PASSWORD)

1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ stages:
- script: |
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
displayName: 'Add Environment Variable with yq'
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
Expand Down
15 changes: 15 additions & 0 deletions db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

<changeSet id="1" author="your_name">
<createTable tableName="cicd_test_table">
<column name="testvalue" type="VARCHAR2(64)"/>
</createTable>
</changeSet>

</databaseChangeLog>
6 changes: 6 additions & 0 deletions liquibase.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
driver: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@//${DB_HOST}:${DB_PORT}/${DB_SERVICE_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
changeLogFile: db/changelog/db.changelog-master.xml
classpath: ojdbc8.jar

0 comments on commit 65dc943

Please sign in to comment.