From 2244edd2ed553c9423de40d44f5ec6fbbf8e5a98 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Thu, 14 Nov 2024 16:12:06 +0200 Subject: [PATCH] add docker, deploy --- .dockerignore | 25 +++++ .gitignore | 3 +- Azaion.Api.sln | 7 ++ Azaion.Api/.env | 1 + Azaion.Api/Azaion.Api.csproj | 1 + Azaion.Api/Azaion.Api.http | 6 -- Azaion.Api/Program.cs | 3 +- Azaion.Api/appsettings.Development.json | 4 - Dockerfile | 22 +++++ env/01 sh-install/01-general.sh | 8 ++ env/01 sh-install/02-rabbit-install.sh | 41 +++++++++ env/01 sh-install/03-rabbit-configure.sh | 15 +++ env/01 sh-install/04-nginx-docker-registry.sh | 92 +++++++++++++++++++ env/01_db_permissions.sql | 16 ---- .../02_structure.sql} | 0 15 files changed, 215 insertions(+), 29 deletions(-) create mode 100644 .dockerignore create mode 100644 Azaion.Api/.env delete mode 100644 Azaion.Api/Azaion.Api.http create mode 100644 Dockerfile create mode 100644 env/01 sh-install/01-general.sh create mode 100644 env/01 sh-install/02-rabbit-install.sh create mode 100644 env/01 sh-install/03-rabbit-configure.sh create mode 100644 env/01 sh-install/04-nginx-docker-registry.sh delete mode 100644 env/01_db_permissions.sql rename env/{02_db_structure.sql => 02 db-scripts/02_structure.sql} (100%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index ae8e9cc..23faf00 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ obj log* *.cmd *permissions.sql -Content/ \ No newline at end of file +Content/ +.env \ No newline at end of file diff --git a/Azaion.Api.sln b/Azaion.Api.sln index f8d089b..e90cdae 100644 --- a/Azaion.Api.sln +++ b/Azaion.Api.sln @@ -8,6 +8,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Services", "Azaion.S EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Test", "Azaion.Test\Azaion.Test.csproj", "{2F4F0EA9-0645-4917-8D21-F317E815EB9E}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docker", "Docker", "{49FBE419-D2FA-4D7C-8419-D3AD5B44DD58}" + ProjectSection(SolutionItems) = preProject + Dockerfile = Dockerfile + .dockerignore = .dockerignore + deploy.cmd = deploy.cmd + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Azaion.Api/.env b/Azaion.Api/.env new file mode 100644 index 0000000..ff7579e --- /dev/null +++ b/Azaion.Api/.env @@ -0,0 +1 @@ +ASPNETCORE_JwtConfig__Secret=sdkfjghbsdfklhjgvbsdkljfhbvasklhfgsdfvh \ No newline at end of file diff --git a/Azaion.Api/Azaion.Api.csproj b/Azaion.Api/Azaion.Api.csproj index faeea4e..60050f0 100644 --- a/Azaion.Api/Azaion.Api.csproj +++ b/Azaion.Api/Azaion.Api.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + Linux diff --git a/Azaion.Api/Azaion.Api.http b/Azaion.Api/Azaion.Api.http deleted file mode 100644 index 08f7a1f..0000000 --- a/Azaion.Api/Azaion.Api.http +++ /dev/null @@ -1,6 +0,0 @@ -@Azaion.Api_HostAddress = http://localhost:5219 - -GET {{Azaion.Api_HostAddress}}/weatherforecast/ -Accept: application/json - -### diff --git a/Azaion.Api/Program.cs b/Azaion.Api/Program.cs index 54d9cf4..60cfaff 100644 --- a/Azaion.Api/Program.cs +++ b/Azaion.Api/Program.cs @@ -16,7 +16,7 @@ var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel(o => o.Limits.MaxRequestBodySize = 209715200); //increase upload limit up to 200mb var jwtConfig = builder.Configuration.GetSection(nameof(JwtConfig)).Get(); -if (jwtConfig == null) +if (jwtConfig == null || string.IsNullOrEmpty(jwtConfig.Secret)) throw new Exception("Missing configuration section: JwtConfig"); var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtConfig.Secret)); @@ -87,7 +87,6 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } -app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); diff --git a/Azaion.Api/appsettings.Development.json b/Azaion.Api/appsettings.Development.json index 76727db..0c208ae 100644 --- a/Azaion.Api/appsettings.Development.json +++ b/Azaion.Api/appsettings.Development.json @@ -4,9 +4,5 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - }, - "ConnectionStrings": { - "AzaionDb": "Host=localhost;Database=azaion;Username=azaion_reader;Password=Az@1on_re@d!only@$Az;", - "AzaionDbAdmin": "Host=localhost;Database=azaion;Username=azaion_admin;Password=Az@1on_admin$$@r;" } } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3f0a8bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +WORKDIR /app +EXPOSE 8080 + +# Build whole app +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /app + +COPY . . +RUN dotnet restore + +WORKDIR "/app/Azaion.Api" +RUN dotnet build "Azaion.Api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Azaion.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false + +# Build runtime +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Azaion.Api.dll"] diff --git a/env/01 sh-install/01-general.sh b/env/01 sh-install/01-general.sh new file mode 100644 index 0000000..7f20ccb --- /dev/null +++ b/env/01 sh-install/01-general.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +sudo -s +apt -y update +apt -y upgrade + +apt install -y dotnet-sdk-8.0 aspnetcore-runtime-8.0 +apt install -y zlib1g nodejs npm \ No newline at end of file diff --git a/env/01 sh-install/02-rabbit-install.sh b/env/01 sh-install/02-rabbit-install.sh new file mode 100644 index 0000000..7c1071c --- /dev/null +++ b/env/01 sh-install/02-rabbit-install.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +sudo apt-get install curl gnupg apt-transport-https -y + +## Team RabbitMQ's main signing key +curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/com.rabbitmq.team.gpg > /dev/null +## Community mirror of Cloudsmith: modern Erlang repository +curl -1sLf https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg > /dev/null +## Community mirror of Cloudsmith: RabbitMQ repository +curl -1sLf https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/rabbitmq.9F4587F226208342.gpg > /dev/null + +## Add apt repositories maintained by Team RabbitMQ +sudo tee /etc/apt/sources.list.d/rabbitmq.list <