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
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -248,3 +248,5 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
.env
|
.env
|
||||||
Logs/*
|
Logs/*
|
||||||
|
docker-compose.yml
|
||||||
|
*exclude*
|
||||||
63
API/Readme.md
Normal file
63
API/Readme.md
Normal 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
|
||||||
@ -1,11 +1,20 @@
|
|||||||
#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.
|
#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 AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
# EXPOSE 443 # SSL termination expected
|
EXPOSE 443
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
# 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=
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["YABA.API/YABA.API.csproj", "YABA.API/"]
|
COPY ["YABA.API/YABA.API.csproj", "YABA.API/"]
|
||||||
COPY ["YABA.Common/YABA.Common.csproj", "YABA.Common/"]
|
COPY ["YABA.Common/YABA.Common.csproj", "YABA.Common/"]
|
||||||
|
|||||||
@ -16,6 +16,8 @@ using Serilog;
|
|||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
|
|
||||||
var configuration = builder.Configuration;
|
var configuration = builder.Configuration;
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|||||||
24
Readme.md
24
Readme.md
@ -1,23 +1,7 @@
|
|||||||
# YABA: Yet Another Bookmark App
|
# YABA: Yet Another Bookmark App
|
||||||
|
|
||||||
## Developer Guides
|
## Developer Guide
|
||||||
|
|
||||||
### Running Migrations
|
The application is divided into two parts. Refer to the Readme on the root of the following sections for more information:
|
||||||
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:
|
- API: [Readme](API/Readme.md)
|
||||||
|
- Web: [Readme](Web/Readme.md)
|
||||||
```
|
|
||||||
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.
|
|
||||||
@ -1,13 +1,28 @@
|
|||||||
# https://www.knowledgehut.com/blog/web-development/how-to-dockerize-react-app
|
|
||||||
FROM node:17-alpine as builder
|
FROM node:17-alpine as builder
|
||||||
WORKDIR /app
|
|
||||||
COPY package-lock.json .
|
|
||||||
RUN npm install
|
|
||||||
COPY . .
|
|
||||||
RUN npm build
|
|
||||||
|
|
||||||
FROM nginx:latest
|
# Set the environment variables
|
||||||
|
ENV API_BASE_URL=
|
||||||
|
ENV AUTH0_DOMAIN=
|
||||||
|
ENV AUTH0_CLIENT_ID=
|
||||||
|
ENV AUTH0_CALLBACK_URL=
|
||||||
|
ENV AUTH0_AUDIENCE=
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json .
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
RUN echo 'DEBUG': $API_BASE_URL
|
||||||
|
RUN echo 'DEBUG': $AUTH0_DOMAIN
|
||||||
|
RUN echo 'DEBUG': $AUTH0_CLIENT_ID
|
||||||
|
RUN echo 'DEBUG': $AUTH0_CALLBACK_URL
|
||||||
|
RUN echo 'DEBUG': $AUTH0_AUDIENCE
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM nginx:mainline-alpine
|
||||||
WORKDIR /usr/share/nginx/html
|
WORKDIR /usr/share/nginx/html
|
||||||
RUN rm -rf ./*
|
RUN rm -rf ./*
|
||||||
COPY --from=builder /app/build .
|
COPY --from=builder /app/build .
|
||||||
|
EXPOSE 80
|
||||||
ENTRYPOINT ["nginx", "-g", "daemon off;"]
|
ENTRYPOINT ["nginx", "-g", "daemon off;"]
|
||||||
@ -68,3 +68,17 @@ This section has moved here: [https://facebook.github.io/create-react-app/docs/d
|
|||||||
### `npm run build` fails to minify
|
### `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)
|
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
|
||||||
|
|||||||
22151
Web/package-lock.json
generated
22151
Web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
|||||||
"name": "yaba-web",
|
"name": "yaba-web",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"homepage": ".",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@auth0/auth0-react": "^2.0.0",
|
"@auth0/auth0-react": "^2.0.0",
|
||||||
"@testing-library/jest-dom": "^5.16.5",
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
|
|||||||
9
nginx.conf
Normal file
9
nginx.conf
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user