From 0146a8aeb0ddd691e0f72c22db38e78a57456cef Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 4 Dec 2023 14:25:34 +0100 Subject: [PATCH] Update AllInOne dockerfile --- build-and-run-all-in-one-web-docker.sh | 2 +- docker/Dockerfile | 20 ++++--------------- .../Elsa.AllInOne.Web.csproj | 4 ++++ .../Properties/launchSettings.json | 4 ++-- .../Elsa.AllInOne.Web/appsettings.json | 11 ++-------- .../Controllers/HomeController.cs | 20 +++++++++++-------- .../Program.cs | 4 +++- 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/build-and-run-all-in-one-web-docker.sh b/build-and-run-all-in-one-web-docker.sh index 5dde98c34..1674a6463 100644 --- a/build-and-run-all-in-one-web-docker.sh +++ b/build-and-run-all-in-one-web-docker.sh @@ -1,2 +1,2 @@ docker build -t elsa-3:local -f ./docker/Dockerfile . -docker run -t -i -e ASPNETCORE_ENVIRONMENT='Development' -p 13000:80 elsa-3:local \ No newline at end of file +docker run -t -i -e ASPNETCORE_ENVIRONMENT='Development' -e HTTP_PORTS=8080 -p 13000:8080 elsa-3:local \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index b6ca2fec9..4b84a3eb8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,33 +1,21 @@ FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build WORKDIR /source -# install node -ENV NODE_VERSION=19.0.0 -RUN apt install -y curl -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash -ENV NVM_DIR=/root/.nvm -RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} -RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} -RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} -ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" -RUN node --version -RUN npm --version - -# restore packages +# copy sources. COPY src/. ./src COPY ./NuGet.Config ./ COPY *.props ./ -# Restore packages. +# restore packages. RUN dotnet restore "./src/bundles/ElsaStudioWebAssembly/ElsaStudioWebAssembly.csproj" RUN dotnet restore "./src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj" -# build and publish (UseAppHost=false creates platform independent binaries) +# build and publish (UseAppHost=false creates platform independent binaries). WORKDIR /source/src/bundles/Elsa.AllInOne.Web RUN dotnet build "Elsa.AllInOne.Web.csproj" -c Release -o /app/build RUN dotnet publish "Elsa.AllInOne.Web.csproj" -c Release -o /app/publish /p:UseAppHost=false --no-restore -f net8.0 -# move binaries into smaller base image +# move binaries into smaller base image. FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim AS base WORKDIR /app COPY --from=build /app/publish ./ diff --git a/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj b/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj index 7c24b3a8f..eb090ce09 100644 --- a/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj +++ b/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj @@ -36,4 +36,8 @@ + + + + \ No newline at end of file diff --git a/src/bundles/Elsa.AllInOne.Web/Properties/launchSettings.json b/src/bundles/Elsa.AllInOne.Web/Properties/launchSettings.json index e7090179f..323070fb9 100644 --- a/src/bundles/Elsa.AllInOne.Web/Properties/launchSettings.json +++ b/src/bundles/Elsa.AllInOne.Web/Properties/launchSettings.json @@ -8,11 +8,11 @@ } }, "profiles": { - "Elsa.Samles.Web4": { + "Elsa.AllInOne.Web": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7193;http://localhost:5193", + "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/bundles/Elsa.AllInOne.Web/appsettings.json b/src/bundles/Elsa.AllInOne.Web/appsettings.json index 0b79cfb5d..a8caf8fe0 100644 --- a/src/bundles/Elsa.AllInOne.Web/appsettings.json +++ b/src/bundles/Elsa.AllInOne.Web/appsettings.json @@ -20,7 +20,7 @@ }, "Identity": { "Tokens": { - "SigningKey": "secret-signing-key", + "SigningKey": "c7dc81876a782d502084763fa322429fca015941eac90ce8ca7ad95fc8752035", "AccessTokenLifetime": "1:00:00:00", "RefreshTokenLifetime": "1:00:10:00" }, @@ -69,14 +69,7 @@ "BasePath": "/api/workflows" }, "Webhooks": { - "Endpoints": [ - { - "EventTypes": [ - "RunTask" - ], - "Url": "https://localhost:5002/api/webhooks/run-task" - } - ] + "Endpoints": [] }, "CorsPolicy": { "Origins": ["*"], diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.Web/Controllers/HomeController.cs b/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.Web/Controllers/HomeController.cs index 7f78d1660..4b680d2ae 100644 --- a/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.Web/Controllers/HomeController.cs +++ b/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.Web/Controllers/HomeController.cs @@ -16,29 +16,33 @@ public class HomeController : Controller _dbContext = dbContext; _elsaClient = elsaClient; } - + public async Task Index(CancellationToken cancellationToken) { var tasks = await _dbContext.Tasks.Where(x => !x.IsCompleted).ToListAsync(cancellationToken: cancellationToken); var model = new IndexViewModel(tasks); return View(model); } - + public async Task CompleteTask(int taskId, CancellationToken cancellationToken) { var task = _dbContext.Tasks.FirstOrDefault(x => x.Id == taskId); - + if (task == null) return NotFound(); - - await _elsaClient.ReportTaskCompletedAsync(task.ExternalId, cancellationToken: cancellationToken); - + + var result = new + { + Magic = Random.Shared.NextDouble() + }; + await _elsaClient.ReportTaskCompletedAsync(task.ExternalId, result, cancellationToken); + task.IsCompleted = true; task.CompletedAt = DateTimeOffset.Now; - + _dbContext.Tasks.Update(task); await _dbContext.SaveChangesAsync(cancellationToken); - + return RedirectToAction("Index"); } } \ No newline at end of file diff --git a/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.WorkflowServer/Program.cs b/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.WorkflowServer/Program.cs index 486bfe175..1a5649b71 100644 --- a/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.WorkflowServer/Program.cs +++ b/src/samples/aspnet/Elsa.Samples.AspNet.Onboarding.WorkflowServer/Program.cs @@ -24,7 +24,7 @@ builder.Services.AddElsa(elsa => { identity.TokenOptions = options => { - options.SigningKey = "secret-token-signing-key"; + options.SigningKey = "c7dc81876a782d502084763fa322429fca015941eac90ce8ca7ad95fc8752035"; options.AccessTokenLifetime = TimeSpan.FromDays(1); }; @@ -37,6 +37,8 @@ builder.Services.AddElsa(elsa => // Use default authentication (JWT + ApiKey). elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey()); + elsa.UseJavaScript(); + // Enable SignalR for sending events to Elsa Studio for real-time updates. elsa.UseRealTimeWorkflows();