Skip to content

Commit

Permalink
Azure scripts to deploy JTL containers (#87)
Browse files Browse the repository at this point in the history
* Azure scripts to deploy JTL containers

Co-authored-by: Eshan MD <eshan.md@proenco.com>
  • Loading branch information
C0DINGpanda and Eshan MD committed Sep 17, 2021
1 parent ca4bfe6 commit d908151
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 0 deletions.
93 changes: 93 additions & 0 deletions azure-deployment/DeployJTLReport.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
$ResourceGroup = "<ResourceGroup Name>"
$Storageaccountname = "<Storage account name>"
$storageKey = "<Storage key>"
$mongodbshareName = "<MongoDB Fileshare name >"
$postgresdbFileshare = "<postgresDB Fileshare name >"
$JWT_TOKEN = "27JU4qy73hchTMLoH8w9m"
$JWT_TOKEN_LOGIN = "GdK6TrCvX7rJRZJVg4ijt"



#create Postgres container
$postObj = @{ }
$postObj.Add("containerGroupName", "postgres")
$postObj.Add("Storageaccountname", $Storageaccountname)
$postObj.Add("storageKey", $storageKey)
$postObj.Add("postgresdbFileshare", $postgresdbFileshare)
$postgres = New-AzResourceGroupDeployment -name "postgres" -ResourceGroupName $ResourceGroup `
-TemplateParameterObject $postObj -TemplateFile "$($PSScriptRoot)\postgresARM.json"

$MyServer = $postgres.outputs.Values[0].value
$MyPort = "5432"
$MyUid = "postgres"
$MyPass = "postgres"

$DBConnectionString = "Driver={PostgreSQL UNICODE(x64)};Server=$MyServer;Port=$MyPort;Uid=$MyUid;Pwd=$MyPass;"
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = "CREATE DATABASE jtl_report;"
$DBCmd.ExecuteReader();
$DBConn.Close();

$DBConnectionString = "Driver={PostgreSQL UNICODE(x64)};Server=$MyServer;Port=$MyPort;Database=jtl_report;Uid=$MyUid;Pwd=$MyPass;"
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = 'CREATE EXTENSION "uuid-ossp";
CREATE SCHEMA IF NOT EXISTS jtl;
CREATE TABLE jtl.projects(
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
project_name character varying(50) NOT NULL UNIQUE
);
CREATE TABLE jtl.items (
id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
test_name character varying(40) NOT NULL,
project_id uuid NOT NULL REFERENCES jtl.projects(id),
jtl_data jsonb NOT NULL,
note character varying(150),
environment character varying(20),
upload_time timestamp without time zone DEFAULT now(),
start_time timestamp without time zone,
duration integer
);
CREATE TABLE jtl.item_stat (
id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
item_id uuid NOT NULL REFERENCES jtl.items(id),
stats jsonb NOT NULL
);
';
$DBCmd.ExecuteReader();
$DBConn.Close();

#Run migrate container
$DATABASE_URL = "postgres://postgres:postgres@$($MyServer):5432/jtl_report"
$postObj = @{ }
$postObj.Add("containerGroupName", "migration")
$postObj.Add("DATABASE_URL", $DATABASE_URL)
$postObj.Add("JWT_TOKEN_LOGIN", $JWT_TOKEN_LOGIN)
$postObj.Add("JWT_TOKEN", $JWT_TOKEN)

$postgres = New-AzResourceGroupDeployment -name "Migration" -ResourceGroupName $ResourceGroup `
-TemplateParameterObject $postObj -TemplateFile "$($PSScriptRoot)\Migration.json"


#Run other containers
$postObj = @{ }
$postObj.Add("containerGroupName", "JtlReporter")
$postObj.Add("Storageaccountname", $Storageaccountname)
$postObj.Add("storageKey", $storageKey)
$postObj.Add("JWT_TOKEN", $JWT_TOKEN)
$postObj.Add("JWT_TOKEN_LOGIN", $JWT_TOKEN_LOGIN)
$postObj.Add("PostgresIP", $MyServer)
$postObj.Add("mongodbshareName", $mongodbshareName)

$postgres = New-AzResourceGroupDeployment -name "JtlReporter" -ResourceGroupName $ResourceGroup `
-TemplateParameterObject $postObj -TemplateFile "$($PSScriptRoot)\JtlReporterArm.json"

211 changes: 211 additions & 0 deletions azure-deployment/JtlReporterArm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"containerGroupName": {
"type": "string",
"defaultValue": "jtlreportr"
},
"mongodbshareName": {
"type": "string",
"defaultValue": "mongodb"
},
"Storageaccountname": {
"type": "string"
},
"storageKey": {
"type": "string"
},
"JWT_TOKEN": {
"type": "string",
"defaultValue": "27JU4qy73hchTMLoH8w9m"
},
"JWT_TOKEN_LOGIN": {
"type": "string",
"defaultValue": "GdK6TrCvX7rJRZJVg4ijt"
},
"PostgresIP": {
"type": "string",
"defaultValue": "127.0.0.1"
}
},
"variables": {
"location": "northeurope",
"container2name": "be",
"container2image": "novyl/jtl-reporter-be:latest",
"container1name": "listener",
"container1image": "novyl/jtl-reporter-listener-service:latest",
"container3name": "fe",
"container3image": "novyl/jtl-reporter-fe:latest",
"container4name": "mongodb",
"container4image": "mongo:latest"
},
"resources": [
{
"name": "[parameters('containerGroupName')]",
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2021-03-01",
"location": "[variables('location')]",
"properties": {
"containers": [
{
"name": "[variables('container4name')]",
"properties": {
"image": "[variables('container4image')]",
"environmentVariables": [
{
"name": "MONGO_INITDB_DATABASE",
"value": "jtl-data"
}
],
"ports": [
{
"port": 27017
}
],
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1
}
},
"volumeMounts": [
{
"name": "mongodb",
"mountPath": "[concat('/data/', variables('container4name'), 'az')]"
}
]
}
},
{
"name": "[variables('container1name')]",
"properties": {
"image": "[variables('container1image')]",
"command": [ "/bin/sh", "-c", "echo '127.0.0.1 be' >> /etc/hosts; echo '127.0.0.1 fe' >> /etc/hosts;echo '127.0.0.1 listener' >> /etc/hosts; echo '127.0.0.1 mongodb' >> /etc/hosts; npm run start" ],
"environmentVariables": [
{
"name": "JWT_TOKEN",
"value": "[parameters('JWT_TOKEN')]"
},
{
"name": "MONGO_CONNECTION_STRING",
"value": "mongodb://mongodb:27017"
}
],
"ports": [
{
"port": 6000
}
],
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1
}
}
}
},
{
"name": "[variables('container2name')]",
"properties": {
"image": "[variables('container2image')]",
"environmentVariables": [
{
"name": "DB_HOST",
"value": "[parameters('PostgresIP')]"
},
{
"name": "DB_PASS",
"value": "postgres"
},
{
"name": "DB_USER",
"value": "postgres"
},
{
"name": "MONGO_CONNECTION_STRING",
"value": "mongodb://mongodb:27017"
},
{
"name": "JWT_TOKEN",
"value":"[parameters('JWT_TOKEN')]"
},
{
"name": "JWT_TOKEN_LOGIN",
"value": "[parameters('JWT_TOKEN_LOGIN')]"
}
],
"ports": [
{
"port": 5000
}
],
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1
}
}
}
},
{
"name": "[variables('container3name')]",
"properties": {
"image": "[variables('container3image')]",
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1
}
},
"ports": [
{
"port": 80
},
{
"port": 2020
}
]
}
}
],
"osType": "Linux",
"volumes": [
{
"name": "mongodb",
"azureFile": {
"shareName": "[parameters('mongodbshareName')]",
"storageAccountName": "[parameters('Storageaccountname')]",
"storageAccountKey": "[parameters('storageKey')]"
}
}
],
"ipAddress": {
"type": "Public",
"ports": [
{
"protocol": "tcp",
"port": 80
},
{
"protocol": "tcp",
"port": 5000
},
{
"protocol": "tcp",
"port": 2020
},
{
"protocol": "tcp",
"port": 27017
},
{
"protocol": "tcp",
"port": 6000
}
]
}
}
}
]
}
82 changes: 82 additions & 0 deletions azure-deployment/Migration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"containerGroupName": {
"type": "string",
"defaultValue": "migration"
},
"JWT_TOKEN": {
"type": "string",
"defaultValue": "27JU4qy73hchTMLoH8w9m"
},
"JWT_TOKEN_LOGIN": {
"type": "string",
"defaultValue": "GdK6TrCvX7rJRZJVg4ijt"
},
"DATABASE_URL": {
"type": "string",
"defaultValue": "postgres://postgres:postgres@127.0.0.1:5432/jtl_report"
}
},
"variables": {
"location": "northeurope"
},
"resources": [
{
"name": "[parameters('containerGroupName')]",
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2021-03-01",
"location": "[variables('location')]",
"properties": {
"containers": [
{
"name": "migration",
"properties": {
"image": "novyl/jtl-reporter-be:latest",
"command": [ "/bin/sh", "-c", "npm run migrate up" ],
"environmentVariables": [
{
"name": "DATABASE_URL",
"value": "[parameters('DATABASE_URL')]"
},
{
"name": "JWT_TOKEN",
"value": "[parameters('JWT_TOKEN')]"
},
{
"name": "JWT_TOKEN_LOGIN",
"value": "[parameters('JWT_TOKEN_LOGIN')]"
}
],
"resources": {
"requests": {
"cpu": 0.5,
"memoryInGb": 1
}
},
"ports": [
{
"port": 80
}
]
}
}
],
"osType": "Linux",
"restartPolicy": "Never",
"volumes": [
],
"ipAddress": {
"type": "Public",
"ports": [
{
"protocol": "tcp",
"port": 80
}
]
}
}
}
]
}

0 comments on commit d908151

Please sign in to comment.