mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-02 19:02:55 +08:00
ci: Add docker to ci
This commit is contained in:
parent
46202f153e
commit
8b2a951bd9
44
.github/workflows/build-publish-docker.yml
vendored
44
.github/workflows/build-publish-docker.yml
vendored
@ -1,44 +0,0 @@
|
|||||||
name: build-publish-docker
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ develop ]
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build-and-push-docker-image:
|
|
||||||
name: Build and Publish Docker image to DockerHub
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
-
|
|
||||||
- uses: salsify/action-detect-and-tag-new-version@v2
|
|
||||||
|
|
||||||
- name: Versions Outputs
|
|
||||||
run: |
|
|
||||||
echo v{VERSION}
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Build image
|
|
||||||
run: |
|
|
||||||
docker build -t meysamh66/booking-microservices-flight:latest -f "${{ github.workspace }}/src/Services/Flight/Dockerfile" .
|
|
||||||
# docker build -t meysamh66/booking-microservices-identity:latest -f "${{ github.workspace }}/src/Services/Identity/Dockerfile" .
|
|
||||||
# docker build -t meysamh66/booking-microservices-passenger:latest -f "${{ github.workspace }}/src/Services/Passenger/Dockerfile" .
|
|
||||||
# docker build -t meysamh66/booking-microservices-booking:latest -f "${{ github.workspace }}/src/Services/Booking/Dockerfile" .
|
|
||||||
|
|
||||||
- name: Publish image
|
|
||||||
run: |
|
|
||||||
docker push meysamh66/booking-microservices-flight:latest
|
|
||||||
# docker push meysamh66/booking-microservices-identity:latest
|
|
||||||
# docker push meysamh66/booking-microservices-passenger:latest
|
|
||||||
# docker push meysamh66/booking-microservices-booking:latest
|
|
||||||
|
|
||||||
70
.github/workflows/ci.yml
vendored
Normal file
70
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" , "develop" ]
|
||||||
|
paths-ignore:
|
||||||
|
- "README.md"
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" , "develop" ]
|
||||||
|
paths-ignore:
|
||||||
|
- "README.md"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup .NET
|
||||||
|
uses: actions/setup-dotnet@v2
|
||||||
|
with:
|
||||||
|
dotnet-version: 7.0.x
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- name: Update Release Drafter
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
id: last_release
|
||||||
|
uses: release-drafter/release-drafter@v5
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
|
|
||||||
|
##ref: https://docs.docker.com/language/golang/configure-ci-cd/
|
||||||
|
##ref: https://event-driven.io/en/how_to_buid_and_push_docker_image_with_github_actions
|
||||||
|
- name: Build Docker Image
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
run: |
|
||||||
|
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-flight:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Flight/Dockerfile" .
|
||||||
|
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-identity:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Identity/Dockerfile" .
|
||||||
|
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-passenger:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Passenger/Dockerfile" .
|
||||||
|
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-booking:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Booking/Dockerfile" .
|
||||||
|
|
||||||
|
- name: Publish Docker Image
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
run: |
|
||||||
|
docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-flight:${{ steps.last_release.outputs.tag_name }}
|
||||||
|
docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-identity:${{ steps.last_release.outputs.tag_name }}
|
||||||
|
docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-passenger:${{ steps.last_release.outputs.tag_name }}
|
||||||
|
docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-booking:${{ steps.last_release.outputs.tag_name }}
|
||||||
|
|
||||||
42
.github/workflows/dotnet.yml
vendored
42
.github/workflows/dotnet.yml
vendored
@ -1,42 +0,0 @@
|
|||||||
name: Build-Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "main" , "develop" ]
|
|
||||||
paths-ignore:
|
|
||||||
- "README.md"
|
|
||||||
pull_request:
|
|
||||||
branches: [ "main" , "develop" ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- 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
|
|
||||||
|
|
||||||
18
.github/workflows/release-drafter.yml
vendored
18
.github/workflows/release-drafter.yml
vendored
@ -1,18 +0,0 @@
|
|||||||
# https://johanneskonings.dev/github/2021/02/28/github_automatic_releases_and-changelog/
|
|
||||||
# https://tiagomichaelsousa.dev/articles/stop-writing-your-changelogs-manually
|
|
||||||
name: Release Drafter
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
jobs:
|
|
||||||
update_release_draft:
|
|
||||||
name: Release drafter
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Update Release Draft
|
|
||||||
uses: release-drafter/release-drafter@v5
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@ -11,6 +11,6 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<PersistMes
|
|||||||
|
|
||||||
builder.UseNpgsql("Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true")
|
builder.UseNpgsql("Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true")
|
||||||
.UseSnakeCaseNamingConvention();
|
.UseSnakeCaseNamingConvention();
|
||||||
return new PersistMessageDbContext(builder.Options);
|
return new PersistMessageDbContext(builder.Options, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,17 +12,13 @@ using Exception = System.Exception;
|
|||||||
|
|
||||||
public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
||||||
{
|
{
|
||||||
private readonly Lazy<ILogger<PersistMessageDbContext>> _logger;
|
private readonly ILogger<PersistMessageDbContext> _logger;
|
||||||
|
|
||||||
public PersistMessageDbContext(DbContextOptions<PersistMessageDbContext> options)
|
public PersistMessageDbContext(DbContextOptions<PersistMessageDbContext> options,
|
||||||
|
ILogger<PersistMessageDbContext> logger)
|
||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
_logger = new Lazy<ILogger<PersistMessageDbContext>>(() =>
|
_logger = logger;
|
||||||
{
|
|
||||||
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>();
|
||||||
@ -45,7 +41,7 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
|||||||
{
|
{
|
||||||
if (exception != null)
|
if (exception != null)
|
||||||
{
|
{
|
||||||
_logger.Value.LogError(exception,
|
_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,
|
||||||
@ -63,7 +59,7 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
|||||||
var currentValue = entry.Entity; // we can use it for specific merging
|
var currentValue = entry.Entity; // we can use it for specific merging
|
||||||
var databaseValue = await entry.GetDatabaseValuesAsync(cancellationToken);
|
var databaseValue = await entry.GetDatabaseValuesAsync(cancellationToken);
|
||||||
|
|
||||||
_logger.Value.LogInformation(
|
_logger.LogInformation(
|
||||||
"Entry to entity with type: {Type}, database-value: {DatabaseValue} and current-value: {CurrentValue}",
|
"Entry to entity with type: {Type}, database-value: {DatabaseValue} and current-value: {CurrentValue}",
|
||||||
entry.GetType().Name,
|
entry.GetType().Name,
|
||||||
databaseValue,
|
databaseValue,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user