Updating docker file to not include ports. Added scripts folder and script to run docker with env vars passed via command line. Also now the build and packaging is happening in container
This commit is contained in:
parent
60efbc0f9e
commit
3262ff82b0
9 changed files with 123 additions and 7 deletions
|
@ -1,8 +1,8 @@
|
||||||
FROM gcr.io/google-appengine/aspnetcore:2.1.0
|
FROM gcr.io/google-appengine/aspnetcore:2.1.0
|
||||||
COPY . /app
|
COPY . /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
RUN dotnet restore
|
||||||
|
RUN dotnet build
|
||||||
|
RUN dotnet publish
|
||||||
|
WORKDIR /app/bin/Debug/netcoreapp2.0
|
||||||
ENTRYPOINT ["dotnet", "cartservice.dll", "start"]
|
ENTRYPOINT ["dotnet", "cartservice.dll", "start"]
|
||||||
ENV REDIS_ADDR=172.30.147.193
|
|
||||||
ENV CART_SERVICE_ADDR=127.0.0.1
|
|
||||||
ENV CART_SERVICE_PORT=8080
|
|
||||||
EXPOSE 8080
|
|
|
@ -85,7 +85,7 @@ namespace cartservice
|
||||||
int port = options.Port;
|
int port = options.Port;
|
||||||
if (options.Port <= 0)
|
if (options.Port <= 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Reading cart service port from {CART_SERVICE_ADDRESS} environment variable");
|
Console.WriteLine($"Reading cart service port from {CART_SERVICE_PORT} environment variable");
|
||||||
string portStr = Environment.GetEnvironmentVariable(CART_SERVICE_PORT);
|
string portStr = Environment.GetEnvironmentVariable(CART_SERVICE_PORT);
|
||||||
if (string.IsNullOrEmpty(portStr))
|
if (string.IsNullOrEmpty(portStr))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
echo building container image for cart service
|
echo building container image for cart service
|
||||||
docker build -t cartservice .
|
docker build -t cartservice ..\.
|
||||||
|
|
||||||
echo running the image, mapping the port
|
echo running the image, mapping the port
|
||||||
docker run -it --rm -p 5000:8080 --name
|
rem echo docker run -it --rm -p 5000:8080 --name
|
13
src/cartservice/scripts/docker_setup.bat
Normal file
13
src/cartservice/scripts/docker_setup.bat
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
set REDIS_PORT=6379
|
||||||
|
set REDIS_ADDR=172.30.147.193
|
||||||
|
set CART_SERVICE_ADDR=127.0.0.1
|
||||||
|
set CART_SERVICE_PORT=7070
|
||||||
|
|
||||||
|
rem run docker container with redis
|
||||||
|
rem docker run -d --name=redis -p %REDIS_PORT%:%REDIS_PORT% redis:alpine
|
||||||
|
|
||||||
|
rem run docker container with cart service
|
||||||
|
docker run -it --rm -e REDIS_ADDR=%REDIS_ADDR%:%REDIS_PORT% -e CART_SERVICE_ADDR=%CART_SERVICE_ADDR% -e CART_SERVICE_PORT=%CART_SERVICE_PORT% -p %CART_SERVICE_PORT%:%CART_SERVICE_PORT% cartservice
|
||||||
|
rem -e GRPC_TRACE=all -e GRPC_VERBOSITY=debug
|
3
tests/cartservice/.gitignore
vendored
Normal file
3
tests/cartservice/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/bin/*
|
||||||
|
/obj/*
|
||||||
|
/.vs/*
|
64
tests/cartservice/CartServiceTests.cs
Normal file
64
tests/cartservice/CartServiceTests.cs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Grpc.Core;
|
||||||
|
using Hipstershop;
|
||||||
|
using Xunit;
|
||||||
|
using static Hipstershop.CartService;
|
||||||
|
|
||||||
|
namespace cartservice
|
||||||
|
{
|
||||||
|
public class E2ETests
|
||||||
|
{
|
||||||
|
private static string serverHostName = "172.17.0.2";
|
||||||
|
private static int port = 7070;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddItem_ItemInserted()
|
||||||
|
{
|
||||||
|
string userId = "user1";
|
||||||
|
|
||||||
|
// Construct server's Uri
|
||||||
|
string targetUri = $"{serverHostName}:{port}";
|
||||||
|
|
||||||
|
// Create a GRPC communication channel between the client and the server
|
||||||
|
var channel = new Channel(targetUri, ChannelCredentials.Insecure);
|
||||||
|
//ar interceptorObject = new ObjecT();
|
||||||
|
//var channel.Intercept(interceptorObject);
|
||||||
|
// Create a proxy object to work with the server
|
||||||
|
var client = new CartServiceClient(channel);
|
||||||
|
|
||||||
|
var request = new AddItemRequest
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Item = new CartItem
|
||||||
|
{
|
||||||
|
ProductId = "1",
|
||||||
|
Quantity = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine("Try " + i+1);
|
||||||
|
await client.AddItemAsync(request);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var getCardRequest = new GetCartRequest
|
||||||
|
{
|
||||||
|
UserId = userId
|
||||||
|
};
|
||||||
|
var cart = await client.GetCartAsync(getCardRequest);
|
||||||
|
|
||||||
|
Assert.Equal(userId, cart.UserId);
|
||||||
|
Assert.Single(cart.Items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
tests/cartservice/cartservice.tests.csproj
Normal file
30
tests/cartservice/cartservice.tests.csproj
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Google.Protobuf" Version="3.6.0" />
|
||||||
|
<PackageReference Include="Google.Protobuf.Tools" Version="3.6.0" />
|
||||||
|
<PackageReference Include="Grpc" Version="1.12.0" />
|
||||||
|
<PackageReference Include="Grpc.Tools" Version="1.12.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.3.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||||
|
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\cartservice\cartservice.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
6
tests/cartservice/cartservice.tests.csproj.user
Normal file
6
tests/cartservice/cartservice.tests.csproj.user
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ShowAllFiles>true</ShowAllFiles>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
Loading…
Reference in a new issue