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

Basic Setup for File Service and Some Refactoring #28

Merged
merged 12 commits into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
fi
docker buildx build \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION} \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/auth-service:${IMAGE_VERSION} \
-f ./backend/src/AuthService/Dockerfile \
./backend/src

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jobs:
curl --fail http://0.0.0.0:8000/auth/health && break || sleep 5
done
curl --fail http://0.0.0.0:8000/auth/health || exit 1

- name: Health Check FileService
run: |
echo "Checking health..."
for i in {1..10}; do
curl --fail http://0.0.0.0:8000/file/health && break || sleep 5
done
curl --fail http://0.0.0.0:8000/file/health || exit 1

- name: Health Check PostService
run: |
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: File Service CI/CD Pipeline

on:
push:
paths:
- backend/src/**
- .github/workflows/file.yml
branches:
- master
- develop
tags:
- 'v*'
pull_request:
types: [opened, synchronize, reopened]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run reusable Build and Test action
uses: ./.github/actions/build-and-test
with:
backendCsprojPath: ./backend/src/FileService/FileService.Api/FileService.Api.csproj
# unitTestsProjectPath: ./backend/tests/FileService/FileService.Domain.Tests/FileService.Domain.Tests.csproj
buildConfiguration: Release
serviceName: FileService

docker:
needs: build-and-test
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin

- name: Build Docker image
run: |
IMAGE_VERSION="latest"
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
fi
docker buildx build \
-t ${{ secrets.DOCKER_HUB_USERNAME }}/file-service:${IMAGE_VERSION} \
-f ./backend/src/FileService/Dockerfile \
./backend/src

- name: Push Docker image to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: |
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/file-service:${IMAGE_VERSION}
42 changes: 42 additions & 0 deletions FitnessApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\compose-build.yml = .github\workflows\compose-build.yml
.github\workflows\frontend.yml = .github\workflows\frontend.yml
.github\workflows\post.yml = .github\workflows\post.yml
.github\workflows\file.yml = .github\workflows\file.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "actions", "actions", "{499BA3B4-A81F-4079-B256-CC04927BB06D}"
Expand All @@ -83,6 +84,21 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gateway", "backend\src\Gate
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gateway", "backend\src\Gateway\Gateway\Gateway.csproj", "{830B4F05-7C89-4C0F-B27D-B1008B605E79}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FileService", "FileService", "{43F219C3-D6F8-4BA4-890D-4411CCEA3034}"
ProjectSection(SolutionItems) = preProject
backend\src\FileService\Dockerfile = backend\src\FileService\Dockerfile
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileService.Api", "backend\src\FileService\FileService.Api\FileService.Api.csproj", "{A42D3D0A-750D-4E69-ACD5-751D64BC50E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileService.Domain", "backend\src\FileService\FileService.Domain\FileService.Domain.csproj", "{757BB459-C6FF-4286-BF77-BBA57C201731}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileService.Application", "backend\src\FileService\FileService.Application\FileService.Application.csproj", "{222CCDC4-3D79-4954-B7E0-736D474270D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileService.Persistence", "backend\src\FileService\FileService.Persistence\FileService.Persistence.csproj", "{2F748171-33D6-484F-924C-21539C87483E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileService.Infrastructure", "backend\src\FileService\FileService.Infrastructure\FileService.Infrastructure.csproj", "{4938EBCD-F47E-4ABF-AD79-A5DEB42341DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -153,6 +169,26 @@ Global
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Release|Any CPU.Build.0 = Release|Any CPU
{A42D3D0A-750D-4E69-ACD5-751D64BC50E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A42D3D0A-750D-4E69-ACD5-751D64BC50E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A42D3D0A-750D-4E69-ACD5-751D64BC50E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A42D3D0A-750D-4E69-ACD5-751D64BC50E9}.Release|Any CPU.Build.0 = Release|Any CPU
{757BB459-C6FF-4286-BF77-BBA57C201731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{757BB459-C6FF-4286-BF77-BBA57C201731}.Debug|Any CPU.Build.0 = Debug|Any CPU
{757BB459-C6FF-4286-BF77-BBA57C201731}.Release|Any CPU.ActiveCfg = Release|Any CPU
{757BB459-C6FF-4286-BF77-BBA57C201731}.Release|Any CPU.Build.0 = Release|Any CPU
{222CCDC4-3D79-4954-B7E0-736D474270D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{222CCDC4-3D79-4954-B7E0-736D474270D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{222CCDC4-3D79-4954-B7E0-736D474270D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{222CCDC4-3D79-4954-B7E0-736D474270D6}.Release|Any CPU.Build.0 = Release|Any CPU
{2F748171-33D6-484F-924C-21539C87483E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F748171-33D6-484F-924C-21539C87483E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F748171-33D6-484F-924C-21539C87483E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F748171-33D6-484F-924C-21539C87483E}.Release|Any CPU.Build.0 = Release|Any CPU
{4938EBCD-F47E-4ABF-AD79-A5DEB42341DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4938EBCD-F47E-4ABF-AD79-A5DEB42341DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4938EBCD-F47E-4ABF-AD79-A5DEB42341DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4938EBCD-F47E-4ABF-AD79-A5DEB42341DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2E44C019-ED30-4671-A878-D2F7B6071024} = {84AE3F00-9A59-4A8D-A737-67AB74E5D1FD}
Expand Down Expand Up @@ -180,5 +216,11 @@ Global
{334DF17C-BD69-47B9-B4D0-ACB5AD6223CF} = {112E9C63-BF62-49C1-AD19-03855535225B}
{DC9B9F00-24BF-4AD3-B45A-38BFCFC309D7} = {B7E4E4CF-E7A9-4DAC-807E-DFF17553BAE8}
{830B4F05-7C89-4C0F-B27D-B1008B605E79} = {DC9B9F00-24BF-4AD3-B45A-38BFCFC309D7}
{43F219C3-D6F8-4BA4-890D-4411CCEA3034} = {B7E4E4CF-E7A9-4DAC-807E-DFF17553BAE8}
{A42D3D0A-750D-4E69-ACD5-751D64BC50E9} = {43F219C3-D6F8-4BA4-890D-4411CCEA3034}
{757BB459-C6FF-4286-BF77-BBA57C201731} = {43F219C3-D6F8-4BA4-890D-4411CCEA3034}
{222CCDC4-3D79-4954-B7E0-736D474270D6} = {43F219C3-D6F8-4BA4-890D-4411CCEA3034}
{2F748171-33D6-484F-924C-21539C87483E} = {43F219C3-D6F8-4BA4-890D-4411CCEA3034}
{4938EBCD-F47E-4ABF-AD79-A5DEB42341DA} = {43F219C3-D6F8-4BA4-890D-4411CCEA3034}
EndGlobalSection
EndGlobal
34 changes: 34 additions & 0 deletions backend/src/FileService/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8004

RUN apt-get update && apt-get install -y curl && apt-get clean

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src

COPY FileService/FileService.Api/FileService.Api.csproj FileService/FileService.Api/
COPY FileService/FileService.Application/FileService.Application.csproj FileService/FileService.Application/
COPY FileService/FileService.Domain/FileService.Domain.csproj FileService/FileService.Domain/
COPY FileService/FileService.Infrastructure/FileService.Infrastructure.csproj FileService/FileService.Infrastructure/
COPY FileService/FileService.Persistence/FileService.Persistence.csproj FileService/FileService.Persistence/
COPY Shared/Shared.Application/Shared.Application.csproj Shared/Shared.Application/
COPY Shared/Shared.DTO/Shared.DTO.csproj Shared/Shared.DTO/

RUN dotnet restore FileService/FileService.Api/FileService.Api.csproj

COPY . .

WORKDIR /src/FileService/FileService.Api

RUN dotnet build FileService.Api.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish FileService.Api.csproj -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "FileService.Api.dll"]
22 changes: 22 additions & 0 deletions backend/src/FileService/FileService.Api/FileService.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FileService.Application\FileService.Application.csproj" />
<ProjectReference Include="..\FileService.Infrastructure\FileService.Infrastructure.csproj" />
<ProjectReference Include="..\FileService.Persistence\FileService.Persistence.csproj" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions backend/src/FileService/FileService.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FileService.Application;
using FileService.Domain.Constants;
using FileService.Infrastructure;
using FileService.Persistence;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

var hostingUrl = builder.Configuration[AppSettingsConstants.WebHostUrl];

builder.WebHost.UseUrls(hostingUrl ?? throw new ArgumentNullException(nameof(hostingUrl), "Hosting URL is not configured."));

builder.Services
.AddPersistenceServices(builder.Configuration)
.AddInfrastructureServices(builder.Configuration)
.AddApplicationServices();

var app = builder.Build();

using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<FileDbContext>();
dbContext.Database.Migrate();
}

app.MapGet("/health", () => Results.Ok("Healthy"));

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:13401",
"sslPort": 44319
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "graphql",
"applicationUrl": "http://localhost:8004",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "graphql",
"applicationUrl": "https://localhost:7144;http://localhost:8004",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
14 changes: 14 additions & 0 deletions backend/src/FileService/FileService.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"WebHostUrl": "http://0.0.0.0:8004",
"ConnectionStrings": {
"DatabaseConnectionString": "Host=localhost;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=FileDb",
"AzureStorageConnectionString": "AccountName=sentemon;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=https;BlobEndpoint=https://localhost:10000/sentemon"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;

namespace FileService.Application;

public static class DependencyInjection
{
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace FileService.Domain.Constants;

public static class AppSettingsConstants
{
public const string WebHostUrl = "WebHostUrl";
public const string DatabaseConnectionString = "DatabaseConnectionString";
public const string AzureStorageConnectionString = "AzureStorageConnectionString";
}
24 changes: 24 additions & 0 deletions backend/src/FileService/FileService.Domain/Entities/File.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace FileService.Domain.Entities;

public class File
{
public Guid Id { get; private set; }
public string Name { get; private set; }
public string BlobName { get; private set; }
public long Size { get; private set; }
public string OwnerId { get; private set; }
public DateTime CreatedAt { get; private set; }

private File(string name, string blobName, long size, string ownerId)
{
Name = name;
BlobName = blobName;
Size = size;
OwnerId = ownerId;
}

public static File CreateFile(string name, string blobName, long size, string ownerId)
{
return new File(name, blobName, size, ownerId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Azure.Storage.Blobs;
using FileService.Domain.Constants;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace FileService.Infrastructure;

public static class DependencyInjection
{
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{
var azureStorageConnectionString = configuration.GetConnectionString(AppSettingsConstants.AzureStorageConnectionString);

services.AddSingleton(new BlobServiceClient(azureStorageConnectionString));

return services;
}
}
Loading
Loading