From 6ecfa671733c96432dfc1fe2e1e39bd029cec424 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 23 May 2024 22:44:52 +0200 Subject: [PATCH] Dockerfiles for auth/web, deployment scripts --- SS14.Auth/SS14.Auth.csproj | 8 ++++---- SS14.Web.sln | 2 ++ auth.Dockerfile | 24 ++++++++++++++++++++++++ build.sh | 17 +++++++++++++++++ deploy.sh | 22 ++++++++++++++++++++++ web.Dockerfile | 24 ++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 auth.Dockerfile create mode 100644 build.sh create mode 100644 deploy.sh create mode 100644 web.Dockerfile diff --git a/SS14.Auth/SS14.Auth.csproj b/SS14.Auth/SS14.Auth.csproj index 26cc08e..e4b3f5d 100644 --- a/SS14.Auth/SS14.Auth.csproj +++ b/SS14.Auth/SS14.Auth.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable @@ -10,10 +10,10 @@ - + - - + + diff --git a/SS14.Web.sln b/SS14.Web.sln index 1591cfb..97d8af6 100644 --- a/SS14.Web.sln +++ b/SS14.Web.sln @@ -13,6 +13,8 @@ ProjectSection(SolutionItems) = preProject deploy.sh = deploy.sh build.sh = build.sh .dockerignore = .dockerignore + auth.Dockerfile = auth.Dockerfile + web.Dockerfile = web.Dockerfile EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{569B190C-2FE6-44FA-B282-E0E7ACE64226}" diff --git a/auth.Dockerfile b/auth.Dockerfile new file mode 100644 index 0000000..d60c26f --- /dev/null +++ b/auth.Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +RUN mkdir /repo && chown $APP_UID /repo +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["SS14.Auth/SS14.Auth.csproj", "SS14.Auth/"] +RUN dotnet restore "SS14.Auth/SS14.Auth.csproj" +COPY . . +WORKDIR "/src/SS14.Auth" +RUN dotnet build "SS14.Auth.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "SS14.Auth.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "SS14.Auth.dll"] diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..6b3ed8b --- /dev/null +++ b/build.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -e + +to_build=$1 + +if [ "$to_build" == hub ]; then + docker build . -f hub.Dockerfile -t ss14_serverhub +fi + +if [ "$to_build" == web ]; then + docker build . -f web.Dockerfile -t ss14_web +fi + +if [ "$to_build" == auth ]; then + docker build . -f auth.Dockerfile -t ss14_auth +fi diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..ea9ee85 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +to_build=$1 + +if [ "$to_build" == hub ]; then + docker image save ss14_serverhub | gzip | ssh pebbles podman load & + docker image save ss14_serverhub | gzip | ssh nsh podman load & +fi + +if [ "$to_build" == auth ]; then + docker image save ss14_auth | gzip | ssh pebbles podman load & + docker image save ss14_auth | gzip | ssh nsh podman load & +fi + +if [ "$to_build" == web ]; then + docker image save ss14_web | gzip | ssh pebbles podman load & + docker image save ss14_web | gzip | ssh nsh podman load & +fi + +wait $(jobs -p) diff --git a/web.Dockerfile b/web.Dockerfile new file mode 100644 index 0000000..027884c --- /dev/null +++ b/web.Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +RUN mkdir /repo && chown 1654 /repo +USER 1654 +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["SS14.Web/SS14.Web.csproj", "SS14.Web/"] +RUN dotnet restore "SS14.Web/SS14.Web.csproj" +COPY . . +WORKDIR "/src/SS14.Web" +RUN dotnet build "SS14.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "SS14.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "SS14.Web.dll"]