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/.github/workflows/api.yml b/.github/workflows/api.yml new file mode 100644 index 0000000..2ace157 --- /dev/null +++ b/.github/workflows/api.yml @@ -0,0 +1,41 @@ +name: .NET + +on: + push: + branches: [ "master" ] + paths: + - 'src/Argon.Api/**' + pull_request: + branches: [ "master" ] + paths: + - 'src/Argon.Api/**' + +jobs: + qa: + runs-on: ARM64 + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + build: +# if: github.ref == 'refs/heads/master' + runs-on: ARM64 + needs: qa + steps: + - name: Log in to GitHub Docker Registry + uses: docker/login-action@v1 + with: + registry: ${{ secrets.REGISTRY }} + username: ${{ secrets.CR_USER }} + password: ${{ secrets.CR_PWD }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./src/Argon.Api/Dockerfile + push: true + tags: reg.staging.svck.dev/argon/api-orleans:${{ github.run_number }} +# platforms: linux/arm64/v8 + \ No newline at end of file diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml deleted file mode 100644 index 6b96b57..0000000 --- a/.github/workflows/dotnet.yml +++ /dev/null @@ -1,28 +0,0 @@ -# This workflow will build a .NET project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net - -name: .NET - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - # - name: Restore dependencies - # run: dotnet restore - # - name: Build - # run: dotnet build --no-restore - # - name: Test - # run: dotnet test --no-build --verbosity normal diff --git a/src/Argon.Api/Argon.Api.csproj b/src/Argon.Api/Argon.Api.csproj index ede983a..ecf2e7e 100644 --- a/src/Argon.Api/Argon.Api.csproj +++ b/src/Argon.Api/Argon.Api.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + Linux @@ -23,4 +24,10 @@ + + + .dockerignore + + + diff --git a/src/Argon.Api/Dockerfile b/src/Argon.Api/Dockerfile new file mode 100644 index 0000000..84630df --- /dev/null +++ b/src/Argon.Api/Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine-arm64v8 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine-arm64v8 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["src/Argon.Api/Argon.Api.csproj", "src/Argon.Api/"] +COPY ["src/ServiceDefaults/ServiceDefaults.csproj", "src/ServiceDefaults/"] +RUN dotnet restore "src/Argon.Api/Argon.Api.csproj" +COPY . . +WORKDIR "/src/src/Argon.Api" +RUN dotnet build "Argon.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "Argon.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Argon.Api.dll"] diff --git a/src/Argon.Api/Program.cs b/src/Argon.Api/Program.cs index 6502a28..1a1cb98 100644 --- a/src/Argon.Api/Program.cs +++ b/src/Argon.Api/Program.cs @@ -21,20 +21,21 @@ public static async Task Main(string[] args) siloBuilder.AddMemoryGrainStorage("replaceme"); // TODO: replace me pls }); var app = builder.Build(); + app.UseSwagger(); + app.UseSwaggerUI(); if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); using var scope = app.Services.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); Thread.Sleep(5000); await db.Database.MigrateAsync(); } - app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.MapDefaultEndpoints(); + var buildTime = File.GetLastWriteTimeUtc(typeof(Program).Assembly.Location); + app.MapGet("/", () => new { buildTime = buildTime }); await app.RunAsync(); } } \ No newline at end of file diff --git a/src/Argon.Api/appsettings.json b/src/Argon.Api/appsettings.json index f943254..a41c41d 100644 --- a/src/Argon.Api/appsettings.json +++ b/src/Argon.Api/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Host=database;Port=5432;Username=svck;Password=Password123;Database=apiDb", + "DefaultConnection": "Host=localhost;Port=5432;Username=svck;Password=1ed1f86a265ecffa4c0de1a1;Database=argon_api", "cache": "localhost:1500", "rmq": "amqp://svck:Password123@localhost:5672" },