diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 220f0cd..d4936c6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,13 +1,13 @@ -image: node:lts-alpine - stages: - install - lint - build + - test - publish install-mobile: stage: install + image: node:lts-alpine before_script: - cd src/WorkTime.Mobile script: @@ -15,12 +15,13 @@ install-mobile: cache: key: files: - - package.json + - src/WorkTime.Mobile/package.json paths: - - node_modules + - src/WorkTime.Mobile/node_modules lint-mobile: stage: lint + image: node:lts-alpine needs: ["install-mobile"] before_script: - cd src/WorkTime.Mobile @@ -29,13 +30,14 @@ lint-mobile: cache: key: files: - - package.json + - src/WorkTime.Mobile/package.json paths: - - node_modules + - src/WorkTime.Mobile/node_modules policy: pull build-mobile: stage: build + image: node:lts-alpine needs: ["lint-mobile"] before_script: - cd src/WorkTime.Mobile @@ -43,16 +45,35 @@ build-mobile: - npm run build artifacts: paths: - - $CI_PROJECT_DIR/www + - $CI_PROJECT_DIR/src/WorkTime.Mobile/www expire_in: 10 minutes cache: key: files: - - package.json + - src/WorkTime.Mobile/package.json paths: - - node_modules + - src/WorkTime.Mobile/node_modules policy: pull +build-backend: + stage: build + image: mcr.microsoft.com/dotnet/sdk:9.0 + script: + - dotnet restore + - dotnet build --configuration Release --no-restore + artifacts: + paths: + - "**/bin/Release" + expire_in: 10 minutes + +test-backend: + stage: test + image: mcr.microsoft.com/dotnet/sdk:9.0 + script: + - dotnet test --verbosity normal + dependencies: + - build-backend + publish-mobile: stage: publish needs: ["build-mobile"] @@ -70,3 +91,15 @@ publish-mobile: - docker push registry.leon-hoppe.de/leon.hoppe/worktime:latest only: - tags + +publish-backend: + stage: publish + script: + - export VERSION=$(echo $CI_COMMIT_TAG | sed 's/^v//') + - dotnet pack -c Release -o . /p:Version=$VERSION + - for nupkg in *.nupkg; do dotnet nuget push $nupkg -k ${NUGET_API_KEY} -s https://api.nuget.org/v3/index.json; done + only: + - tags + dependencies: + - build-backend + - test-backend diff --git a/WorkTime.sln b/WorkTime.sln index a55ff74..bb03b9a 100644 --- a/WorkTime.sln +++ b/WorkTime.sln @@ -1,8 +1,21 @@  Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{25C5A6B2-A1F9-4244-9538-18E3FE76D382}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Api", "src\WorkTime.Api\WorkTime.Api.csproj", "{63F71A39-70D8-4F22-8006-C345E0CD4A5C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {63F71A39-70D8-4F22-8006-C345E0CD4A5C} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection EndGlobal diff --git a/src/WorkTime.Api/Dockerfile b/src/WorkTime.Api/Dockerfile new file mode 100644 index 0000000..5e8e0d2 --- /dev/null +++ b/src/WorkTime.Api/Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["src/WorkTime.Api/WorkTime.Api.csproj", "src/WorkTime.Api/"] +RUN dotnet restore "src/WorkTime.Api/WorkTime.Api.csproj" +COPY . . +WORKDIR "/src/src/WorkTime.Api" +RUN dotnet build "WorkTime.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "WorkTime.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "WorkTime.Api.dll"] diff --git a/src/WorkTime.Api/Program.cs b/src/WorkTime.Api/Program.cs new file mode 100644 index 0000000..d9cfd47 --- /dev/null +++ b/src/WorkTime.Api/Program.cs @@ -0,0 +1,15 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi +builder.Services.AddOpenApi(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) { + app.MapOpenApi(); +} + +app.UseHttpsRedirection(); +app.Run(); diff --git a/src/WorkTime.Api/Properties/launchSettings.json b/src/WorkTime.Api/Properties/launchSettings.json new file mode 100644 index 0000000..577246b --- /dev/null +++ b/src/WorkTime.Api/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5295", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7294;http://localhost:5295", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/WorkTime.Api/WorkTime.Api.csproj b/src/WorkTime.Api/WorkTime.Api.csproj new file mode 100644 index 0000000..126398a --- /dev/null +++ b/src/WorkTime.Api/WorkTime.Api.csproj @@ -0,0 +1,20 @@ + + + + net9.0 + enable + enable + Linux + + + + + + + + + .dockerignore + + + + diff --git a/src/WorkTime.Api/appsettings.Development.json b/src/WorkTime.Api/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/WorkTime.Api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/WorkTime.Api/appsettings.json b/src/WorkTime.Api/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/WorkTime.Api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}