Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Docker image build #35

Merged
merged 3 commits into from Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
@@ -0,0 +1,4 @@
**/bin/
**/obj/
**/out/
**/TestResults/
46 changes: 34 additions & 12 deletions .github/workflows/aspnetcore.yml
Expand Up @@ -3,15 +3,37 @@ name: ASP.NET Core CI
on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.100'
- name: Build with dotnet
run: dotnet build --configuration Release ./EventSourcing.NetCore.sln
build:
runs-on: ubuntu-latest

steps:
- name: Check Out Repo
uses: actions/checkout@v1

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.100'

- name: Build with dotnet
run: dotnet build --configuration Release ./EventSourcing.NetCore.sln

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: github.ref == 'refs/heads/main'
tags: oskardudycz/eventsourcing.netcore:latest

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 2 additions & 0 deletions .gitignore
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
@@ -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
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
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
@@ -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
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
44 changes: 44 additions & 0 deletions docker-compose.build.yml
@@ -0,0 +1,44 @@
version: "2.1"
services:
postgres:
image: clkao/postgres-plv8
container_name: postgres
hostname: postgres
environment:
POSTGRES_PASSWORD: Password12!
ports:
- "5432:5432"
networks:
- es_network
healthcheck:
test: "pg_isready -U postgres"
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
context: .
container_name: event_sourcing_sample
ports:
- "5555:5000"
depends_on:
postgres:
condition: service_healthy
networks:
- es_network
networks:
es_network:
driver: bridge
20 changes: 15 additions & 5 deletions docker-compose.yml
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,23 @@ 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
context: .
image: oskardudycz/eventsourcing.netcore
container_name: event_sourcing_sample
ports:
- "5000:5000"
- "5555:5000"
depends_on:
postgres:
condition: service_healthy
Expand Down