Skip to content

Commit

Permalink
feat: Added docker support.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-meier committed Sep 15, 2023
1 parent eac009b commit f1dbe55
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.user
*.userosscache
*.sln.docstates
https/*
.idea
data/*
.vscode
Expand Down
11 changes: 9 additions & 2 deletions Chrono.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Applicat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebUI", "src\WebUI\WebUI.csproj", "{9BA631F2-D082-437D-8100-99F826858941}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_docs", "_docs", "{79449CD2-6C8D-4E22-BD09-1AB18846078C}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{79449CD2-6C8D-4E22-BD09-1AB18846078C}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
LICENSE = LICENSE
Expand All @@ -28,11 +28,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "static", "static", "{11D354
static\Start.png = static\Start.png
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_config", "_config", "{C6C4884B-F513-4419-8326-6DA9F3CE3189}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{C6C4884B-F513-4419-8326-6DA9F3CE3189}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.gitkeep = .gitkeep
setup.sh = setup.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{56763119-C6D6-40E9-9D27-A16C2A2C132E}"
Expand All @@ -45,6 +46,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{C21C3EBB-6435-432F-9291-F3165DD416AA}"
ProjectSection(SolutionItems) = preProject
Dockerfile = Dockerfile
docker-compose.yml = docker-compose.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS server-base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get install -y nodejs

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get install -y nodejs
WORKDIR /source
COPY Chrono.sln .
COPY src/. ./src
COPY tests/. ./tests
RUN dotnet publish -c release -o /app/publish

FROM server-base AS server
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "Chrono.WebUI.dll"]
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,25 @@ simple tool to keep track of useful ideas that positively impact your project(s)

## Getting started

You will need an empty `sqlite3`-database in the `data`-folder of the project. For this you can execute the following
command:
Run `setup.sh` to automatically create all required files (e.g. the SQLite3 database).
You also need an OAuth provider like [auth0](https://auth0.com) and configure the `Authority`, `ClientId`
and `ClientSecret` in the `appsettings.json` file of the `WebUI` project.

```sh
sqlite3 chrono.db "VACUUM;"
```
Once this is done, you can run the application with (for example) `dotnet watch` in the `WebUI` folder.

Besides the database, you also need an OAuth provider like [auth0](https://auth0.com) and configure
the `Authority`, `ClientId` and `ClientSecret` in the `appsettings.json` file of the `WebUI` project.
**Swagger UI**: https://localhost:7151/swagger/index.html

Once that is done, you can run the application with (for example) `dotnet watch` in the `WebUI` folder.
### Docker

**Swagger UI**: https://localhost:7151/swagger/index.html
Chrono can also be hosted with Docker. You can configure the OAuth credentials in the `docker-compose.yml` or in
the `appsettings.json`-file.
You also have to provide a https certificate, if you want to serve Chrono directly via https using the Kestrel
web-server.

A dev-certificate can be created using the following command or running `setup.sh`:
`dotnet dev-certs https -ep ./https/aspnetapp.pfx -p <password>`.

To start the application, you can simply use the `docker compose up` command.

## Useful scripts

Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.4"

services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "127.0.0.1:443:443"
#- "127.0.0.1:80:80"
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=https://+:443
#- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
- ASPNETCORE_Kestrel__Certificates__Default__Password=defaultPassword
- ConnectionStrings__DefaultConnection=Data Source=../data/chrono.db
- IdentityProvider__Authority=https://<HOSTNAME>.auth0.com/
- IdentityProvider__ClientId=<CLIENT_ID>
- IdentityProvider__ClientSecret=<CLIENT_SECRET>
volumes:
- ./data:/data
- ./https:/https
16 changes: 16 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Ensures all required files are created.
mkdir -p ./data
mkdir -p ./https

if [ ! -f ./data/chrono.db ]; then
sqlite3 data/chrono.db "VACUUM;"
echo "Created chrono.db."
else
echo "chrono.db already exists."
fi

if [ ! -f ./https/aspnetapp.pfx ]; then
dotnet dev-certs https -ep ./https/aspnetapp.pfx -p defaultPassword
else
echo "Valid https certificate already exists."
fi
1 change: 1 addition & 0 deletions src/WebUI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Chrono.Application.Infrastructure.Persistence;

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
builder.WebHost.UseKestrel(option => option.AddServerHeader = false);

// Add services to the container.
Expand Down

0 comments on commit f1dbe55

Please sign in to comment.