From a90cdc08b80aa2fccc898cee7b3c79445cc647d9 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 30 May 2026 15:41:59 +0100 Subject: [PATCH] docker composes --- .env.sample | 14 ++--- .gitignore | 1 + .vscode/settings.json | 1 + Dockerfile | 54 +++++++++---------- Makefile | 7 +++ docker-compose.yaml | 24 +++++++++ .../PostIt.Android/PostIt.Android.csproj | 2 +- src/PostIt/PostIt/Views/MainView.axaml | 38 ++++++------- src/Yavsc.Abstract/Constants.cs | 1 - 9 files changed, 88 insertions(+), 54 deletions(-) create mode 100644 docker-compose.yaml diff --git a/.env.sample b/.env.sample index 8ba5ba93..034e914e 100644 --- a/.env.sample +++ b/.env.sample @@ -1,7 +1,9 @@ APP_NAME=Yavsc -YAVSC_CONNECTION_HOST=localhost -YAVSC_CONNECTION_PORT=5432 -YAVSC_CONNECTION_DATABASE=Yavsc -YAVSC_CONNECTION_USERNAME=Yavsc -YAVSC_CONNECTION_PASSWORD=lame-YAVSC_CONNECTION_PASSWORD -DESTDIR=/srv/www/Yavsc +POSTGRES_HOST=localhost +POSTGRES_PORT=5432 +POSTGRES_DB=yavsc +POSTGRES_USER=yavsc +POSTGRES_PASSWORD=lame-YAVSC_CONNECTION_PASSWORD +DESTDIR=/srv/www/yavsc + +ASPNETCORE_ConnectionStrings__YavscConnection=Server=$POSTGRES_HOST;Port=$POSTGRES_PORT;Database=$POSTGRES_DB;Username=$POSTGRES_USER;Password=$POSTGRES_PASSWORD; diff --git a/.gitignore b/.gitignore index 17320654..8e16d9bd 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,5 @@ binaries/ build/ src/*/Blog-Dev/ *.mp4 +src/Yavsc.Org/data/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 9a0ff7f3..420ea3b7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "appsettings", "asciidoctor", "Cratie", + "DESTDIR", "Newtonsoft", "Npgsql", "Yavsc" diff --git a/Dockerfile b/Dockerfile index 8e96d6df..74fc0f9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,30 @@ -# syntax=docker/dockerfile:1 -# Learn about building .NET container images: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base -WORKDIR /app -EXPOSE 80 -EXPOSE 443 - -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +# Build stage +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src -COPY ["/src", "/src"] -COPY "Directory.Packages.props" "Directory.Packages.props" +COPY . . +RUN dotnet publish src/Yavsc/Yavsc.csproj -c Release -o /app/publish -RUN dotnet nuget add source https://isn.pschneider.fr/v3/index.json --allow-insecure-connections - -# Just to see if two lines above work -RUN dotnet nuget list source - -RUN dotnet restore "/src/Yavsc/Yavsc.csproj" - -# Copy source code and publish app - -WORKDIR "/src/Yavsc" -RUN dotnet build "Yavsc.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Yavsc.csproj" -c Release -o /app/publish /p:UseAppHost=false - -FROM base AS final +# Runtime stage +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app -COPY --from=publish /app/publish . + +# Variables d'environnement avec valeurs par défaut +ARG POSTGRES_HOST=localhost +ARG POSTGRES_PORT=5432 +ARG POSTGRES_DB=yavsc +ARG POSTGRES_USER=yavsc +ARG POSTGRES_PASSWORD + +ENV POSTGRES_HOST=${POSTGRES_HOST} +ENV POSTGRES_PORT=${POSTGRES_PORT} +ENV POSTGRES_DB=${POSTGRES_DB} +ENV POSTGRES_USER=${POSTGRES_USER} +ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + +# Chaîne de connexion construite depuis les variables +ENV ConnectionStrings__DefaultConnection=\ +"Host=${POSTGRES_HOST};Port=${POSTGRES_PORT};Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}" + +COPY --from=build /app/publish . +EXPOSE 5000 ENTRYPOINT ["dotnet", "Yavsc.dll"] diff --git a/Makefile b/Makefile index ee44956b..1ef9fe7c 100644 --- a/Makefile +++ b/Makefile @@ -40,4 +40,11 @@ install: $(DESTDIR) docker-image: docker build . +docker-build: + docker compose up --build + +docker-run: + docker run -d -p 5000:5000 --name yavsc yavsc + + .PHONY: diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..c1127397 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +services: + db: + image: postgres:16 + env_file: .env + volumes: + - pgdata:/var/lib/postgresql/data + + web: + build: + context: . + args: + POSTGRES_HOST: db + POSTGRES_PORT: ${POSTGRES_PORT} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + env_file: .env + ports: + - "5000:5000" + depends_on: + - db + +volumes: + pgdata: \ No newline at end of file diff --git a/src/PostIt/PostIt.Android/PostIt.Android.csproj b/src/PostIt/PostIt.Android/PostIt.Android.csproj index b50719ed..a50da484 100644 --- a/src/PostIt/PostIt.Android/PostIt.Android.csproj +++ b/src/PostIt/PostIt.Android/PostIt.Android.csproj @@ -2,7 +2,7 @@ Exe net10.0-android - 23 + 23.0.0 enable com.CompanyName.PostIt 1 diff --git a/src/PostIt/PostIt/Views/MainView.axaml b/src/PostIt/PostIt/Views/MainView.axaml index 35333b01..19bf7eb4 100644 --- a/src/PostIt/PostIt/Views/MainView.axaml +++ b/src/PostIt/PostIt/Views/MainView.axaml @@ -1,26 +1,28 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vm="using:PostIt.ViewModels" + xmlns:views="using:PostIt.Views" + xmlns:AvaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="PostIt.Views.MainView" + x:DataType="vm:MainViewModel"> + to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --> + - - + + + diff --git a/src/Yavsc.Abstract/Constants.cs b/src/Yavsc.Abstract/Constants.cs index 88a3a431..e1a8e717 100644 --- a/src/Yavsc.Abstract/Constants.cs +++ b/src/Yavsc.Abstract/Constants.cs @@ -39,7 +39,6 @@ namespace Yavsc public const string FrontOfficeGroupName = "FrontOffice"; public const string DefaultAvatar = "/images/Users/icon_user.png"; public const string AnonAvatar = "/images/Users/icon_anon_user.png"; - public const string YavscConnectionStringEnvName = "YAVSC_CONNECTION_STRING"; public const string YavscConnectionStringName = "YavscConnection"; // at the end, let 4*4 bytes in peace