From b9ef2f94bbb66bf06b3beee5ddca7d7493381b0f Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 14 Nov 2021 13:12:41 +0200 Subject: [PATCH] AddEnvironmentVariables fix + build and release scripts --- Chatbot.Api/Dockerfile | 2 ++ Chatbot.Api/Program.cs | 1 + Chatbot.sln | 7 +++++++ build-amd64.sh | 23 +++++++++++++++++++++++ release.sh | 22 ++++++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 build-amd64.sh create mode 100644 release.sh diff --git a/Chatbot.Api/Dockerfile b/Chatbot.Api/Dockerfile index 49eb04e..3aef4e2 100644 --- a/Chatbot.Api/Dockerfile +++ b/Chatbot.Api/Dockerfile @@ -27,6 +27,8 @@ COPY --from=publish /app/publish . ENV urls="http://*:80" ENV ConnectionStrings__DatabaseConnection="***REMOVED***" +ENV TZ=Europe/Bucharest +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone #Workaround to lower the TLS level in container for old sql server version RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf diff --git a/Chatbot.Api/Program.cs b/Chatbot.Api/Program.cs index d33556f..da3fd45 100644 --- a/Chatbot.Api/Program.cs +++ b/Chatbot.Api/Program.cs @@ -26,6 +26,7 @@ namespace Chatbot.Api var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddEnvironmentVariables() .Build(); var connectionString = configuration.GetConnectionString("DatabaseConnection"); diff --git a/Chatbot.sln b/Chatbot.sln index ef87f2e..f8f08ce 100644 --- a/Chatbot.sln +++ b/Chatbot.sln @@ -23,6 +23,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chatbot.Api.Domain.Data", " EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{3AC727D4-4E65-4D98-A532-04C489540A74}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{341EE785-7F03-457F-9188-0ADB1A2B9DBD}" + ProjectSection(SolutionItems) = preProject + build-amd64.sh = build-amd64.sh + release.sh = release.sh + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -54,6 +60,7 @@ Global {3759725E-8E75-44F4-86A3-34CC1EAC1D6C} = {3AC727D4-4E65-4D98-A532-04C489540A74} {1FDA8402-A777-48AF-91A3-34B7D033A8A5} = {3AC727D4-4E65-4D98-A532-04C489540A74} {999F5359-3CD8-4A0C-86B8-E3DC5421AA0C} = {3AC727D4-4E65-4D98-A532-04C489540A74} + {341EE785-7F03-457F-9188-0ADB1A2B9DBD} = {C42EC299-F3D5-4326-A756-80F9FEF233D9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B43E78A6-ACCC-4A5C-84E2-0B6237C79896} diff --git a/build-amd64.sh b/build-amd64.sh new file mode 100644 index 0000000..d3f6913 --- /dev/null +++ b/build-amd64.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "Welcome!" + +version="1.0.0" +localRegistryPass="***REMOVED***" + +echo "Create docker image with version $version." +docker image build -t "chatbot-api:$version" -f "Chatbot.Api/Dockerfile" . + +echo "Tag docker image with registry prefix." +docker tag chatbot-api:$version alpine-nexus:8500/chatbot/chatbot-api:$version + +echo "Login to alpine-nexus registry." +docker login --username=admin --password=$localRegistryPass alpine-nexus:8500 + +echo "Push image alpine-nexus:8500/chatbot/chatbot-api:$version to registry." +docker push alpine-nexus:8500/chatbot/chatbot-api:$version + +echo "Remove image alpine-nexus:8500/chatbot/chatbot-api:$version from local machine." +docker rmi alpine-nexus:8500/chatbot/chatbot-api:$version + +echo "DONE!" \ No newline at end of file diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..a0c7da2 --- /dev/null +++ b/release.sh @@ -0,0 +1,22 @@ +#!/bin/sh +echo "Welcome!" + +version="1.0.1" +oldver="1.0.0" + +echo "Pull docker image chatbot-api:$version from registry." +docker pull alpine-nexus:8500/chatbot/chatbot-api:$version + +echo "Stop old container." +docker stop chatbot-api && docker rm chatbot-api + +echo "Run new container." +docker run -d --name chatbot-api --restart=always -p 5006:80 alpine-nexus:8500/chatbot/chatbot-api:$version + +echo "Remove old image chatbot-api:$oldver." +docker rmi alpine-nexus:8500/chatbot/chatbot-api:$oldver + +echo "Get container logs:" +docker logs chatbot-api + +echo "DONE!" \ No newline at end of file