Skip to content

Commit

Permalink
Addi new docker containers (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkisse authored Mar 7, 2024
1 parent 95b5e5e commit 8a6e087
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/tre-sql-pg-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: TRE SQL PG Container

on:
pull_request:
paths:
- 'src/Tre-SQL-PG/**'
push:
branches:
- main
paths:
- 'src/Tre-SQL-PG/**'

permissions:
contents: write
pull-requests: read
actions: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
tre-hasura-container:
uses: SwanseaUniversityMedical/workflows/.github/workflows/pr-and-release-container.yaml@v1.4.2-containers
with:
job-name: tre-sqlpg-container
registry: ${{ vars.HARBOR_REGISTRY }}
registry-user: ${{ vars.HARBOR_USER }}
registry-repo: ${{ vars.HARBOR_PROJECT }}/${{ vars.HARBOR_REPO }}-tre-sqlpg
release-tag-format: 'DARE-TRE-SQLPG-Container-${version}'
cosign-public-key: ${{ vars.COSIGN_PUBLIC_KEY }}
slack-channel: ${{ vars.SLACK_CHANNEL }}
build-file: src/Tre-SQL-PG/Dockerfile
build-context: src
secrets:
cosign-private-key: ${{ secrets.COSIGN_PRIVATE_KEY }}
cosign-password: ${{ secrets.COSIGN_PASSWORD }}
registry-token: ${{ secrets.HARBOR_TOKEN }}
slack-token: ${{ secrets.SLACK_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/tre-sql-trino-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: TRE SQL Trino Container

on:
pull_request:
paths:
- 'src/Tre-SQL-Trino/**'
push:
branches:
- main
paths:
- 'src/Tre-SQL-Trino/**'

permissions:
contents: write
pull-requests: read
actions: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
tre-hasura-container:
uses: SwanseaUniversityMedical/workflows/.github/workflows/pr-and-release-container.yaml@v1.4.2-containers
with:
job-name: tre-sqltrino-container
registry: ${{ vars.HARBOR_REGISTRY }}
registry-user: ${{ vars.HARBOR_USER }}
registry-repo: ${{ vars.HARBOR_PROJECT }}/${{ vars.HARBOR_REPO }}-tre-sqltrino
release-tag-format: 'DARE-TRE-SQLTRINO-Container-${version}'
cosign-public-key: ${{ vars.COSIGN_PUBLIC_KEY }}
slack-channel: ${{ vars.SLACK_CHANNEL }}
build-file: src/Tre-SQL-Trino/Dockerfile
build-context: src
secrets:
cosign-private-key: ${{ secrets.COSIGN_PRIVATE_KEY }}
cosign-password: ${{ secrets.COSIGN_PASSWORD }}
registry-token: ${{ secrets.HARBOR_TOKEN }}
slack-token: ${{ secrets.SLACK_TOKEN }}
14 changes: 14 additions & 0 deletions DARE-Control.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data-Egress-UI", "src\Data-
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tre-Hasura", "src\Tre-Hasura\Tre-Hasura.csproj", "{3BAD3B69-2B08-4E09-BB8A-2611A0990062}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tre-SQL-PG", "src\Tre-SQL-PG\Tre-SQL-PG.csproj", "{C51CB601-57E5-445D-975E-62041FCF65A9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tre-SQL-Trino", "src\Tre-SQL-Trino\Tre-SQL-Trino.csproj", "{B47DC0A4-0691-456F-BBB2-7901E2398526}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -70,6 +74,14 @@ Global
{3BAD3B69-2B08-4E09-BB8A-2611A0990062}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BAD3B69-2B08-4E09-BB8A-2611A0990062}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BAD3B69-2B08-4E09-BB8A-2611A0990062}.Release|Any CPU.Build.0 = Release|Any CPU
{C51CB601-57E5-445D-975E-62041FCF65A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C51CB601-57E5-445D-975E-62041FCF65A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C51CB601-57E5-445D-975E-62041FCF65A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C51CB601-57E5-445D-975E-62041FCF65A9}.Release|Any CPU.Build.0 = Release|Any CPU
{B47DC0A4-0691-456F-BBB2-7901E2398526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B47DC0A4-0691-456F-BBB2-7901E2398526}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B47DC0A4-0691-456F-BBB2-7901E2398526}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B47DC0A4-0691-456F-BBB2-7901E2398526}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -85,6 +97,8 @@ Global
{68369D1D-B5AE-4CED-944C-3FEF0EB23414} = {BCA7B4D1-726B-46EA-90D1-2BD3ACD5154A}
{80C9C407-D56A-4FD1-9FE3-58B046729ADC} = {ED66814A-91F3-4E06-AE48-B7A9F666659E}
{3BAD3B69-2B08-4E09-BB8A-2611A0990062} = {505AD4FB-0822-4989-9A01-1F56C3820D0D}
{C51CB601-57E5-445D-975E-62041FCF65A9} = {505AD4FB-0822-4989-9A01-1F56C3820D0D}
{B47DC0A4-0691-456F-BBB2-7901E2398526} = {505AD4FB-0822-4989-9A01-1F56C3820D0D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29E246A8-202C-4544-A30D-33E0AB416005}
Expand Down
2 changes: 1 addition & 1 deletion src/Tre-Hasura/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Tre_Hasura.Models;


Console.WriteLine("Hello, World!");
Console.WriteLine("TREFX Hashura Runner");
var configuration = GetConfiguration();

using IHost host = Host.CreateDefaultBuilder(args).ConfigureServices
Expand Down
20 changes: 20 additions & 0 deletions src/Tre-SQL-PG/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["src/Tre-SQL-PG/Tre-SQL-PG.csproj", "src/Tre-SQL-PG/"]
RUN dotnet restore "src/Tre-SQL-PG/Tre-SQL-PG.csproj"
COPY . .
WORKDIR "/src/src/Tre-SQL-PG"
RUN dotnet build "Tre-SQL-PG.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Tre-SQL-PG.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Tre-SQL-PG.dll"]
89 changes: 89 additions & 0 deletions src/Tre-SQL-PG/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Data;
using System.IO;
using Npgsql;

Console.WriteLine("TREFX SQL Runner Module : Postgress");

// Tre-SQL-PG.exe "--Query=select * from \"profileForm\"" --Output=data.csv

var Token = "";
var OutputFilename = "data.csv";
var Query = "SELECT * FROM \"profileForm\"";
string connectionString = "Host=localhost:5432;Username=admin;Password=admin;Database=assets3";

foreach (var arg in args)
{
Console.WriteLine("Arg = " + arg);

if (arg.StartsWith("--Output"))
{
OutputFilename = arg.Replace("--Output=", "");
}

if (arg.StartsWith("--Token_"))
{
Token = arg.Replace("--Token_", "");
}

if (arg.StartsWith("--Connection"))
{
connectionString = arg.Replace("--Connection=", "");
}

if (arg.StartsWith("--Query"))
{
Query = arg.Replace("--Query=", "");
}

}

Console.WriteLine("Query > " + Query);
Console.WriteLine("Token > " + Token);
Console.WriteLine("Output > " + OutputFilename);

ExportToCsv(connectionString, Query, OutputFilename);

Console.WriteLine("Completed");



static void ExportToCsv(string connectionString, string sqlQuery, string csvFilePath)
{
using (var connection = new NpgsqlConnection(connectionString))
{
connection.Open();
using (var command = new NpgsqlCommand(sqlQuery, connection))
{
using (var reader = command.ExecuteReader())
{
if (reader.HasRows)
{
using (var streamWriter = new StreamWriter(csvFilePath))
{
// Write column headers
for (int i = 0; i < reader.FieldCount; i++)
{
if (i > 0)
streamWriter.Write(",");
streamWriter.Write(reader.GetName(i));
}
streamWriter.WriteLine();

// Write data rows
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
if (i > 0)
streamWriter.Write(",");
streamWriter.Write(reader[i].ToString());
}
streamWriter.WriteLine();
}
}
}
}
}
}
}
10 changes: 10 additions & 0 deletions src/Tre-SQL-PG/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Tre-SQL-PG": {
"commandName": "Project"
},
"Docker": {
"commandName": "Docker"
}
}
}
18 changes: 18 additions & 0 deletions src/Tre-SQL-PG/Tre-SQL-PG.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Tre_SQL_PG</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Npgsql" Version="8.0.2" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions src/Tre-SQL-Trino/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["src/Tre-SQL-Trino/Tre-SQL-Trino.csproj", "src/Tre-SQL-Trino/"]
RUN dotnet restore "src/Tre-SQL-Trino/Tre-SQL-Trino.csproj"
COPY . .
WORKDIR "/src/src/Tre-SQL-Trino"
RUN dotnet build "Tre-SQL-Trino.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Tre-SQL-Trino.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Tre-SQL-Trino.dll"]
110 changes: 110 additions & 0 deletions src/Tre-SQL-Trino/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using System.Data;
using System.IO;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;

Console.WriteLine("TREFX SQL Runner Module : Trino");

// Tre-SQL-Trino.exe "--Query=select * from \"profileForm\"" --Output=data.csv

string trinoUrl = "http://trino-server:8080/v1/statement";
var Token = "";
var OutputFilename = "data.csv";
var Query = "SELECT * FROM \"profileForm\"";

foreach (var arg in args)
{
Console.WriteLine("Arg = " + arg);

if (arg.StartsWith("--Output"))
{
OutputFilename = arg.Replace("--Output=", "");
}

if (arg.StartsWith("--Token_"))
{
Token = arg.Replace("--Token_", "");
}

if (arg.StartsWith("--Connection"))
{
trinoUrl = arg.Replace("--Connection=", "");
}

if (arg.StartsWith("--Query"))
{
Query = arg.Replace("--Query=", "");
}

}

Console.WriteLine("Query > " + Query);
Console.WriteLine("Token > " + Token);
Console.WriteLine("Output > " + OutputFilename);

await ExportToCsv(trinoUrl, Query, OutputFilename);

Console.WriteLine("Completed");


static async Task ExportToCsv(string trinoUrl, string sqlQuery, string csvFilePath)
{
using (var httpClient = new HttpClient())
{
var requestBody = new
{
query = sqlQuery
};

var requestContent = new StringContent(JsonConvert.SerializeObject(requestBody));
requestContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

using (var response = await httpClient.PostAsync(trinoUrl, requestContent))
{
response.EnsureSuccessStatusCode();

using (var responseStream = await response.Content.ReadAsStreamAsync())
using (var streamReader = new StreamReader(responseStream))
using (var jsonReader = new JsonTextReader(streamReader))
{
var jsonSerializer = new JsonSerializer();

using (var streamWriter = new StreamWriter(csvFilePath))
using (var csvWriter = new CsvHelper.CsvWriter(streamWriter, System.Globalization.CultureInfo.InvariantCulture))
{
while (jsonReader.Read())
{
if (jsonReader.TokenType == JsonToken.StartObject)
{
// Deserialize JSON response into a dynamic object
var jsonObject = jsonSerializer.Deserialize<JObject>(jsonReader);

// Write column headers
var columns = jsonObject["columns"];
foreach (var column in columns)
{
csvWriter.WriteField(column["name"].ToString());
}
csvWriter.NextRecord();

// Write data rows
var data = jsonObject["data"];
foreach (var rowData in data)
{
foreach (var value in rowData)
{
csvWriter.WriteField(value.ToString());
}
csvWriter.NextRecord();
}
}
}
}
}
}
}
}

Loading

0 comments on commit 8a6e087

Please sign in to comment.