mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-03 19:41:52 +08:00
try for build-publish
This commit is contained in:
parent
198256dfda
commit
af3ec2e2ab
56
.github/workflows/build-publish.yml
vendored
56
.github/workflows/build-publish.yml
vendored
@ -1,23 +1,53 @@
|
|||||||
name: Build and Push Docker Image
|
name: build-publish
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
# run it on push to the default repository branch
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [develop]
|
||||||
- develop
|
# run it during pull request
|
||||||
|
pull_request: [develop]
|
||||||
|
|
||||||
jobs:
|
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
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# steps to perform in job
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Build Docker Image
|
# setup Docker buld action
|
||||||
run: |
|
- name: Set up Docker Buildx
|
||||||
docker build -t myimage:${{ github.sha }} -f ./src/Services/Flight/Dockerfile .
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to DockerHub
|
||||||
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
|
|
||||||
- name: Push to Docker Hub
|
- name: Login to Github Packages
|
||||||
run: docker push myimage:${{ github.sha }}
|
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 }}
|
||||||
|
|||||||
16
.github/workflows/dotnet.yml
vendored
16
.github/workflows/dotnet.yml
vendored
@ -2,7 +2,7 @@ name: Build-Test
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" , "develop"]
|
branches: [ "main" , "develop" ]
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- "README.md"
|
- "README.md"
|
||||||
pull_request:
|
pull_request:
|
||||||
@ -19,10 +19,24 @@ jobs:
|
|||||||
uses: actions/setup-dotnet@v2
|
uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: 7.0.x
|
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
|
- name: Restore dependencies
|
||||||
run: dotnet restore
|
run: dotnet restore
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: dotnet build -c Release --no-restore
|
run: dotnet build -c Release --no-restore
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: dotnet test -c Release --no-restore
|
run: dotnet test -c Release --no-restore
|
||||||
|
|
||||||
|
|||||||
@ -12,9 +12,17 @@ using Exception = System.Exception;
|
|||||||
|
|
||||||
public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
||||||
{
|
{
|
||||||
|
private readonly Lazy<ILogger<PersistMessageDbContext>> _logger;
|
||||||
|
|
||||||
public PersistMessageDbContext(DbContextOptions<PersistMessageDbContext> options)
|
public PersistMessageDbContext(DbContextOptions<PersistMessageDbContext> options)
|
||||||
: base(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>();
|
public DbSet<PersistMessage> PersistMessages => Set<PersistMessage>();
|
||||||
@ -37,10 +45,7 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
|||||||
{
|
{
|
||||||
if (exception != null)
|
if (exception != null)
|
||||||
{
|
{
|
||||||
var factory = LoggerFactory.Create(b => b.AddConsole());
|
_logger.Value.LogError(exception,
|
||||||
var logger = factory.CreateLogger<PersistMessageDbContext>();
|
|
||||||
|
|
||||||
logger.LogError(exception,
|
|
||||||
"Request failed with {StatusCode}. Waiting {TimeSpan} before next retry. Retry attempt {RetryCount}.",
|
"Request failed with {StatusCode}. Waiting {TimeSpan} before next retry. Retry attempt {RetryCount}.",
|
||||||
HttpStatusCode.Conflict,
|
HttpStatusCode.Conflict,
|
||||||
timeSpan,
|
timeSpan,
|
||||||
@ -55,12 +60,22 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
|||||||
{
|
{
|
||||||
foreach (var entry in ex.Entries)
|
foreach (var entry in ex.Entries)
|
||||||
{
|
{
|
||||||
var currentEntity = entry.Entity; // we can use it for specific merging
|
var currentValue = entry.Entity; // we can use it for specific merging
|
||||||
var databaseValues = await entry.GetDatabaseValuesAsync(cancellationToken);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user