Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/enable deployment in azure #7

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#### Description of Change
Describe your changes here and include any background context, dependencies, etc.


#### Testing Instructions
Describe how to test your change and what tests have been added/updated that relate to your change.


#### Issue


#### PR Checklist
- [ ] Has tests (if omitted, state reason in description)
- [ ] Branch name includes Issue ticket
- [ ] Documentation updated (if appropriate)
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy resources on cloud provider

on:
workflow_dispatch:
inputs:
cloud:
description: 'A supported cloud provider our resources will be deployed on'
required: true
default: 'azure-ps1'
type: choice
options:
- azure-ps1
- azure-bicep
- azure-ansible
- azure-terraform
- aws-terraform
- digitalocean-terraform
- digitalocean-ansible

env:
DOCKER_HUB_USER: ${{ vars.DOCKER_HUB_USER }}
DOCKER_IMAGE_NAME: productsmanagement

jobs:
if: inputs.cloud == 'azure-ps1'
deploy-on-azure-ps1:
name: CD Release on Azure (PS1)
runs-on: ubuntu-latest
environment: development

steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in via Az module
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true

- name: Run Azure PowerShell for deployment
uses: azure/powershell@v1
with:
inlineScript: ./cloud/azure/ps1/deploy.ps1
azPSVersion: "latest"
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ jobs:
context: .
file: ./Dockerfile.dev
push: ${{ github.event_name != 'pull_request' }} # Don't push on PR
#push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
173 changes: 173 additions & 0 deletions cloud/azure/ps1/deploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
$ApplicationId = "qrpayments"
$Tags = @{
Provisioner = "PowerShell"
Environment = "Development"
"Technical-Owner" = "TeamDragons"
"Application-Id" = $ApplicationId
"Data-Classification" = "Restricted"
}

$ResourceGroupName = "TeamDragons_rg"
$ResourceGroup = Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction Stop
$Location = $ResourceGroup.Location

# Azure resources to be created
$SqlServerName = $ApplicationId + "sqlserver"
$SqlDatabaseName = $ApplicationId + "database"
$AppServicePlanName = $ApplicationId + "serviceplan"
$WebAppName = $ApplicationId + "webapp"

$AdminUser = "azuser"
$AdminPassSecure = "your@p4ssw0rd" | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential ($AdminUser, $AdminPassSecure)

$CommonProps = @{
ResourceGroupName = $ResourceGroup.ResourceGroupName
Location = $Location
ServerName = $SqlServerName
ServerVersion = "12.0"
SqlAdministratorCredentials = $Credentials
Tags = $Tags
}

Write-Host "1. Get or Create new SQL Server"
$SqlServer = Get-AzSqlServer -ResourceGroupName $ResourceGroupName -ServerName $SqlServerName -ErrorAction SilentlyContinue
if ($null -eq $SqlServer) {
Write-Host "Creating new SQL Server.."
$SqlServer = New-AzSqlServer @CommonProps
}

Write-Host "SQL Server: $($SqlServer.ServerName)"
Write-Host "SQL Server FQDN: $($SqlServer.FullyQualifiedDomainName)"

$CommonProps = @{
ResourceGroupName = $ResourceGroup.ResourceGroupName
DatabaseName = $SqlDatabaseName
ServerName = $SqlServer.ServerName
Edition = "GeneralPurpose" # Free, Basic, Standard, Premiun, GeneralPurpose
ComputeModel = "Provisioned" # Serverless
VCore = 2
ComputeGeneration = "Gen5"
Tags = $Tags
}

Write-Host "2. Get or Create new SQL Database"
$SqlDatabase = Get-AzSqlDatabase -ResourceGroupName $ResourceGroupName -ServerName $SqlDatabaseName -ErrorAction SilentlyContinue
if ($null -eq $SqlDatabase) {
Write-Host "Creating new SQL Database.."
$SqlDatabase = New-AzSqlDatabase @CommonProps
}

Write-Host "SQL Database: $($SqlDatabase.DatabaseName)"

$CommonPropsList = @(
@{
ResourceGroupName = $ResourceGroup.ResourceGroupName
ServerName = $SqlServer.ServerName
FirewallRuleName = "Allow-AllAzureServices"
StartIpAddress = "0.0.0.0"
EndIpAddress = "0.0.0.0"
}
)

Write-Host "3. Get or Create new SQL Server Firewall rules"
foreach ($CommonProps in $CommonPropsList) {
$SqlServerFirewallRule = Get-AzSqlServerFirewallRule -ResourceGroupName $ResourceGroupName -ServerName $SqlServerName -FirewallRuleName $CommonProps.FirewallRuleName -ErrorAction SilentlyContinue
if ($null -eq $SqlServerFirewallRule) {
Write-Host "Creating new SQL Server.."
$SqlServerFirewallRule = New-AzSqlServerFirewallRule @CommonProps
}
Write-Host "Firewall Rule: $($SqlServerFirewallRule.FirewallRuleName)"
}

$CommonProps = @{
ResourceGroupName = $ResourceGroup.ResourceGroupName
Location = $Location
Name = $AppServicePlanName
Tier = "Standard" # Free, Basic, Standard, Premium
NumberofWorkers = 2
WorkerSize = "Medium" # Small, Medium, Large
Linux = $true
Tag = $Tags
}

Write-Host "4. Get or Create new App Service Plan"
$AppServicePlan = Get-AzAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName -ErrorAction SilentlyContinue
if ($null -eq $AppServicePlan) {
Write-Host "Creating new App Service Plan.."
$AppServicePlan = New-AzAppServicePlan @CommonProps
}

Write-Host "App Service Plan: $($AppServicePlan.Name)"

$CommonProps = @{
ResourceGroupName = $ResourceGroup.ResourceGroupName
Location = $Location
Name = $AppServicePlanName
Tier = "Standard" # Free, Basic, Standard, Premium
NumberofWorkers = 2
WorkerSize = "Small" # Small, Medium, Large
Linux = $true
Tag = $Tags
}

Write-Host "1. Get or Create new App Service Plan"
$AppServicePlan = Get-AzAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName -ErrorAction SilentlyContinue
if ($null -eq $AppServicePlan) {
Write-Host "Creating new App Service Plan.."
$AppServicePlan = New-AzAppServicePlan @CommonProps
}
Write-Host "App Service Plan: $($AppServicePlan.Name)"

$CommonWebAppProps = @{
ResourceGroupName = $ResourceGroup.ResourceGroupName
Location = $Location
Name = $WebAppName
AppServicePlan = $AppServicePlan.Id
ContainerImageName = "psharpx/productsmanagement-api:latest"
Tag = $Tags
}

Write-Host "5. Get or Create new Web App"
$WebApp = Get-AzWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -ErrorAction SilentlyContinue
if ($null -eq $WebApp) {
Write-Host "Creating new Web App.."
$WebApp = New-AzWebApp @CommonWebAppProps
}
Write-Host "Web App: $($WebApp.Name)"
Write-Host "Web App Hostname: $($WebApp.DefaultHostName)"


Write-Host "6. Update new Web App"

$AppSettings = @{}
foreach ($Item in $WebApp.SiteConfig.AppSettings) {
$AppSettings[$Item.Name] = $Item.Value
}

# Configure Spring Boot application using environment variables
$AppSettings["SPRING_PROFILES_ACTIVE"] = "dev"
$AppSettings["SERVER_PORT"] = "80"
$AppSettings["DATABASE_HOSTNAME"] = "qrpaymentssqlserver.database.windows.net"
$AppSettings["DATABASE_PORT"] = "1433"
$AppSettings["DATABASE_NAME"] = "qrpaymentsdatabase"
$AppSettings["SPRING_DATASOURCE_USERNAME"] = "azuser"
$AppSettings["SPRING_DATASOURCE_PASSWORD"] = "your@p4ssw0rd"
$AppSettings["SPRING_DATASOURCE_DRIVERCLASSNAME"] = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
$AppSettings["SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT"] = "org.hibernate.dialect.SQLServer2012Dialect"
$AppSettings["SPRING_DATASOURCE_URL"] = "jdbc:sqlserver://qrpaymentssqlserver.database.windows.net:1433;databaseName=qrpaymentsdatabase"

$ContainerImageName = "psharpx/productsmanagement-api:latest"

$CommonWebAppProps = @{
ResourceGroupName = $ResourceGroup.ResourceGroupName
Name = $WebAppName
AppServicePlan = $AppServicePlan.Id
ContainerImageName = $ContainerImageName
AppSettings = $AppSettings
HttpLoggingEnabled = $true
HttpsOnly = $true
}

Write-Host "Web App: $($WebApp.Name)"
Set-AzWebApp @CommonWebAppProps