Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI/CD Pipeline - Docker Build

on:
push:
branches: [ "main" ]
workflow_dispatch:

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: sonu7552/aspnetrun-realworld:latest
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# STAGE 1: Build
# We switched from 'dotnet/core/sdk:3.1' to 'dotnet/sdk:5.0'
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app

# 1. Copy the project files
COPY src/AspnetRun.Core/*.csproj ./src/AspnetRun.Core/
COPY src/AspnetRun.Application/*.csproj ./src/AspnetRun.Application/
COPY src/AspnetRun.Infrastructure/*.csproj ./src/AspnetRun.Infrastructure/
COPY src/AspnetRun.Web/*.csproj ./src/AspnetRun.Web/

# 2. Restore dependencies
RUN dotnet restore src/AspnetRun.Web/AspnetRun.Web.csproj

# 3. Copy the rest of the source code
COPY src/ ./src/

# 4. Build and Publish
WORKDIR /app/src/AspnetRun.Web
RUN dotnet publish -c Release -o /app/publish

# STAGE 2: Runtime
# We switched from 'dotnet/core/aspnet:3.1' to 'dotnet/aspnet:5.0'
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish .
EXPOSE 80
ENTRYPOINT ["dotnet", "AspnetRun.Web.dll"]
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

services:
# 1. THE WEB APPLICATION
aspnetrun-web:
image: aspnetrun-web
build:
context: .
dockerfile: Dockerfile
ports:
# Maps port 80 inside the container to port 8000 on your machine
- "8000:80"
environment:
- ASPNETCORE_ENVIRONMENT=Production
# This overrides the appsettings.json connection string
# 'db' refers to the service name below
- ConnectionStrings__AspnetRunConnection=Server=db;Database=AspnetRunDb;User Id=sa;Password=Password@12345;MultipleActiveResultSets=true
depends_on:
- db

# 2. THE SQL SERVER DATABASE
db:
image: mcr.microsoft.com/mssql/server:2019-latest
environment:
# SQL Server requires a strong password (Capital, lowercase, number, symbol)
- SA_PASSWORD=Password@12345
- ACCEPT_EULA=Y
ports:
- "1433:1433"