Skip to content

Commit 7ab0ab1

Browse files
authored
Merge pull request #8 from VillSource/main
Deploy container to ghcr with GitHub action
2 parents d91ddac + f6b8f98 commit 7ab0ab1

File tree

10 files changed

+168
-28
lines changed

10 files changed

+168
-28
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
**/secrets.dev.yaml
2323
**/values.dev.yaml
2424
LICENSE
25-
README.md
25+
README.md
26+
Gateway\ocelot.json

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish Image to GHCR
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
publish-image:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Login to GitHub Container Registry
16+
uses: docker/login-action@v1
17+
with:
18+
registry: ghcr.io
19+
username: ${{ github.actor }}
20+
password: ${{ secrets.GITHUB_TOKEN }}
21+
- name: Build the Docker image
22+
run: |
23+
docker build -f ./Gateway/Dockerfile . --tag ghcr.io/untitlecms/gateway:v0
24+
docker push ghcr.io/untitlecms/gateway:v0

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,6 @@ MigrationBackup/
360360
.ionide/
361361

362362
# Fody - auto-generated XML schema
363-
FodyWeavers.xsd
363+
FodyWeavers.xsd
364+
365+
ocelot.json

Gateway/.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"dotnet-ef": {
6+
"version": "8.0.0",
7+
"commands": [
8+
"dotnet-ef"
9+
]
10+
}
11+
}
12+
}

Gateway/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#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.
22

33
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
4+
LABEL org.opencontainers.image.source = "https://github.com/UntitleCMS/Gateway"
45
WORKDIR /app
6+
RUN mkdir /app/Ocelot
57
EXPOSE 80
68
EXPOSE 443
79

@@ -19,4 +21,4 @@ RUN dotnet publish "Gateway.csproj" -c Release -o /app/publish /p:UseAppHost=fal
1921
FROM base AS final
2022
WORKDIR /app
2123
COPY --from=publish /app/publish .
22-
ENTRYPOINT ["dotnet", "Gateway.dll"]
24+
ENTRYPOINT ["dotnet", "Gateway.dll"]

Gateway/Ocelot/ocelot.authv2.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"Routes": [
3+
{
4+
"DownstreamPathTemplate": "/api/auth/v2",
5+
"DownstreamScheme": "http",
6+
"DownstreamHostAndPorts": [
7+
{
8+
"Host": "local.villsource.tk",
9+
"Port": 8081
10+
}
11+
],
12+
"UpstreamPathTemplate": "/api/auth/v2",
13+
"UpstreamHeaderTransform": {
14+
"X-Forwarded-For": "{RemoteIpAddress}",
15+
"X-Forwarded-Host": "localhost:7269",
16+
"X-Forwarded-Proto": "https"
17+
}
18+
},
19+
20+
{
21+
"DownstreamPathTemplate": "/api/auth/v2/.well-known/openid-configuration",
22+
"DownstreamScheme": "http",
23+
"DownstreamHostAndPorts": [
24+
{
25+
"Host": "local.villsource.tk",
26+
"Port": 8081
27+
}
28+
],
29+
"UpstreamPathTemplate": "/api/auth/v2/.well-known/openid-configuration",
30+
"UpstreamHeaderTransform": {
31+
"X-Forwarded-For": "{RemoteIpAddress}",
32+
"X-Forwarded-Host": "localhost:7269",
33+
"X-Forwarded-Proto": "https"
34+
},
35+
"DownstreamHeaderTransform": {
36+
"Uncle": "Bob"
37+
}
38+
},
39+
40+
41+
42+
{
43+
"DownstreamPathTemplate": "/api/auth/v2{url}",
44+
"DownstreamScheme": "http",
45+
"DownstreamHostAndPorts": [
46+
{
47+
"Host": "local.villsource.tk",
48+
"Port": 8081
49+
}
50+
],
51+
"UpstreamPathTemplate": "/api/auth/v2{url}",
52+
"UpstreamHeaderTransform": {
53+
"X-Forwarded-For": "{RemoteIpAddress}",
54+
"X-Forwarded-Host": "localhost:7269",
55+
"X-Forwarded-Proto": "https"
56+
}
57+
},
58+
59+
{
60+
"DownstreamPathTemplate": "/oauth/cb/{url}",
61+
"DownstreamScheme": "http",
62+
"DownstreamHostAndPorts": [
63+
{
64+
"Host": "local.villsource.tk",
65+
"Port": 8081
66+
}
67+
],
68+
"UpstreamPathTemplate": "/oauth/cb/{url}",
69+
"UpstreamHeaderTransform": {
70+
"X-Forwarded-For": "{RemoteIpAddress}",
71+
"X-Forwarded-Host": "localhost:7269",
72+
"X-Forwarded-Proto": "https"
73+
}
74+
}
75+
76+
]
77+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Routes": [
3+
// Get Articles with authorize
4+
{
5+
"DownstreamScheme": "https",
6+
"DownstreamHostAndPorts": [
7+
{
8+
"Host": "google.com",
9+
"Port": 443
10+
}
11+
],
12+
"DownstreamPathTemplate": "/",
13+
"UpstreamPathTemplate": "/qwerty",
14+
"UpstreamHttpMethod": [ "GET" ],
15+
"AuthenticationOptions": {
16+
"AuthenticationProviderKey": "OpenIddict.Validation.AspNetCore"
17+
}
18+
}
19+
]
20+
}

Gateway/Program.cs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,47 @@
22
using Microsoft.AspNetCore.Server.Kestrel.Core;
33
using Ocelot.DependencyInjection;
44
using Ocelot.Middleware;
5-
using Ocelot.Values;
6-
using OpenIddict.Abstractions;
7-
using OpenIddict.Validation.AspNetCore;
85
using OpenIddict.Validation.SystemNetHttp;
96

107
var builder = WebApplication.CreateBuilder(args);
118

129
builder.Logging.ClearProviders();
1310
builder.Logging.AddConsole();
1411

15-
// Add services to the container.
16-
1712
builder.Services.AddControllers();
18-
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
13+
1914
builder.Services.AddEndpointsApiExplorer();
2015
builder.Services.AddSwaggerGen();
2116

22-
//builder.Configuration.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);
23-
builder.Configuration.AddOcelot(Path.Combine(System.IO.Directory.GetCurrentDirectory(),"Ocelot"),builder.Environment);
24-
25-
17+
builder.Configuration
18+
.AddOcelot(Path.Combine(Directory.GetCurrentDirectory(),"Ocelot"),builder.Environment);
2619

2720
builder.Services.AddOpenIddict()
2821
.AddValidation(option =>
2922
{
30-
option.SetIssuer("http://authenticationservice/");
23+
option.SetIssuer(Environment.GetEnvironmentVariable("AUTH_ISSUER")
24+
?? "https://p.villsource.tk/api/auth/v2"
25+
?? throw new Exception("Authentication Issuer not found."));
3126
option.UseSystemNetHttp();
3227
option.UseAspNetCore();
3328
});
29+
3430
// Allow any certificate ***DANGER FOR PRODUCTION***
3531
builder.Services.AddHttpClient(typeof(OpenIddictValidationSystemNetHttpOptions).Assembly.GetName().Name!)
3632
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler
3733
{
3834
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
3935
});
40-
//builder.Services.AddAuthentication(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
41-
// option =>
42-
//{
43-
// option.DefaultScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
44-
// option.DefaultChallengeScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
45-
// option.DefaultAuthenticateScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
46-
//});
47-
48-
// body size
36+
37+
38+
// Set max Body size
39+
_ = int.TryParse(Environment.GetEnvironmentVariable("MAX_REQUEST_BODY_SIZE")
40+
??"50", out int maxBodySizeMegabyte);
4941
builder.Services.Configure<KestrelServerOptions>(options =>
50-
options.Limits.MaxRequestBodySize = 20 * 1_000_000
42+
options.Limits.MaxRequestBodySize = maxBodySizeMegabyte * 1_000_000
5143
);
5244
builder.Services.Configure<IISServerOptions>(options =>
53-
options.MaxRequestBodyBufferSize = 20 * 1_000_000
45+
options.MaxRequestBodyBufferSize = maxBodySizeMegabyte * 1_000_000
5446
);
5547

5648

@@ -68,13 +60,12 @@
6860
}
6961

7062

71-
//app.UseHttpsRedirection();
63+
app.UseHttpsRedirection();
7264

7365
app.UseAuthentication();
7466
app.UseAuthorization();
7567

7668
app.MapControllers();
77-
//app.UseWebSockets();
7869
app.UseOcelot().Wait();
7970

8071
app.Run();

Gateway/ocelot.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ services:
1212
depends_on:
1313
- blogservice
1414
- authenticationservice
15+
environment:
16+
AUTH_ISSUER: https://p.villsource.tk/api/auth/v2
1517

1618
frontend:
1719
image: villsource/beta-blog
@@ -45,6 +47,9 @@ services:
4547
depends_on:
4648
- blog-database
4749
- mongo1
50+
environment:
51+
DB_CONNECTION_STRING: mongodb://mongo1:50001/?replicaSet=my-mongo-set
52+
MQ_HOST: rabit-mq
4853

4954
commentservice:
5055
image: villsource/commentservice
@@ -147,6 +152,13 @@ services:
147152
networks:
148153
- backend
149154

155+
rabit-mq:
156+
hostname: rabit-mq
157+
image: rabbitmq:3-management
158+
ports:
159+
- 15672:15672
160+
- 5672:5672
161+
150162

151163
python-slave:
152164
image: python-slave

0 commit comments

Comments
 (0)