Skip to content

Commit

Permalink
Fixed Dockerfile - added proper multistage build and replaced sample …
Browse files Browse the repository at this point in the history
…from Bank Accounts to Cinema Tickets (as it's more complete)

Added pgAdmin image to docker-compose to be able to see changes in DB
Added .dockerignore to not copy binaries into the docker build
Added missing projects to Tickets/Tickets.sln
Updated README information about .NET
  • Loading branch information
oskardudycz committed Jan 2, 2021
1 parent cc16294 commit f26d4d3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 39 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/bin/
**/obj/
**/out/
**/TestResults/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,5 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml

**/out
19 changes: 0 additions & 19 deletions DOCKERFILE

This file was deleted.

60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
########################################
# First stage of multistage build
########################################
# Use Build image with label `builder
########################################
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS builder

# Setup working directory for project
WORKDIR /app

COPY ./Core/Core.csproj ./Core/
COPY ./Core.Marten/Core.Marten.csproj ./Core.Marten/
COPY ./Sample/Tickets/Tickets/Tickets.csproj ./Sample/Tickets/Tickets/
COPY ./Sample/Tickets/Tickets.Api/ ./Sample/Tickets/Tickets.Api/

# Restore nuget packages
RUN dotnet restore ./Sample/Tickets/Tickets.Api/Tickets.Api.csproj

# Copy project files
COPY ./Core ./Core
COPY ./Core.Marten ./Core.Marten
COPY ./Sample/Tickets/Tickets ./Sample/Tickets/Tickets
COPY ./Sample/Tickets/Tickets.Api ./Sample/Tickets/Tickets.Api

# Build project with Release configuration
# and no restore, as we did it already
RUN dotnet build -c Release --no-restore ./Sample/Tickets/Tickets.Api/Tickets.Api.csproj

## Test project with Release configuration
## and no build, as we did it already
#RUN dotnet test -c Release --no-build ./Sample/Tickets/Tickets.Api/Tickets.Api.csproj


# Publish project to output folder
# and no build, as we did it already
WORKDIR /app/Sample/Tickets/Tickets.Api
RUN ls
RUN dotnet publish -c Release --no-build -o out

########################################
# Second stage of multistage build
########################################
# Use other build image as the final one
# that won't have source codes
########################################
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine

# Setup working directory for project
WORKDIR /app

# Copy published in previous stage binaries
# from the `builder` image
COPY --from=builder /app/Sample/Tickets/Tickets.Api/out .

# Set URL that App will be exposed
ENV ASPNETCORE_URLS="http://*:5000"

# sets entry point command to automatically
# run application on `docker run`
ENTRYPOINT ["dotnet", "Tickets.Api.dll"]
7 changes: 7 additions & 0 deletions EventSourcing.NetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,11 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A5F55604-2FF3-43B7-B657-4F18E6E95D3B}
EndGlobalSection
GlobalSection(RiderSharedRunConfigurations) = postSolution
File = Workshops\PracticalEventSourcing\Carts.run.xml
File = Workshops\PracticalEventSourcing\Orders.run.xml
File = Workshops\PracticalEventSourcing\Payments.run.xml
File = Workshops\PracticalEventSourcing\PracticalEventSourcing.run.xml
File = Workshops\PracticalEventSourcing\Shipments.run.xml
EndGlobalSection
EndGlobal
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ Feel free to [create an issue](https://github.com/oskardudycz/EventSourcing.NetC

## 2. Prerequisites

For running the Event Store examples you need to have Postgres DB. You can get it by:
For running the Event Store examples you need to have:

1. .NET 5 installed - https://dotnet.microsoft.com/download/dotnet/5.0
2. Postgres DB. You can get it by:
- Installing [Docker](https://store.docker.com/search?type=edition&offering=community), going to the `docker` folder and running:

```
docker-compose up
```
- Installing a most recent version of the Postgres DB (eg. from <https://www.postgresql.org/download/>).

**More information about using .NET Core, WebApi and Docker you can find in my other tutorial:** [.Net Core With Docker](https://github.com/oskardudycz/NetCoreWithDocker)
**More information about using .NET Core, WebApi and Docker you can find in my other tutorials:** [WebApi with .NET](https://github.com/oskardudycz/WebApiWith.NETCore)

- Installing a most recent version of the Postgres DB (eg. from <https://www.postgresql.org/download/>).

Watch "Practical Event Sourcing with Marten":

Expand Down Expand Up @@ -302,4 +304,4 @@ Support this project with your organization. Your logo will show up here with a
<a href="https://opencollective.com/eventsourcingnetcore/organization/8/website"><img src="https://opencollective.com/eventsourcingnetcore/organization/8/avatar.svg"></a>
<a href="https://opencollective.com/eventsourcingnetcore/organization/9/website"><img src="https://opencollective.com/eventsourcingnetcore/organization/9/avatar.svg"></a>

**EventSourcing.NetCore** is Copyright &copy; 2017-2020 [Oskar Dudycz](http://oskar-dudycz.pl) and other contributors under the [MIT license](LICENSE).
**EventSourcing.NetCore** is Copyright &copy; 2017-2021 [Oskar Dudycz](http://oskar-dudycz.pl) and other contributors under the [MIT license](LICENSE).
30 changes: 18 additions & 12 deletions Sample/Tickets/Tickets.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{5985A39C-B4DE-438B-9AF9-BDCA9B15876E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Testing", "Core.Testing\Core.Testing.csproj", "{57EA5769-4B22-45C9-A525-6256B95A17C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tickets", "Tickets\Tickets.csproj", "{F48D6AE8-49A5-4890-BA18-C0AEBD9A411C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tickets.Api", "Tickets.Api\Tickets.Api.csproj", "{B550D4DB-33D5-4560-AE32-0773BB7BAAF8}"
Expand All @@ -12,20 +8,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tickets.Api.Tests", "Ticket
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tickets.Tests", "Tickets.Tests\Tickets.Tests.csproj", "{3349648E-E8EB-49C6-BDA0-D8E675F36B88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "..\..\Core\Core.csproj", "{868A877F-2073-4AFD-8573-7FC16B4E82C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Marten", "..\..\Core.Marten\Core.Marten.csproj", "{7CB6C83C-75AA-4639-BC46-1BF99D26512C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Testing", "..\..\Core.Testing\Core.Testing.csproj", "{87D49BAA-91B6-4209-868B-B5C8C9E1C8EF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5985A39C-B4DE-438B-9AF9-BDCA9B15876E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5985A39C-B4DE-438B-9AF9-BDCA9B15876E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5985A39C-B4DE-438B-9AF9-BDCA9B15876E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5985A39C-B4DE-438B-9AF9-BDCA9B15876E}.Release|Any CPU.Build.0 = Release|Any CPU
{57EA5769-4B22-45C9-A525-6256B95A17C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57EA5769-4B22-45C9-A525-6256B95A17C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57EA5769-4B22-45C9-A525-6256B95A17C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57EA5769-4B22-45C9-A525-6256B95A17C6}.Release|Any CPU.Build.0 = Release|Any CPU
{F48D6AE8-49A5-4890-BA18-C0AEBD9A411C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F48D6AE8-49A5-4890-BA18-C0AEBD9A411C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F48D6AE8-49A5-4890-BA18-C0AEBD9A411C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -42,5 +36,17 @@ Global
{3349648E-E8EB-49C6-BDA0-D8E675F36B88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3349648E-E8EB-49C6-BDA0-D8E675F36B88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3349648E-E8EB-49C6-BDA0-D8E675F36B88}.Release|Any CPU.Build.0 = Release|Any CPU
{868A877F-2073-4AFD-8573-7FC16B4E82C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{868A877F-2073-4AFD-8573-7FC16B4E82C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{868A877F-2073-4AFD-8573-7FC16B4E82C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{868A877F-2073-4AFD-8573-7FC16B4E82C5}.Release|Any CPU.Build.0 = Release|Any CPU
{7CB6C83C-75AA-4639-BC46-1BF99D26512C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CB6C83C-75AA-4639-BC46-1BF99D26512C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CB6C83C-75AA-4639-BC46-1BF99D26512C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CB6C83C-75AA-4639-BC46-1BF99D26512C}.Release|Any CPU.Build.0 = Release|Any CPU
{87D49BAA-91B6-4209-868B-B5C8C9E1C8EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87D49BAA-91B6-4209-868B-B5C8C9E1C8EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87D49BAA-91B6-4209-868B-B5C8C9E1C8EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87D49BAA-91B6-4209-868B-B5C8C9E1C8EF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Workshops/BuildYourOwnEventStore/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Prerequisities

1. Install git - https://git-scm.com/downloads.
2. Install .NET Core 3.1 - https://dotnet.microsoft.com/download/dotnet-core/thank-you/sdk-3.1.402-windows-x64-installer.
2. Install .NET 5 - https://dotnet.microsoft.com/download/dotnet/5.0.
3. Install Visual Studio 2019, Rider or VSCode.
4. Install docker - https://docs.docker.com/docker-for-windows/install/.
5. Make sure that you have ~10GB disk space.
Expand Down
18 changes: 15 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: postgres
hostname: postgres
environment:
- postgres/variables.env
POSTGRES_PASSWORD: Password12!
ports:
- "5432:5432"
networks:
Expand All @@ -15,13 +15,25 @@ services:
interval: 10s
timeout: 5s
retries: 5

pgadmin:
image: dpage/pgadmin4
container_name: pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- es_network

backend:
build:
dockerfile: DOCKERFILE
dockerfile: Dockerfile
context: .
container_name: event_sourcing_sample
ports:
- "5000:5000"
- "5555:5000"
depends_on:
postgres:
condition: service_healthy
Expand Down

0 comments on commit f26d4d3

Please sign in to comment.