From d9e8d8708373e71b9eb61e2a1fdb711c68a66514 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 14 Aug 2021 19:40:36 +0300 Subject: [PATCH] dockerfile for arm32v7 --- NetworkResurrector.sln | 7 ++++ build-amd64.sh | 25 +++++++++++++ build-arm32v7.sh | 32 ++++++++++++++++ .../NetworkResurrector.Api/Docker/Dockerfile | 37 +++++++++++++++++++ .../{ => Docker/amd64}/Dockerfile | 2 +- .../Docker/arm32v7/Dockerfile | 35 ++++++++++++++++++ .../Notes/{Docker.txt => Docker-amd64.txt} | 3 +- .../Notes/Docker-arm32v7.txt | 33 +++++++++++++++++ 8 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 build-amd64.sh create mode 100644 build-arm32v7.sh create mode 100644 src/api/NetworkResurrector.Api/Docker/Dockerfile rename src/api/NetworkResurrector.Api/{ => Docker/amd64}/Dockerfile (91%) create mode 100644 src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile rename src/api/NetworkResurrector.Api/Notes/{Docker.txt => Docker-amd64.txt} (86%) create mode 100644 src/api/NetworkResurrector.Api/Notes/Docker-arm32v7.txt diff --git a/NetworkResurrector.sln b/NetworkResurrector.sln index 6fa5fd3..79f7d3a 100644 --- a/NetworkResurrector.sln +++ b/NetworkResurrector.sln @@ -41,6 +41,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Api.Doma EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Api.Domain.Data", "src\api\NetworkResurrector.Api.Domain.Data\NetworkResurrector.Api.Domain.Data.csproj", "{509767A7-D11C-4143-8D45-01E62DFC2C74}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{DF5CBFF4-B348-4D4C-A6D4-B65BA1D64CEF}" + ProjectSection(SolutionItems) = preProject + build-amd64.sh = build-amd64.sh + build-arm32v7.sh = build-arm32v7.sh + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -104,6 +110,7 @@ Global {EE31B126-12EC-46B3-8FB4-AD5BCF14C029} = {43C78941-52E6-4AB8-9170-CC7C006E4784} {885D5625-028A-4B35-8C89-7EF718BC6E34} = {43C78941-52E6-4AB8-9170-CC7C006E4784} {509767A7-D11C-4143-8D45-01E62DFC2C74} = {43C78941-52E6-4AB8-9170-CC7C006E4784} + {DF5CBFF4-B348-4D4C-A6D4-B65BA1D64CEF} = {FDDE879C-E0A3-4BF1-945F-7FEA324C8EBA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7} diff --git a/build-amd64.sh b/build-amd64.sh new file mode 100644 index 0000000..8ab664f --- /dev/null +++ b/build-amd64.sh @@ -0,0 +1,25 @@ +#!/bin/bash +echo "Welcome!" + +version="1.0.0" +localRegistryPass="***REMOVED***" + +echo "Login to dockerhub registry." +docker login --username=tstanciu --password=$dockerHubRegistryPass + +echo "Create docker image with version $version." +docker image build -t "network-resurrector-api:$version" -f "src/api/NetworkResurrector.Api/Docker/amd64/Dockerfile" . + +echo "Tag docker image with registry prefix." +docker tag network-resurrector-api:$version alpine-nexus:8500/network-resurrector/network-resurrector-api:$version + +echo "Login to alpine-nexus registry." +docker login --username=admin --password=$localRegistryPass alpine-nexus:8500 + +echo "Push image alpine-nexus:8500/network-resurrector/network-resurrector-api:$version to registry." +docker push alpine-nexus:8500/network-resurrector/network-resurrector-api:$version + +echo "Remove image alpine-nexus:8500/network-resurrector/network-resurrector-api:$version from local machine." +docker rmi alpine-nexus:8500/network-resurrector/network-resurrector-api:$version + +echo "DONE!" \ No newline at end of file diff --git a/build-arm32v7.sh b/build-arm32v7.sh new file mode 100644 index 0000000..005dd99 --- /dev/null +++ b/build-arm32v7.sh @@ -0,0 +1,32 @@ +#!/bin/bash +echo "Welcome!" + +version="1.0.0" +localRegistryPass="***REMOVED***" +dockerHubRegistryPass="***REMOVED***" + +echo "Login to dockerhub registry." +docker login --username=tstanciu --password=$dockerHubRegistryPass + +echo "Create docker image with version $version and publish it to dockerhub registry." +docker buildx build --platform linux/arm/v7 -t "tstanciu/sta-registry:network-resurrector-api-$version-arm32v7" -f "src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile" --push . + +echo "Pull docker image with version $version from dockerhub registry." +docker pull tstanciu/sta-registry:network-resurrector-api-$version-arm32v7 + +echo "Tag docker image with alpine-nexus registry prefix." +docker tag tstanciu/sta-registry:network-resurrector-api-$version-arm32v7 alpine-nexus:8500/network-resurrector/network-resurrector-api:$version-arm32v7 + +echo "Login to alpine-nexus registry." +docker login --username=admin --password=$localRegistryPass alpine-nexus:8500 + +echo "Push image alpine-nexus:8500/network-resurrector/network-resurrector-api:$version-arm32v7 to registry." +docker push alpine-nexus:8500/network-resurrector/network-resurrector-api:$version-arm32v7 + +echo "Remove docker image tstanciu/sta-registry:network-resurrector-api-$version-arm32v7 from local machine." +docker rmi tstanciu/sta-registry:network-resurrector-api-$version-arm32v7 + +echo "Remove docker image tstanciu/sta-registry:network-resurrector-api-$version-arm32v7 from local machine." +docker rmi alpine-nexus:8500/network-resurrector/network-resurrector-api:$version-arm32v7 + +echo "DONE!" \ No newline at end of file diff --git a/src/api/NetworkResurrector.Api/Docker/Dockerfile b/src/api/NetworkResurrector.Api/Docker/Dockerfile new file mode 100644 index 0000000..5043792 --- /dev/null +++ b/src/api/NetworkResurrector.Api/Docker/Dockerfile @@ -0,0 +1,37 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +ARG BASE_IMAGE_VERSION + +FROM mcr.microsoft.com/dotnet/core/aspnet:$BASE_IMAGE_VERSION AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +WORKDIR /src +COPY dependencies.props . +COPY Directory.Build.props . +COPY NuGet.config . +COPY ["src/api/NetworkResurrector.Api/NetworkResurrector.Api.csproj", "NetworkResurrector.Api/"] +COPY ["src/api/NetworkResurrector.Api.Application/NetworkResurrector.Api.Application.csproj", "NetworkResurrector.Api.Application/"] +COPY ["src/api/NetworkResurrector.Api.Domain/NetworkResurrector.Api.Domain.csproj", "NetworkResurrector.Api.Domain/"] +COPY ["src/api/NetworkResurrector.Api.Domain.Data/NetworkResurrector.Api.Domain.Data.csproj", "NetworkResurrector.Api.Domain.Data/"] +RUN dotnet restore "NetworkResurrector.Api/NetworkResurrector.Api.csproj" +COPY src/api . +WORKDIR "/src/NetworkResurrector.Api" +RUN dotnet build "NetworkResurrector.Api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "NetworkResurrector.Api.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . + +ENV urls="http://*:80" +ENV ConnectionStrings__DatabaseConnection="***REMOVED***" +ENV IdentityServer__BaseAddress="http://***REMOVED***/" + +#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 + +ENTRYPOINT ["dotnet", "NetworkResurrector.Api.dll", "--console"] \ No newline at end of file diff --git a/src/api/NetworkResurrector.Api/Dockerfile b/src/api/NetworkResurrector.Api/Docker/amd64/Dockerfile similarity index 91% rename from src/api/NetworkResurrector.Api/Dockerfile rename to src/api/NetworkResurrector.Api/Docker/amd64/Dockerfile index 2a52bdf..8922bd2 100644 --- a/src/api/NetworkResurrector.Api/Dockerfile +++ b/src/api/NetworkResurrector.Api/Docker/amd64/Dockerfile @@ -1,4 +1,4 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app diff --git a/src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile b/src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile new file mode 100644 index 0000000..187e711 --- /dev/null +++ b/src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile @@ -0,0 +1,35 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim-arm32v7 AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +WORKDIR /src +COPY dependencies.props . +COPY Directory.Build.props . +COPY NuGet.config . +COPY ["src/api/NetworkResurrector.Api/NetworkResurrector.Api.csproj", "NetworkResurrector.Api/"] +COPY ["src/api/NetworkResurrector.Api.Application/NetworkResurrector.Api.Application.csproj", "NetworkResurrector.Api.Application/"] +COPY ["src/api/NetworkResurrector.Api.Domain/NetworkResurrector.Api.Domain.csproj", "NetworkResurrector.Api.Domain/"] +COPY ["src/api/NetworkResurrector.Api.Domain.Data/NetworkResurrector.Api.Domain.Data.csproj", "NetworkResurrector.Api.Domain.Data/"] +RUN dotnet restore "NetworkResurrector.Api/NetworkResurrector.Api.csproj" +COPY src/api . +WORKDIR "/src/NetworkResurrector.Api" +RUN dotnet build "NetworkResurrector.Api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "NetworkResurrector.Api.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . + +ENV urls="http://*:80" +ENV ConnectionStrings__DatabaseConnection="***REMOVED***" +ENV IdentityServer__BaseAddress="http://***REMOVED***/" + +#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 + +ENTRYPOINT ["dotnet", "NetworkResurrector.Api.dll", "--console"] \ No newline at end of file diff --git a/src/api/NetworkResurrector.Api/Notes/Docker.txt b/src/api/NetworkResurrector.Api/Notes/Docker-amd64.txt similarity index 86% rename from src/api/NetworkResurrector.Api/Notes/Docker.txt rename to src/api/NetworkResurrector.Api/Notes/Docker-amd64.txt index c8e3558..3f44965 100644 --- a/src/api/NetworkResurrector.Api/Notes/Docker.txt +++ b/src/api/NetworkResurrector.Api/Notes/Docker-amd64.txt @@ -3,7 +3,7 @@ Create image: --from solution folder: -docker image build -t "network-resurrector-api:1.0.1" -f "src/api/NetworkResurrector.Api/Dockerfile" . +docker image build -t "network-resurrector-api:1.0.1" -f "src/api/NetworkResurrector.Api/Docker/amd64/Dockerfile" . Run image: docker run -p 5053:80 -it network-resurrector-api:1.0.1 @@ -30,6 +30,7 @@ docker rm network-resurrector-api Run container in prod env docker run -d --name network-resurrector-api --restart=always -p 5008:80 alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1 +docker run -d --name network-resurrector-api --restart=always -p 5008:80 tstanciu/sta-registry:nr-api-1.0.1-arm Remove old image docker rmi alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.0 diff --git a/src/api/NetworkResurrector.Api/Notes/Docker-arm32v7.txt b/src/api/NetworkResurrector.Api/Notes/Docker-arm32v7.txt new file mode 100644 index 0000000..70e52a1 --- /dev/null +++ b/src/api/NetworkResurrector.Api/Notes/Docker-arm32v7.txt @@ -0,0 +1,33 @@ +Docker commands: +***************** + +Create image and push it: +--login to registry +docker login --username=tstanciu --password="***REMOVED***" + +--from solution folder: +docker buildx build --platform linux/arm/v7 -t "tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7" -f "src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile" --push . + +# With insecure registry +docker buildx build --platform linux/arm/v7 -t "alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1-arm" -f "src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile" --push . +https://docs.docker.com/engine/reference/commandline/buildx_create/ +https://stackoverflow.com/questions/63409755/how-to-use-docker-buildx-pushing-image-to-registry-use-http-protocol + + +Pull image from registry +--login to registry + +--pull image +docker pull tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7 + +Stop old container +docker stop network-resurrector-api && docker rm network-resurrector-api + +Run container in prod env +docker run -d --name network-resurrector-api --restart=always -p 5008:80 tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7 + +Remove old image +docker rmi tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7 + +docker run -d --name network-resurrector-api --restart=always -p 5008:80 alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1 +####################################################################################################################################################### \ No newline at end of file