Skip to content

Commit d48c77b

Browse files
committed
Complete revamp in .NET 8
1 parent a361896 commit d48c77b

30 files changed

+562
-689
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bin/
2+
Dockerfile
3+
.dockerignore
4+
.git
5+
.github
6+
.gitignore
7+
*.md
8+
obj/
9+
*.sh
10+
tmp*
11+
*tmp

.github/workflows/gcr-deploy.yaml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
workflow_dispatch:
9+
10+
# Environment variables available to all jobs and steps in this workflow
11+
# NOTE: these aren't really secret, but there aren't non-secret settings
12+
env:
13+
RUN_PROJECT: ${{ secrets.RUN_PROJECT }}
14+
RUN_REGION: ${{ secrets.RUN_REGION }}
15+
RUN_SERVICE: ${{ secrets.RUN_SERVICE }}
16+
17+
jobs:
18+
deploy:
19+
name: Deploy to CloudRun
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: gcloud auth
27+
id: 'auth'
28+
uses: 'google-github-actions/auth@v2'
29+
with:
30+
credentials_json: '${{ secrets.GCP_SA_KEY }}'
31+
32+
# Setup gcloud CLI
33+
- name: gcloud setup
34+
uses: google-github-actions/setup-gcloud@v2
35+
36+
- name: gcloud docker-auth
37+
run: gcloud auth configure-docker
38+
39+
# Build and push image to Google Container Registry
40+
- name: Build
41+
run: |
42+
docker build \
43+
--build-arg COMMIT=${GITHUB_SHA:0:7} \
44+
--build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
45+
--tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
46+
.
47+
48+
- name: GCloud auth to docker
49+
run: |
50+
gcloud auth configure-docker
51+
52+
- name: Push to registry
53+
run: |
54+
docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA
55+
56+
# Deploy image to Cloud Run
57+
- name: Deploy
58+
run: |
59+
gcloud run deploy ${RUN_SERVICE} \
60+
--allow-unauthenticated \
61+
--image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
62+
--platform managed \
63+
--project ${RUN_PROJECT} \
64+
--region ${RUN_REGION}

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bin
2+
.DS_Store
3+
*.env*
4+
obj
5+
*tmp
6+
tmp*

Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0-noble AS builder
2+
ARG TARGETARCH
3+
4+
# Copy project file and restore as distinct layers
5+
WORKDIR /source
6+
#COPY --link ./*.csproj .
7+
#RUN dotnet restore -a $TARGETARCH
8+
9+
# Copy source code and publish app
10+
COPY --link . .
11+
#RUN dotnet publish -a $TARGETARCH --no-restore -c Release
12+
RUN dotnet publish -c Release
13+
14+
RUN find .
15+
16+
#CMD ["/source/bin/Release/net8.0/publish/regexplanet-dotnet.dll"]
17+
#
18+
# final image
19+
#
20+
FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled-extra
21+
WORKDIR /app
22+
COPY --from=builder /source/bin/Release/net8.0/publish /app
23+
COPY ./wwwroot /app/wwwroot
24+
25+
CMD ["/app/regexplanet-dotnet.dll"]

Program.cs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Text.Json;
2+
using Microsoft.AspNetCore.HttpLogging;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
builder.Services.AddHttpLogging(logging =>
6+
{
7+
logging.LoggingFields = HttpLoggingFields.All;
8+
logging.CombineLogs = true;
9+
});
10+
11+
var app = builder.Build();
12+
13+
app.UseHttpLogging();
14+
15+
app.UseStaticFiles();
16+
17+
app.MapGet("/", () => "Running!");
18+
app.MapGet("/status.json", IResult (HttpContext theContext) =>
19+
{
20+
var statusResult = new StatusResult(true,
21+
$".NET {Environment.Version}",
22+
Environment.Version.ToString(),
23+
DateTime.UtcNow.ToString("o"),
24+
Environment.GetEnvironmentVariable("LASTMOD") ?? "(local)",
25+
Environment.GetEnvironmentVariable("COMMIT") ?? "(local)"
26+
);
27+
28+
var callback = theContext.Request.Query["callback"];
29+
if (string.IsNullOrEmpty(callback)) {
30+
return Results.Json(statusResult);
31+
}
32+
string json = JsonSerializer.Serialize(statusResult);
33+
return Results.Content($"{callback}({json});", "application/javascript");
34+
});
35+
36+
app.MapPost("/test.json", static async (HttpContext theContext) =>
37+
{
38+
// read form variables
39+
var form = await theContext.Request.ReadFormAsync();
40+
var regex = form["regex"].FirstOrDefault();
41+
var replacement = form["replacement"].FirstOrDefault();
42+
var input = form["input"].ToArray() ?? new string[] { };
43+
44+
var html = $"{regex} {replacement} {input.Length} {input.FirstOrDefault()}";
45+
46+
var testOutput = new TestOutput(true, html);
47+
48+
var callback = theContext.Request.Query["callback"];
49+
if (string.IsNullOrEmpty(callback)) {
50+
return Results.Json(testOutput);
51+
}
52+
string json = JsonSerializer.Serialize(testOutput);
53+
return Results.Content($"{callback}({json});", "application/javascript");
54+
});
55+
56+
var hostname = Environment.GetEnvironmentVariable("HOSTNAME") ?? "0.0.0.0";
57+
var port = Environment.GetEnvironmentVariable("PORT") ?? "4000";
58+
var url = $"http://{hostname}:{port}";
59+
60+
app.Logger.LogInformation($"App started on {url}", url);
61+
62+
app.Run(url);
63+
64+
record StatusResult(Boolean success, string tech, string version, string timestamp, string lastmod, string commit);
65+
record TestOutput(Boolean success, string html);
66+

Properties/launchSettings.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:62740",
8+
"sslPort": 44349
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5047",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7090;http://localhost:5047",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
File renamed without changes.

RegexPlanet-DotNet.sln

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
4-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexPlanet-DotNet", "RegexPlanet-DotNet\RegexPlanet-DotNet.csproj", "{FDFF3E98-15B8-4FAC-988C-5A61C86666CE}"
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "regexplanet-dotnet", "regexplanet-dotnet.csproj", "{686D22DC-C3D7-4D47-8BDE-A609F580D0D9}"
57
EndProject
68
Global
79
GlobalSection(SolutionConfigurationPlatforms) = preSolution
810
Debug|Any CPU = Debug|Any CPU
911
Release|Any CPU = Release|Any CPU
1012
EndGlobalSection
1113
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12-
{FDFF3E98-15B8-4FAC-988C-5A61C86666CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13-
{FDFF3E98-15B8-4FAC-988C-5A61C86666CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
14-
{FDFF3E98-15B8-4FAC-988C-5A61C86666CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
15-
{FDFF3E98-15B8-4FAC-988C-5A61C86666CE}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{686D22DC-C3D7-4D47-8BDE-A609F580D0D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{686D22DC-C3D7-4D47-8BDE-A609F580D0D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{686D22DC-C3D7-4D47-8BDE-A609F580D0D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{686D22DC-C3D7-4D47-8BDE-A609F580D0D9}.Release|Any CPU.Build.0 = Release|Any CPU
1618
EndGlobalSection
1719
GlobalSection(SolutionProperties) = preSolution
1820
HideSolutionNode = FALSE
1921
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {DA9609D1-C9D1-4278-88C3-775AFA871B42}
24+
EndGlobalSection
2025
EndGlobal

RegexPlanet-DotNet/Properties/AssemblyInfo.cs

-35
This file was deleted.

0 commit comments

Comments
 (0)