diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0f1a0eb..ff5a74e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,17 @@ on: - 'bugfix/**' workflow_dispatch: +env: + OCTOPUS_TENANT_NAME: Internal + OCTOPUS_PROJECT_NAME: Trident - Tenant + OCTOPUS_FEATURE_BRANCH_CHANNEL: Default + OCTOPUS_FEATURE_BRANCH_ENVIRONMENT: Development + OCTOPUS_RELEASE_CHANNEL: Release + OCTOPUS_RELEASE_ENVIRONMENT: Staging + OCTOPUS_SPACE: Default + OCTOPUS_API_KEY: ${{ secrets.OCTOPUSSERVERAPIKEY }} + OCTOPUS_URL: ${{ secrets.OCTOPUSSERVERURL }} + jobs: build-and-push-application: @@ -31,6 +42,10 @@ jobs: $branchName = (((${env:GITHUB_REF} -replace "refs/heads/", "") -replace "feature/", "") -replace "bugfix/", "") -replace " ", "" Write-Host "The Branch Name is: $branchName" + $channelName = "${env:OCTOPUS_RELEASE_CHANNEL}" + Write-Host "The channel name is now $channelName" + $environmentName = "${env:OCTOPUS_RELEASE_ENVIRONMENT}" + Write-Host "The environment name is now $environmentName" $versionNumber = "$($versionPrefix).${env:GITHUB_RUN_NUMBER}" Write-Host "The version number is now $versionNumber" @@ -38,13 +53,23 @@ jobs: { Write-Host "The branch is not the main branch, using the feature branch settings instead." + $channelName = "${env:OCTOPUS_FEATURE_BRANCH_CHANNEL}" + Write-Host "The channel name is now $channelName" + $environmentName = "${env:OCTOPUS_FEATURE_BRANCH_ENVIRONMENT}" + Write-Host "The environment name is now $environmentName" $versionNumber = "$versionNumber-$branchName" Write-Host "The version number is now $versionNumber" - } + } + + Write-Host "Setting the Output Variable OCTOPUS_CHANNEL to $channelName" + Write-Output "OCTOPUS_CHANNEL=$channelName" >> $Env:GITHUB_OUTPUT Write-Host "Setting the Output Variable VERSION to $versionNumber" Write-Output "APP_VERSION=$versionNumber" >> $Env:GITHUB_OUTPUT + Write-Host "Setting the Output Variable OCTOPUS_ENVIRONMENT to $environmentName" + Write-Output "OCTOPUS_ENVIRONMENT=$environmentName" >> $Env:GITHUB_OUTPUT + shell: pwsh - name: Setup .NET SDK uses: actions/setup-dotnet@v3 @@ -68,4 +93,61 @@ jobs: - name: build database working-directory: src/Octopus.Trident.Database.DbUp run: dotnet publish --output "$GITHUB_WORKSPACE/artifacts/database" -c Release --runtime win-x64 --sc true --p:PublishSingleFile=true --p:PublishTrimmed=true --p:Version=${{ steps.ReleaseNum.outputs.APP_VERSION }} + + - name: package website + id: "website_package" + uses: OctopusDeploy/create-zip-package-action@v3 + with: + package_id: Trident.Web + version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} + base_path: "artifacts/web" + files: "**/*" + output_folder: packaged + + - name: package database + id: "database_package" + uses: OctopusDeploy/create-zip-package-action@v3 + with: + package_id: Trident.Database + version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} + base_path: "artifacts/database" + files: "**/*" + output_folder: packaged + + - name: Upload artifacts to GitHub + uses: actions/upload-artifact@v4 + with: + name: assets-for-download + path: packaged + + - name: push packages to Octopus + uses: OctopusDeploy/push-package-action@v3 + with: + packages: | + packaged/**/*.zip + + - name: push build information to Octopus + uses: OctopusDeploy/push-build-information-action@v3 + with: + packages: | + Trident.Database + Trident.Web + version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} + + - name: create release + uses: OctopusDeploy/create-release-action@v3 + with: + project: ${{ env.OCTOPUS_PROJECT_NAME }} + channel: ${{ steps.ReleaseNum.outputs.OCTOPUS_CHANNEL }} + release_number: ${{ steps.ReleaseNum.outputs.APP_VERSION }} + package_version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} + + - name: deploy release + uses: OctopusDeploy/deploy-release-tenanted-action@v3 + id: "deploy_release" + with: + project: ${{ env.OCTOPUS_PROJECT_NAME }} + release_number: ${{ steps.ReleaseNum.outputs.APP_VERSION }} + environment: ${{ steps.ReleaseNum.outputs.OCTOPUS_ENVIRONMENT }} + tenants: ${{ env.OCTOPUS_TENANT_NAME }} diff --git a/.octopus/deployment_process.ocl b/.octopus/deployment_process.ocl new file mode 100644 index 0000000..63aaee1 --- /dev/null +++ b/.octopus/deployment_process.ocl @@ -0,0 +1,185 @@ +step "calculate-deployment-mode" { + name = "Calculate Deployment Mode" + + action { + properties = { + Octopus.Action.Template.Id = "ActionTemplates-6" + Octopus.Action.Template.Version = "5" + } + worker_pool = "hosted-windows" + worker_pool_variable = "" + } +} + +step "create-database-via-runbook" { + condition = "Variable" + name = "Create Database Via Runbook" + properties = { + Octopus.Step.ConditionVariableExpression = "#{unless Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/unless}" + } + + action { + properties = { + Octopus.Action.Template.Id = "ActionTemplates-5" + Octopus.Action.Template.Version = "18" + Run.Runbook.Api.Key = "#{Project.Runbook.Api.Key}" + Run.Runbook.AutoApproveManualInterventions = "No" + Run.Runbook.Base.Url = "#{Octopus.Web.ServerUri}" + Run.Runbook.CancelInSeconds = "1800" + Run.Runbook.CustomNotes.Toggle = "False" + Run.Runbook.DateTime = "N/A" + Run.Runbook.Environment.Name = "#{Octopus.Environment.Name}" + Run.Runbook.Machines = "N/A" + Run.Runbook.ManualIntervention.EnvironmentToUse = "#{Octopus.Environment.Name}" + Run.Runbook.Name = "Configure SQL Server" + Run.Runbook.Project.Name = "Trident" + Run.Runbook.Space.Name = "#{Octopus.Space.Name}" + Run.Runbook.UsePublishedSnapShot = "True" + Run.Runbook.Waitforfinish = "True" + } + worker_pool = "hosted-windows" + } +} + +step "generate-what-if-report" { + condition = "Variable" + name = "Generate What If Report" + properties = { + Octopus.Step.ConditionVariableExpression = "#{unless Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/unless}" + } + + action { + properties = { + Database.Deploy.ConnectionString = "#{Project.Connection.String}" + Database.Deploy.Package = "{\"PackageId\":\"Trident.Database\",\"FeedId\":\"octopus-server-built-in\"}" + Database.Deploy.PathToDBUpExe = ".\\Octopus.Trident.Database.DbUp" + Database.Deploy.ReportPath = "#{Project.Database.Report.Path}" + Database.Deploy.WhatIf = "true" + Octopus.Action.Template.Id = "ActionTemplates-4" + Octopus.Action.Template.Version = "3" + } + worker_pool = "hosted-windows" + + packages "Database.Deploy.Package" { + acquisition_location = "Server" + feed = "octopus-server-built-in" + package_id = "Trident.Database" + properties = { + Extract = "True" + PackageParameterName = "Database.Deploy.Package" + SelectionMode = "deferred" + } + } + } +} + +step "review-database-changes" { + condition = "Variable" + name = "Review Database Changes." + properties = { + Octopus.Step.ConditionVariableExpression = "#{unless Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/unless}" + } + + action { + action_type = "Octopus.Manual" + environments = ["staging"] + properties = { + Octopus.Action.Manual.BlockConcurrentDeployments = "False" + Octopus.Action.Manual.Instructions = "Please review the database changes from the artifact attached to this deployment." + Octopus.Action.Manual.ResponsibleTeamIds = "dba,global/octopus-managers" + } + } +} + +step "deploy-database-changes" { + condition = "Variable" + name = "Deploy Database Changes" + properties = { + Octopus.Step.ConditionVariableExpression = "#{unless Octopus.Deployment.Error}#{Octopus.Action[Calculate Deployment Mode].Output.RunOnDeploy}#{/unless}" + } + + action { + properties = { + Database.Deploy.ConnectionString = "#{Project.Connection.String}" + Database.Deploy.Package = "{\"PackageId\":\"Trident.Database\",\"FeedId\":\"octopus-server-built-in\"}" + Database.Deploy.PathToDBUpExe = ".\\Octopus.Trident.Database.DbUp" + Database.Deploy.WhatIf = "False" + Octopus.Action.Template.Id = "ActionTemplates-4" + Octopus.Action.Template.Version = "3" + } + worker_pool = "hosted-windows" + + packages "Database.Deploy.Package" { + acquisition_location = "Server" + feed = "octopus-server-built-in" + package_id = "Trident.Database" + properties = { + Extract = "True" + PackageParameterName = "Database.Deploy.Package" + SelectionMode = "deferred" + } + } + } +} + +step "deploy-a-trident-web" { + name = "Deploy a Trident Web" + properties = { + Octopus.Action.TargetRoles = "trident-web" + } + + action { + action_type = "Octopus.TentaclePackage" + properties = { + Octopus.Action.EnabledFeatures = "Octopus.Features.JsonConfigurationVariables" + Octopus.Action.Package.DownloadOnTentacle = "False" + Octopus.Action.Package.FeedId = "octopus-server-built-in" + Octopus.Action.Package.JsonConfigurationVariablesTargets = "appsettings.json" + Octopus.Action.Package.PackageId = "Trident.Web" + } + worker_pool_variable = "" + + packages { + acquisition_location = "Server" + feed = "octopus-server-built-in" + package_id = "Trident.Web" + properties = { + SelectionMode = "immediate" + } + } + } +} + +step "verify-app" { + name = "Verify App" + + action { + action_type = "Octopus.Script" + properties = { + Octopus.Action.Script.ScriptBody = "Write-Host \"This application has been verified.\"" + Octopus.Action.Script.ScriptSource = "Inline" + Octopus.Action.Script.Syntax = "PowerShell" + OctopusUseBundledTooling = "False" + } + worker_pool = "hosted-windows" + } +} + +step "notification" { + condition = "Always" + name = "Notification" + + action { + properties = { + Octopus.Action.Template.Id = "ActionTemplates-1" + Octopus.Action.Template.Version = "15" + ssn_Color = "good" + ssn_HookUrl = "#{Notification.Slack.Webhook.Url}" + ssn_IconUrl = "https://octopus.com/content/resources/favicon.png" + ssn_Message = "#{Notification.Body.Text}" + ssn_Title = "#{Notification.Subject.Text}" + ssn_Username = "Octopus Deploy" + } + worker_pool = "hosted-windows" + } +} \ No newline at end of file diff --git a/.octopus/deployment_settings.ocl b/.octopus/deployment_settings.ocl new file mode 100644 index 0000000..562e7dd --- /dev/null +++ b/.octopus/deployment_settings.ocl @@ -0,0 +1,7 @@ +connectivity_policy { + allow_deployments_to_no_targets = true +} + +versioning_strategy { + template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}" +} \ No newline at end of file diff --git a/.octopus/runbooks/migrated-drafts/configure-sql-server.ocl b/.octopus/runbooks/migrated-drafts/configure-sql-server.ocl new file mode 100644 index 0000000..3295b30 --- /dev/null +++ b/.octopus/runbooks/migrated-drafts/configure-sql-server.ocl @@ -0,0 +1,47 @@ +name = "Configure SQL Server" +default_guided_failure_mode = "EnvironmentDefault" +description = "" + +connectivity_policy { + allow_deployments_to_no_targets = true +} + +run_retention_policy { + type = "Default" +} + +process { + step "install-sql-server" { + name = "Install SQL Server" + + action { + action_type = "Octopus.Script" + properties = { + Octopus.Action.Script.ScriptBody = <<-EOT + Write-Host "Installing SQL Server Localdb" + choco install sqllocaldb -y + EOT + Octopus.Action.Script.ScriptSource = "Inline" + Octopus.Action.Script.Syntax = "PowerShell" + OctopusUseBundledTooling = "False" + } + worker_pool = "hosted-windows" + } + } + + step "sql-create-database-if-not-exists" { + name = "SQL - Create Database If Not Exists" + + action { + properties = { + createCommandTimeout = "30" + createDatabaseName = "#{Project.Database.Name}" + createSqlDatabaseRetryAttempts = "0" + createSqlServer = "#{Project.Database.Server.Name}" + Octopus.Action.Template.Id = "ActionTemplates-2" + Octopus.Action.Template.Version = "5" + } + worker_pool = "hosted-windows" + } + } +} \ No newline at end of file diff --git a/.octopus/schema_version.ocl b/.octopus/schema_version.ocl new file mode 100644 index 0000000..500586e --- /dev/null +++ b/.octopus/schema_version.ocl @@ -0,0 +1 @@ +version = 10 \ No newline at end of file diff --git a/.octopus/variables.ocl b/.octopus/variables.ocl new file mode 100644 index 0000000..28754d8 --- /dev/null +++ b/.octopus/variables.ocl @@ -0,0 +1,45 @@ +variable "ConnectionStrings:Database" { + value "#{Project.Connection.String}" {} +} + +variable "Octopus.ServiceNow.ChangeRequest.Number" { + value { + prompt { + description = "" + display_settings = { + Octopus.ControlType = "SingleLineText" + } + label = "Octopus.ServiceNow.ChangeRequest.Number" + } + } +} + +variable "Project.Connection.String" { + value "Server=#{Project.Database.Server.Name};Integrated Security=true;Database=#{Project.Database.Name}" {} +} + +variable "Project.Database.Name" { + value "Trident" { + environment = ["production"] + } + + value "Trident_Development" { + environment = ["development"] + } + + value "Trident_Staging" { + environment = ["staging"] + } + + value "Trident_Test" { + environment = ["test"] + } +} + +variable "Project.Database.Report.Path" { + value "C:\\DatabaseReports\\\\#{Octopus.Environment.Name}" {} +} + +variable "Project.Database.Server.Name" { + value "(localdb)\\MSSQLLocalDB" {} +} \ No newline at end of file diff --git a/README.md b/README.md index f1454bc..5b14c7d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # OctopusPractitioner -Public Repo containing resources for the Octopus Practitioner Training Course +Public Repo containing resources for the Octopus Practitioner Training Course - Test 2 +CRM-5 \ No newline at end of file