try for build-publish

This commit is contained in:
meysamhadeli 2023-01-24 18:46:07 +03:30
parent 198256dfda
commit af3ec2e2ab
3 changed files with 93 additions and 34 deletions

View File

@ -1,23 +1,53 @@
name: Build and Push Docker Image
name: build-publish
on:
# run it on push to the default repository branch
push:
branches:
- develop
branches: [develop]
# run it during pull request
pull_request: [develop]
jobs:
build_and_push:
# define job to build and publish docker image
build-and-push-docker-image:
name: Build Docker image and push to repositories
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest
# steps to perform in job
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v3
- name: Build Docker Image
run: |
docker build -t myimage:${{ github.sha }} -f ./src/Services/Flight/Dockerfile .
# setup Docker buld action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to Docker Hub
run: docker push myimage:${{ github.sha }}
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v2
with:
# relative path to the place where source code with Dockerfile is located
context: ./src/Services/Flight
# Note: tags has to be all lower-case
tags: |
meysamhadeli/booking-microservices/flight:latest
ghcr.io/meysamhadeli/booking-microservices/flight:latest
# build on feature branches, push only on develop branch
push: ${{ github.ref == 'refs/heads/develop' }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

View File

@ -2,9 +2,9 @@ name: Build-Test
on:
push:
branches: [ "main" , "develop"]
branches: [ "main" , "develop" ]
paths-ignore:
- "README.md"
- "README.md"
pull_request:
branches: [ "main" , "develop" ]
@ -14,15 +14,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-restore
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: ${{ runner.os }}-dotnet-nuget
path: ~/.nuget/packages
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-restore

View File

@ -12,9 +12,17 @@ using Exception = System.Exception;
public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
{
private readonly Lazy<ILogger<PersistMessageDbContext>> _logger;
public PersistMessageDbContext(DbContextOptions<PersistMessageDbContext> options)
: base(options)
{
_logger = new Lazy<ILogger<PersistMessageDbContext>>(() =>
{
var factory = LoggerFactory.Create(b => b.AddConsole());
var logger = factory.CreateLogger<PersistMessageDbContext>();
return logger;
});
}
public DbSet<PersistMessage> PersistMessages => Set<PersistMessage>();
@ -37,10 +45,7 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
{
if (exception != null)
{
var factory = LoggerFactory.Create(b => b.AddConsole());
var logger = factory.CreateLogger<PersistMessageDbContext>();
logger.LogError(exception,
_logger.Value.LogError(exception,
"Request failed with {StatusCode}. Waiting {TimeSpan} before next retry. Retry attempt {RetryCount}.",
HttpStatusCode.Conflict,
timeSpan,
@ -55,12 +60,22 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
{
foreach (var entry in ex.Entries)
{
var currentEntity = entry.Entity; // we can use it for specific merging
var databaseValues = await entry.GetDatabaseValuesAsync(cancellationToken);
var currentValue = entry.Entity; // we can use it for specific merging
var databaseValue = await entry.GetDatabaseValuesAsync(cancellationToken);
if (databaseValues != null)
_logger.Value.LogInformation(
"Entry to entity with type: {Type}, database-value: {DatabaseValue} and current-value: {CurrentValue}",
entry.GetType().Name,
databaseValue,
currentValue);
if (databaseValue != null)
{
entry.OriginalValues.SetValues(databaseValues);
entry.OriginalValues.SetValues(databaseValue);
}
else
{
entry.OriginalValues.SetValues(currentValue);
}
}