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

Develop #8

Merged
merged 3 commits 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:
deploy-on-azure-ps1:
if: inputs.cloud == '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 @@ -2,13 +2,13 @@ name: Publish Docker Image

on:
push:
branches: [ master ]
branches: [ develop, master ]
pull_request:
branches: [ master ]

env:
DOCKER_HUB_USER: ${{ vars.DOCKER_HUB_USER }}
DOCKER_IMAGE_NAME: productsmanagement-api
DOCKER_IMAGE_NAME: productsmanagement
# github.repository as <account>/<repo>
#IMAGE_NAME: ${{ github.repository }}

Expand Down 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 }}
8 changes: 4 additions & 4 deletions build_image.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/sh
#echo Building psharpx/productsmanagement-api:v1.0
echo Building psharpx/productsmanagement-api:v1.0
#echo Building psharpx/productsmanagement:v1.0
echo Building psharpx/productsmanagement:v1.0

docker build --no-cache -t psharpx/productsmanagement-api:v1.0 . -f Dockerfile
#docker build --no-cache -t psharpx/productsmanagement-api:v1.0 . -f Dockerfile.client
docker build --no-cache -t psharpx/productsmanagement:v1.0 . -f Dockerfile
#docker build --no-cache -t psharpx/productsmanagement:v1.0 . -f Dockerfile.client

echo Building was successful !!...

Expand Down
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
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
build:
context: ./
dockerfile: Dockerfile
image: psharpx/productsmanagement-api:${TAG}
image: psharpx/productsmanagement:${TAG}
container_name: api_productsmanagement
hostname: ${API_HOSTNAME}
networks:
Expand All @@ -43,10 +43,8 @@ services:
- db
restart: always
environment:
- SPRING_PROFILES_ACTIVE=prod
- DATABASE_HOSTNAME=${DATABASE_HOSTNAME}
- DATABASE_PORT=${DATABASE_PORT}
- DATABASE_NAME=${DATABASE_NAME}
- SPRING_PROFILES_ACTIVE=dev
- SPRING_DATASOURCE_URL=jdbc:postgresql://${DATABASE_HOSTNAME}:${DATABASE_PORT}/${DATABASE_NAME}
- SPRING_DATASOURCE_USERNAME=${DATABASE_USER}
- SPRING_DATASOURCE_PASSWORD=${DATABASE_PASSWORD}
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
Expand Down
1 change: 1 addition & 0 deletions k8s/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ stringData:
DATABASE_PORT: '5432'
DATABASE_PASSWORD: productsmanagement-pass
DATABASE_USER: productsmanagement-user
SPRING_DATASOURCE_URL: jdbc:postgresql://productsmanagement-database-service:5432/productsmanagement_database
API_HOSTNAME: api.productsmanagement.pe
13 changes: 3 additions & 10 deletions k8s/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,19 @@ spec:
spec:
containers:
- name: productsmanagement-server
image: psharpx/productsmanagement-api:latest
image: psharpx/productsmanagement:latest
ports:
- containerPort: 8080
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
- name: DATABASE_HOSTNAME
value: productsmanagement-database-service
- name: SPRING_JPA_HIBERNATE_DDL_AUTO
value: update
- name: DATABASE_NAME
- name: SPRING_DATASOURCE_URL
valueFrom:
secretKeyRef:
name: productsmanagement.secret
key: DATABASE_NAME
- name: DATABASE_PORT
valueFrom:
secretKeyRef:
name: productsmanagement.secret
key: DATABASE_PORT
key: SPRING_DATASOURCE_URL
- name: SPRING_DATASOURCE_USERNAME
valueFrom:
secretKeyRef:
Expand Down
2 changes: 1 addition & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
local:
push: false
artifacts:
- image: psharpx/productsmanagement-api
- image: psharpx/productsmanagement
context: .
buildpacks:
builder: paketobuildpacks/builder:base
Expand Down
2 changes: 1 addition & 1 deletion skaffold/skaffold-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
local:
push: false
artifacts:
- image: psharpx/productsmanagement-api
- image: psharpx/productsmanagement
context: .
docker:
dockerfile: Dockerfile.dev
Expand Down
2 changes: 1 addition & 1 deletion skaffold/skaffold-jib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
local:
push: false
artifacts:
- image: psharpx/productsmanagement-api
- image: psharpx/productsmanagement
context: .
jib:
type: maven
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
server.port=8080

spring.datasource.url=jdbc:postgresql://localhost:5432/myapp
spring.datasource.username=myapp
spring.datasource.password=dbpass
spring.jpa.hibernate.ddl-auto=update

spring.devtools.restart.enabled=true
spring.devtools.restart.trigger-file=.reloadtrigger
8 changes: 0 additions & 8 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
database.hostname=192.168.99.12
database.port=5432
database.name=myapp

spring.datasource.username=myapp
spring.datasource.password=dbpass
spring.jpa.hibernate.ddl-auto=update

tp.api.host=run.mocky.io
tp.api.port=
tp.api.services.detail=/v3/37041c07-02f6-4b8b-a926-533c36659c98
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application-test.properties

This file was deleted.

Loading