From 1fe352eb09b06dbb79aa7c44a6d6c19b7a80b12b Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Sun, 16 Feb 2020 14:47:00 -0500 Subject: [PATCH] Add new infrastructure template and pipeline --- .../openshift-app-build-template.yml | 0 build/aro/webapp-build-artifacts.yml | 2 +- build/aro/webapp-container-build.yml | 2 +- deploy/aro/basket-api/azure-pipelines.yml | 2 +- deploy/aro/infrastructure/azure-pipelines.yml | 39 +++++ .../rabbitmq-image-deploy-template.yml | 142 ++++++++++++++++++ .../secrets-deploy-template.yml | 77 ++++++++++ .../webapp-deploy-template.yml} | 0 8 files changed, 261 insertions(+), 3 deletions(-) rename build/aro/{ => openshift-templates}/openshift-app-build-template.yml (100%) create mode 100644 deploy/aro/infrastructure/azure-pipelines.yml create mode 100644 deploy/aro/openshift-templates/rabbitmq-image-deploy-template.yml create mode 100644 deploy/aro/openshift-templates/secrets-deploy-template.yml rename deploy/aro/{openshift-webapp-deploy-template.yml => openshift-templates/webapp-deploy-template.yml} (100%) diff --git a/build/aro/openshift-app-build-template.yml b/build/aro/openshift-templates/openshift-app-build-template.yml similarity index 100% rename from build/aro/openshift-app-build-template.yml rename to build/aro/openshift-templates/openshift-app-build-template.yml diff --git a/build/aro/webapp-build-artifacts.yml b/build/aro/webapp-build-artifacts.yml index 3b97491ca..b241f5b41 100644 --- a/build/aro/webapp-build-artifacts.yml +++ b/build/aro/webapp-build-artifacts.yml @@ -45,7 +45,7 @@ jobs: - task: CopyFiles@2 displayName: 'Copy OpenShift Web App Deploy Template' inputs: - sourceFolder: '$(Build.SourcesDirectory)/deploy/aro' + sourceFolder: '$(Build.SourcesDirectory)/deploy/aro/openshift-templates' contents: 'openshift-webapp-deploy-template.yml' targetFolder: $(Build.ArtifactStagingDirectory) - task: PublishBuildArtifacts@1 diff --git a/build/aro/webapp-container-build.yml b/build/aro/webapp-container-build.yml index 3eef3f811..01ba1f97e 100644 --- a/build/aro/webapp-container-build.yml +++ b/build/aro/webapp-container-build.yml @@ -19,7 +19,7 @@ jobs: - task: DownloadPipelineArtifact@2 inputs: artifact: drop - - script: 'oc process -f $(Pipeline.Workspace)/openshift-app-build-template.yml -p APPLICATION_NAME=$(AppName) | oc apply -f-' + - script: 'oc process -f $(Pipeline.Workspace)/openshift-templates/openshift-app-build-template.yml -p APPLICATION_NAME=$(AppName) | oc apply -f-' failOnStderr: true displayName: 'Ensure OpenShift BuildConfig' - powershell: | diff --git a/deploy/aro/basket-api/azure-pipelines.yml b/deploy/aro/basket-api/azure-pipelines.yml index d47b2375f..286a1d645 100644 --- a/deploy/aro/basket-api/azure-pipelines.yml +++ b/deploy/aro/basket-api/azure-pipelines.yml @@ -24,6 +24,6 @@ stages: - script: 'oc project $(OpenShiftProject)' failOnStderr: true displayName: 'Set OpenShift Project Context' - - script: 'oc process -f ./deploy/aro/openshift-webapp-deploy-template.yml -p APPLICATION_NAME=$(AppName) -p IMAGE_REGISTRY_PROJECT_NAME=$(SourceImageRegistryProjectName) | oc apply -f-' + - script: 'oc process -f ./deploy/aro/openshift-templates/webapp-deploy-template.yml -p APPLICATION_NAME=$(AppName) -p IMAGE_REGISTRY_PROJECT_NAME=$(SourceImageRegistryProjectName) | oc apply -f-' failOnStderr: true displayName: 'Ensure OpenShift DeploymentConfig and Service' \ No newline at end of file diff --git a/deploy/aro/infrastructure/azure-pipelines.yml b/deploy/aro/infrastructure/azure-pipelines.yml new file mode 100644 index 000000000..2433ddc34 --- /dev/null +++ b/deploy/aro/infrastructure/azure-pipelines.yml @@ -0,0 +1,39 @@ +variables: + OpenShiftServiceConnection: 'OpenShift on ARO' +stages: + - stage: development + displayName: Development + variables: + OpenShiftProject: development + SourceImageRegistryProjectName: development + SqlHostName: mssql-server-linux.$(OpenShiftProject).svc + jobs: + - job: Infrastructure_Containers_Deployment + displayName: 'Infrastructure Containers Deployment' + variables: + CatalogDbConnection: Server=$(SqlHostName);Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=$(SqlUsername);Password=$(SqlPassword) + IdentityDbConnection: Server=$(SqlHostName);Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=$(SqlUsername);Password=$(SqlPassword) + MarketingDbConnection: Server=$(SqlHostName);Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=$(SqlUsername);Password=$(SqlPassword) + OrderingDbConnection: Server=$(SqlHostName);Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=$(SqlUsername);Password=$(SqlPassword) + WebhooksDbConnection: Server=$(SqlHostName);Database=Microsoft.eShopOnContainers.Services.WebhooksDb;User Id=$(SqlUsername);Password=$(SqlPassword) + pool: + vmImage: 'windows-latest' + steps: + - task: AzureKeyVault@1 + displayName: 'Azure Key Vault: openshift-demo-vault' + inputs: + azureSubscription: 'Azure OpenShift Demo' + KeyVaultName: 'openshift-demo-vault' + - task: redhat.openshift-vsts.oc-setup-task.oc-setup@2 + displayName: 'Setup Openshift CLI' + inputs: + openshiftService: $(OpenShiftServiceConnection) + - script: 'oc project $(OpenShiftProject)' + failOnStderr: true + displayName: 'Set OpenShift Project Context' + - script: 'oc process -f ./deploy/aro/openshift-templates/secrets-deploy-template.yml -p IDENTITY_DB_CONNECTION_SECRET=$(IdentityDbConnection) -p MARKETING_DB_CONNECTION_SECRET=$(MarketingDbConnection) -p ORDERING_DB_CONNECTION_SECRET=$(OrderingDbConnection) -p SQL_PASSWORD_SECRET=$(SqlPassword) -p WEBHOOKS_DB_CONNECTION_SECRET=$(WebhooksDbConnection) | oc apply -f-' + failOnStderr: true + displayName: 'Secrets Deployment' + - script: 'oc process -f ./deploy/aro/openshift-templates/rabbitmq-image-deploy-template.yml -p APPLICATION_NAME=$(AppName) -p IMAGE_REGISTRY_PROJECT_NAME=$(SourceImageRegistryProjectName) | oc apply -f-' + failOnStderr: true + displayName: 'RabbitMQ Deployment' \ No newline at end of file diff --git a/deploy/aro/openshift-templates/rabbitmq-image-deploy-template.yml b/deploy/aro/openshift-templates/rabbitmq-image-deploy-template.yml new file mode 100644 index 000000000..df5877836 --- /dev/null +++ b/deploy/aro/openshift-templates/rabbitmq-image-deploy-template.yml @@ -0,0 +1,142 @@ +apiVersion: template.openshift.io/v1 +kind: Template +metadata: + name: ${TEMPLATE_NAME} +objects: +- apiVersion: apps.openshift.io/v1 + kind: DeploymentConfig + metadata: + generation: 2 + labels: + app: ${APPLICATION_NAME} + template: ${TEMPLATE_NAME} + name: ${APPLICATION_NAME} + spec: + replicas: 1 + revisionHistoryLimit: 10 + selector: + app: ${APPLICATION_NAME} + deploymentconfig: ${APPLICATION_NAME} + strategy: + activeDeadlineSeconds: 21600 + resources: {} + rollingParams: + intervalSeconds: 1 + maxSurge: 25% + maxUnavailable: 25% + timeoutSeconds: 600 + updatePeriodSeconds: 1 + type: Rolling + template: + metadata: + labels: + app: ${APPLICATION_NAME} + deploymentconfig: ${APPLICATION_NAME} + spec: + containers: + - image: ${APPLICATION_NAME}:latest + imagePullPolicy: IfNotPresent + name: ${APPLICATION_NAME} + ports: + - containerPort: 5672 + protocol: TCP + - containerPort: 15671 + protocol: TCP + - containerPort: 15672 + protocol: TCP + - containerPort: 25672 + protocol: TCP + - containerPort: 4369 + protocol: TCP + - containerPort: 5671 + protocol: TCP + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /var/lib/rabbitmq + name: ${APPLICATION_NAME}-volume-1 + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 + volumes: + - emptyDir: {} + name: ${APPLICATION_NAME}-volume-1 + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - ${APPLICATION_NAME} + from: + kind: ImageStreamTag + name: '${APPLICATION_NAME}:3-management-alpine' + namespace: ${IMAGE_REGISTRY_PROJECT_NAME} + type: ImageChange +- apiVersion: v1 + kind: Service + metadata: + labels: + app: ${APPLICATION_NAME} + template: ${TEMPLATE_NAME} + name: ${APPLICATION_NAME} + spec: + ports: + - name: 4369-tcp + port: 4369 + protocol: TCP + targetPort: 4369 + - name: 5671-tcp + port: 5671 + protocol: TCP + targetPort: 5671 + - name: 5672-tcp + port: 5672 + protocol: TCP + targetPort: 5672 + - name: 15671-tcp + port: 15671 + protocol: TCP + targetPort: 15671 + - name: 15672-tcp + port: 15672 + protocol: TCP + targetPort: 15672 + - name: 25672-tcp + port: 25672 + protocol: TCP + targetPort: 25672 + selector: + app: ${APPLICATION_NAME} + deploymentconfig: ${APPLICATION_NAME} + sessionAffinity: None + type: ClusterIP + status: + loadBalancer: {} +- apiVersion: image.openshift.io/v1 + kind: ImageStream + metadata: + labels: + app: ${APPLICATION_NAME} + template: ${TEMPLATE_NAME} + name: ${APPLICATION_NAME} + spec: + lookupPolicy: + local: false +parameters: +- description: The name for the application. + displayName: Application Name + name: APPLICATION_NAME + required: true + value: rabbitmq +- description: The OpenShift project name that is hosting the image registry. + displayName: Image Registry Project Name + name: IMAGE_REGISTRY_PROJECT_NAME + required: true +- description: The template name. + displayName: Template Name + name: TEMPLATE_NAME + required: true + value: rabbitmq-image-deploy-template \ No newline at end of file diff --git a/deploy/aro/openshift-templates/secrets-deploy-template.yml b/deploy/aro/openshift-templates/secrets-deploy-template.yml new file mode 100644 index 000000000..11b015013 --- /dev/null +++ b/deploy/aro/openshift-templates/secrets-deploy-template.yml @@ -0,0 +1,77 @@ +apiVersion: template.openshift.io/v1 +kind: Template +metadata: + name: ${TEMPLATE_NAME} +objects: +- apiVersion: v1 + kind: Secret + stringData : + ConnectionString: ${CATALOG_DB_CONNECTION_SECRET} + metadata: + name: catalog-db-connection-secret + type: Opaque +- apiVersion: v1 + kind: Secret + stringData : + ConnectionString: ${IDENTITY_DB_CONNECTION_SECRET} + metadata: + name: identity-db-connection-secret + type: Opaque +- apiVersion: v1 + kind: Secret + stringData : + ConnectionString: ${MARKETING_DB_CONNECTION_SECRET} + metadata: + name: marketing-db-connection-secret + type: Opaque +- apiVersion: v1 + kind: Secret + stringData : + ConnectionString: ${ORDERING_DB_CONNECTION_SECRET} + metadata: + name: ordering-db-connection-secret + type: Opaque +- apiVersion: v1 + kind: Secret + stringData : + ConnectionString: ${SQL_PASSWORD_SECRET} + metadata: + name: sql-password--secret + type: Opaque +- apiVersion: v1 + kind: Secret + stringData : + ConnectionString: ${WEBHOOKS_DB_CONNECTION_SECRET} + metadata: + name: webhooks-db-connection-secret + type: Opaque +parameters: +- description: The Catalog database connection string. + displayName: Catalog Database Connection String + name: CATALOG_DB_CONNECTION_SECRET + required: true +- description: The Identity database connection string. + displayName: Identity Database Connection String + name: IDENTITY_DB_CONNECTION_SECRET + required: true +- description: The Marketing database connection string. + displayName: Marketing Database Connection String + name: MARKETING_DB_CONNECTION_SECRET + required: true +- description: The Ordering database connection string. + displayName: Ordering Database Connection String + name: ORDERING_DB_CONNECTION_SECRET + required: true +- description: The SQL Server sa password. + displayName: SQL Server SA password + name: SQL_PASSWORD_SECRET + required: true +- description: The Webhooks database connection string. + displayName: Webhooks Database Connection String + name: WEBHOOKS_DB_CONNECTION_SECRET + required: true +- description: The template name. + displayName: Template Name + name: TEMPLATE_NAME + required: true + value: secrets-template diff --git a/deploy/aro/openshift-webapp-deploy-template.yml b/deploy/aro/openshift-templates/webapp-deploy-template.yml similarity index 100% rename from deploy/aro/openshift-webapp-deploy-template.yml rename to deploy/aro/openshift-templates/webapp-deploy-template.yml