12 Commits

Author SHA1 Message Date
9d59359074 Attempting to fix error authentication to container
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline failed
2024-03-21 23:38:41 -05:00
c23ffc3fd8 Changed CI pipeline to accomodate non master tags
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2024-03-21 23:33:10 -05:00
fe57aca2f7 Changed step name to attempt fix CI pipeline 2024-03-21 23:27:45 -05:00
e61e8fb898 Fixing CI error for Docker image deployment 2024-03-21 23:25:48 -05:00
afe04ec68b Added deploy step for API Dockerfile 2024-03-21 23:19:34 -05:00
445b33f852 Fixed wrong path for dotnet test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-03-21 23:15:55 -05:00
433a8d78a4 Temporarily removed deployment of Docker image
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-03-21 23:13:50 -05:00
fd2246391c Add sample pipeline for building API project 2024-03-21 23:12:23 -05:00
95ddb3236c Fixed issue with Web Docker image not getting proper environment variable substitution
As ReactJS does not seem to support reading environment variables from Docker runtime variables, we'll pull it instead from buildtime.
Also added copying of nginx config file in the Dockerfile
Modified API Dockerfile to accept WebUri for CORS, also removed duplicate setting of CORS in Program.cs
2024-03-21 21:01:58 -05:00
f1144d2cb9 Committing work for creating docker images of Web and API apps
Outstanding work include:
- Adding CI/CD workflow compatible with Woodpecker CI
- Figure out how to load runtime environment variables onto the API docker build process
2024-03-19 20:56:56 -05:00
0ca2a0e38c Added Dockerfile for API and Web apps 2023-03-29 22:56:42 -05:00
9b590bb4fa Moved projects to their own separate subdirectories 2023-03-27 21:48:25 -05:00
143 changed files with 30895 additions and 18248 deletions

4
.gitignore vendored
View File

@ -247,4 +247,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env
Logs/*
Logs/*
docker-compose.yml
*exclude*

21
.woodpecker.yaml Normal file
View File

@ -0,0 +1,21 @@
steps:
- name: (YABA.API) Build and run tests
image: mcr.microsoft.com/dotnet/sdk:6.0
commands:
- dotnet build ./API
- dotnet test ./API
- name: (YABA.API) Deploy Docker Image (Non-Prod Branch)
when:
- event: tag
branch:
exclude: [master]
secrets: [gitea_yaba_registry_username, gitea_yaba_registry_password]
image: woodpeckerci/plugin-docker-buildx
settings:
repo: yaba/api
context: ./API/YABA.API
dockerfile: Dockerfile
tags: ${CI_COMMIT_TAG}
username: ${gitea_yaba_registry_username}
password: ${gitea_yaba_registry_password}
registry: https://gitea.iwanaga.moe/cjtibule/YABA/packages

63
API/Readme.md Normal file
View File

@ -0,0 +1,63 @@
# YABA: Yet Another Bookmark App
## YABA.API - Developer Guide
### Running Migrations
When running migrations, .NET seems to be ignoring dependency injection settings. In order to get around this, be sure to add the connection string to the command like. For example, when adding the migration:
```
dotnet ef migrations add InitialMigration -p YABA.Data -s YABA.API --context YABABaseContext -- {CONNECTION_STRING_HERE}
```
When removing last migration:
```
dotnet ef migrations remove InitialMigration -p YABA.Data -s YABA.API --context YABABaseContext -- {CONNECTION_STRING_HERE}
```
When applying migrations:
```
dotnet ef database update -p YABA.Data -s YABA.API -c YABABaseContext -- { CONNECTION_STRING_HERE }
```
As per the documentation [on MSDN](https://learn.microsoft.com/en-ca/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#from-application-services):
> The -- token directs dotnet ef to treat everything that follows as an argument and not try to parse them as options. Any extra arguments not used by dotnet ef are forwarded to the app.
### Managing secrets
Best practice dictates that sensitive values should never be committed to source control. To manage secrets locally, this project utilize the [secrets manager](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-7.0&tabs=windows).
To initialize a secrets manager:
```
dotnet user-secrets init --project YABA.API
```
To set (or override) the value of a secret using a provided key:
```
dotnet user-secrets set "Key" "Value" --project YABA.API
```
```
dotnet user-secrets set "Object:Property" "Value" --project YABA.API
```
To list all secets:
```
dotnet user-secrets list --project YABA.API
```
### Docker
To build a dockerized version of the API project:
```
docker build { API_PROJECT_ROOT_SOURCE } -f { API_PROJECT_DOCKERFILE_PATH } -t { imagename:tag }
```
In order to run a container using the image built above, keep the following things in mind:
- It might be necessary to map container port 80 to another
- In the absence of a linked user secrets, secrets will have to be passed in to the container as environment variables, prefixed with `ASPNETCORE_`
```
docker run -d -p { HOST_PC_PORT_HERE }:80 --env ASPNETCORE_Object__Property=Value --name { CONTAINER_NAME } {imagename:tag}
```
Environment variables that are explicitly listed in `YABA.API\Dockerfile` will have to be properly set for proper operation of the application

36
API/YABA.API/Dockerfile Normal file
View File

@ -0,0 +1,36 @@
#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.
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# Set environment variables
ENV ASPNETCORE_Environment=Development
ENV ASPNETCORE_Authentication__Auth0__ClientId=
ENV ASPNETCORE_Authentication__Auth0__ClientSecret=
ENV ASPNETCORE_Authentication__Auth0__Domain=
ENV ASPNETCORE_Authentication__Auth0__Identifier=
ENV ASPNETCORE_ConnectionStrings__YABAReadOnlyDbConnectionString=
ENV ASPNETCORE_ConnectionStrings__YABAReadWriteDbConnectionString=
ENV ASPNETCORE_WebClient__Url=
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src
COPY ["YABA.API/YABA.API.csproj", "YABA.API/"]
COPY ["YABA.Common/YABA.Common.csproj", "YABA.Common/"]
COPY ["YABA.Data/YABA.Data.csproj", "YABA.Data/"]
COPY ["YABA.Models/YABA.Models.csproj", "YABA.Models/"]
COPY ["YABA.Service/YABA.Service.csproj", "YABA.Service/"]
RUN dotnet restore "YABA.API/YABA.API.csproj"
COPY . .
WORKDIR "/src/YABA.API"
RUN dotnet build "YABA.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "YABA.API.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "YABA.API.dll"]

View File

@ -16,6 +16,8 @@ using Serilog;
using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
var configuration = builder.Configuration;
// Add services to the container.
@ -118,13 +120,8 @@ app.MapControllers();
app.UseMiddleware<AddCustomClaimsMiddleware>();
app.UseMiddleware<AddCustomLoggingPropertiesMiddleware>();
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
var webClientUrl = configuration.GetSection("WebClient").GetValue<string>("Url");
app.UseCors(x => x.AllowAnyHeader().AllowAnyMethod().WithOrigins(webClientUrl));
app.UseCors(x => x.WithOrigins(webClientUrl).AllowAnyMethod().AllowAnyHeader());
app.MapHealthChecks("/Pulse");
app.Run();

View File

@ -41,6 +41,6 @@
"Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId"]
},
"WebClient": {
"Url": "https://localhost:3000"
"Url": "http://localhost:3000"
}
}

View File

@ -1,23 +1,7 @@
# YABA: Yet Another Bookmark App
## Developer Guides
## Developer Guide
### Running Migrations
When running migrations, .NET seems to be ignoring dependency injection settings. In order to get around this, be sure to add the connection string to the command like. For example, when adding the migration:
```
dotnet ef migrations add InitialMigration -p YABA.Data -s YABA.API --context YABABaseContext -- {CONNECTION_STRING_HERE}
```
When removing last migration:
```
dotnet ef migrations remove InitialMigration -p YABA.Data -s YABA.API --context YABABaseContext -- {CONNECTION_STRING_HERE}
```
When applying migrations:
```
dotnet ef database update -p YABA.Data -s YABA.API -c YABABaseContext -- { CONNECTION_STRING_HERE }
```
As per the documentation [on MSDN](https://learn.microsoft.com/en-ca/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#from-application-services):
> The -- token directs dotnet ef to treat everything that follows as an argument and not try to parse them as options. Any extra arguments not used by dotnet ef are forwarded to the app.
The application is divided into two parts. Refer to the Readme on the root of the following sections for more information:
- API: [Readme](API/Readme.md)
- Web: [Readme](Web/Readme.md)

1
Web/.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules/

22
Web/Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM node:17-alpine as builder
# Set the environment variables
ARG REACT_APP_API_BASE_URL
ARG REACT_APP_AUTH0_DOMAIN
ARG REACT_APP_AUTH0_CLIENT_ID
ARG REACT_APP_AUTH0_CALLBACK_URL
ARG REACT_APP_AUTH0_AUDIENCE
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:mainline-alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=builder /app/build .
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]

View File

@ -68,3 +68,17 @@ This section has moved here: [https://facebook.github.io/create-react-app/docs/d
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
---
## Docker
To build a dockerized version of the Web project:
```
docker build { WEB_PROJECT_ROOT_SOURCE } -f { WEB_PROJECT_DOCKERFILE_PATH } -t { imagename:tag }
```
In order to run a container using the image built above, keep the following things in mind:
- It might be necessary to map container port 80 to another
- Environment variables actively used by the web app can be overriden when starting uip a container. They are prefixed with: `REACT_APP`
- Environment variables that are explicitly listed in `Web\Dockerfile` will have to be properly set for proper operation of the application

9
Web/nginx.conf Normal file
View File

@ -0,0 +1,9 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}

30717
Web/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
"name": "yaba-web",
"version": "0.1.0",
"private": true,
"homepage": ".",
"dependencies": {
"@auth0/auth0-react": "^2.0.0",
"@testing-library/jest-dom": "^5.16.5",

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Some files were not shown because too many files have changed in this diff Show More