Skip to content

Commit 2c3b31c

Browse files
committed
add Docker support; run the two apps using Docker Compose
1 parent cdd1ef8 commit 2c3b31c

File tree

13 files changed

+173
-6
lines changed

13 files changed

+173
-6
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ ClientBin/
217217
*.dbmdl
218218
*.dbproj.schemaview
219219
*.jfm
220-
*.pfx
221220
*.publishsettings
222221
orleans.codegen.cs
223222

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
# JWT Auth Demo
22

33
This repository demos an ASP.NET Core web API application using JWT auth, and an integration testing project for a set of actions including login, logout, refresh token, impersonation, authentication, and authorization.
4+
5+
## Solution Structure
6+
7+
This repository includes two applications: an Angular SPA in the `angular` folder, and an ASP.NET Core web API app in the `webapi` folder. The SPA makes HTTP requests to the server side (the `webapi` app) using an API BaseURL `https://localhost:5001`. The API BaseURL is set in the `environment.ts` file and the `environment.prod.ts` file, which can be modified based on your situation.
8+
9+
- `angular`
10+
The SPA is served using NGINX on Docker. The application demonstrates JWT authorization in the front-end.
11+
- `webapi`
12+
The ASP.NET Core web API app is served by Kestrel on Docker. This app has implemented HTTPS support.
13+
14+
## Usage
15+
16+
The demo is configured to run by Docker Compose. The services are listed in the `docker-compose.yml` file. You can launch the demo by the following command.
17+
18+
```bash
19+
docker-compose up --build --remove-orphans
20+
```
21+
22+
You can also move the folders around to consolidate the solution to be one ASP.NET Core web app using SPA service.
23+
24+
## Screenshots
25+
26+
- **Front-end** ([http://localhost:8080](http://localhost:8080))
27+
28+
![angular app](./localhost_8080.png)
29+
30+
- **Back-end** ([https://localhost:5001](https://localhost:5001))
31+
32+
![web api](./localhost_5001.png)

angular/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:alpine as builder
2+
3+
WORKDIR /app
4+
COPY package.json package-lock.json ./
5+
ENV CI=1
6+
RUN npm ci
7+
8+
COPY . .
9+
RUN npm run build -- --prod --output-path=/dist
10+
11+
# Deploy our Angular app to NGINX
12+
FROM nginx:alpine
13+
14+
## Replace the default nginx index page with our Angular app
15+
RUN rm -rf /usr/share/nginx/html/*
16+
COPY --from=builder /dist /usr/share/nginx/html
17+
18+
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
19+
COPY ./nginx/gzip.conf /etc/nginx/gzip.conf
20+
21+
ENTRYPOINT ["nginx", "-g", "daemon off;"]

angular/nginx/gzip.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
gzip on;
2+
gzip_vary on;
3+
gzip_http_version 1.0;
4+
gzip_comp_level 5;
5+
gzip_types
6+
application/atom+xml
7+
application/javascript
8+
application/json
9+
application/rss+xml
10+
application/vnd.ms-fontobject
11+
application/x-font-ttf
12+
application/x-web-app-manifest+json
13+
application/xhtml+xml
14+
application/xml
15+
font/opentype
16+
image/svg+xml
17+
image/x-icon
18+
text/css
19+
text/plain
20+
text/x-component;
21+
gzip_proxied no-cache no-store private expired auth;
22+
gzip_min_length 256;
23+
gunzip on;

angular/nginx/nginx.conf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
user nginx;
2+
3+
worker_processes auto;
4+
5+
events { worker_connections 1024; }
6+
7+
http {
8+
include /etc/nginx/mime.types;
9+
include /etc/nginx/gzip.conf;
10+
limit_req_zone $binary_remote_addr zone=one:10m rate=5r/s;
11+
server_tokens off;
12+
13+
sendfile on;
14+
keepalive_timeout 29; # Adjust to the lowest possible value that makes sense for your use case.
15+
client_body_timeout 10; client_header_timeout 10; send_timeout 10;
16+
17+
server {
18+
listen 80;
19+
server_name $hostname;
20+
root /usr/share/nginx/html;
21+
22+
add_header X-Frame-Options DENY;
23+
add_header X-Content-Type-Options nosniff;
24+
add_header X-Frame-Options "SAMEORIGIN";
25+
26+
location / {
27+
try_files $uri $uri/ /index.html;
28+
}
29+
}
30+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<p>management works!</p>
1+
<div class="container p-3">
2+
<p>TODO: impersonation related components</p>
3+
<p>management works!</p>
4+
</div>

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.8'
2+
3+
services:
4+
angular:
5+
build: ./angular
6+
ports:
7+
- '8080:80'
8+
depends_on:
9+
- api
10+
restart: always
11+
12+
api:
13+
build: ./webapi
14+
ports:
15+
- '5001'
16+
environment:
17+
- ASPNETCORE_ENVIRONMENT=Development
18+
- ASPNETCORE_URLS=https://+:5001;http://+:5000
19+
- ASPNETCORE_HTTPS_PORT=5001
20+
- ASPNETCORE_Kestrel__Certificates__Default__Password=mypassword123
21+
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
22+
volumes:
23+
- ./webapi/https/aspnetapp.pfx:/https/aspnetapp.pfx:ro
24+
restart: always

localhost_5001.png

195 KB
Loading

localhost_8080.png

166 KB
Loading

webapi/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build
1+
ARG VERSION=3.1-alpine
2+
3+
FROM mcr.microsoft.com/dotnet/core/sdk:$VERSION AS build
24
WORKDIR /app
35

46
COPY ./*.sln .
@@ -15,8 +17,7 @@ WORKDIR /app/JwtAuthDemo
1517
RUN dotnet publish -c Release -o /out --no-restore
1618

1719

18-
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime
20+
FROM mcr.microsoft.com/dotnet/core/aspnet:$VERSION AS runtime
1921
WORKDIR /app
2022
COPY --from=build /out ./
21-
ENV ASPNETCORE_URLS http://*:5000
2223
ENTRYPOINT ["dotnet", "JwtAuthDemo.dll"]

0 commit comments

Comments
 (0)