From 01c70e5563e50487b0c7474860038842738ae1c1 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 30 Dec 2022 19:29:34 +0100 Subject: [PATCH] Update docker things --- .github/workflows/all-in-one-web.yml | 4 +-- Elsa.sln | 6 ++++ build-and-run-all-in-one-web-docker.sh | 2 ++ .../.dockerignore | 0 docker/Dockerfile | 33 +++++++++++++++++++ src/bundles/Elsa.AllInOne.Web/Dockerfile | 21 ------------ .../Elsa.AllInOne.Web.csproj | 2 +- .../Elsa.JavaScript/Elsa.JavaScript.csproj | 2 +- 8 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 build-and-run-all-in-one-web-docker.sh rename {src/bundles/Elsa.AllInOne.Web => docker}/.dockerignore (100%) create mode 100644 docker/Dockerfile delete mode 100644 src/bundles/Elsa.AllInOne.Web/Dockerfile diff --git a/.github/workflows/all-in-one-web.yml b/.github/workflows/all-in-one-web.yml index 1128950520..9040dadc61 100644 --- a/.github/workflows/all-in-one-web.yml +++ b/.github/workflows/all-in-one-web.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v3 - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 with: platforms: all @@ -49,7 +49,7 @@ jobs: with: builder: ${{ steps.buildx.outputs.name }} context: . - file: ./src/bundles/Elsa.AllInOne.Web/Dockerfile + file: ./docker/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/Elsa.sln b/Elsa.sln index 34c2e0291a..f57e56b576 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -16,6 +16,7 @@ ProjectSection(SolutionItems) = preProject icon.png = icon.png .github\workflows\packages.yml = .github\workflows\packages.yml .github\workflows\all-in-one-web.yml = .github\workflows\all-in-one-web.yml + build-and-run-all-in-one-web-docker.sh = build-and-run-all-in-one-web-docker.sh EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{0354F050-3992-4DD4-B0EE-5FBA04AC72B6}" @@ -132,6 +133,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.WorkflowDesign EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.WorkflowServerAndDesigner", "src\samples\aspnet\Elsa.Samples.WorkflowServerAndDesigner\Elsa.Samples.WorkflowServerAndDesigner.csproj", "{34FBB2D3-4E2B-4411-95F2-C6B56899826A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{986E5482-0482-448C-B9E4-EC67A9474B85}" + ProjectSection(SolutionItems) = preProject + docker\Dockerfile = docker\Dockerfile + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/build-and-run-all-in-one-web-docker.sh b/build-and-run-all-in-one-web-docker.sh new file mode 100644 index 0000000000..5dde98c349 --- /dev/null +++ b/build-and-run-all-in-one-web-docker.sh @@ -0,0 +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 diff --git a/src/bundles/Elsa.AllInOne.Web/.dockerignore b/docker/.dockerignore similarity index 100% rename from src/bundles/Elsa.AllInOne.Web/.dockerignore rename to docker/.dockerignore diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000000..e1ef9fb496 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,33 @@ +FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build +WORKDIR /source + +# install node +ENV NODE_VERSION=18.12.1 +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 src/. ./src +COPY *.props ./ +RUN dotnet restore "./src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj" + +# 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 net7.0 + +# move binaries into smaller base image +FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim AS base +WORKDIR /app +COPY --from=build /app/publish ./ + +EXPOSE 80/tcp +EXPOSE 443/tcp +ENTRYPOINT ["dotnet", "Elsa.AllInOne.Web.dll"] diff --git a/src/bundles/Elsa.AllInOne.Web/Dockerfile b/src/bundles/Elsa.AllInOne.Web/Dockerfile deleted file mode 100644 index 8c3587cce5..0000000000 --- a/src/bundles/Elsa.AllInOne.Web/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base -WORKDIR /app -EXPOSE 80 -EXPOSE 443 - -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build -WORKDIR /src -COPY ["src/apps/all-in-one-web/Elsa.AllInOne.Web.csproj", "apps/all-in-one-web/"] -COPY src . -COPY NuGet.Config . -RUN dotnet restore "apps/all-in-one-web/Elsa.AllInOne.Web.csproj" -WORKDIR "/src/apps/all-in-one-web" -RUN dotnet build "Elsa.AllInOne.Web.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Elsa.AllInOne.Web.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Elsa.AllInOne.Web.dll"] diff --git a/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj b/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj index 95a98eddb1..78c43e421d 100644 --- a/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj +++ b/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0 + net7.0 enable enable Linux diff --git a/src/modules/Elsa.JavaScript/Elsa.JavaScript.csproj b/src/modules/Elsa.JavaScript/Elsa.JavaScript.csproj index 911e4f62b4..bdb72d863a 100644 --- a/src/modules/Elsa.JavaScript/Elsa.JavaScript.csproj +++ b/src/modules/Elsa.JavaScript/Elsa.JavaScript.csproj @@ -19,7 +19,7 @@ - +