Skip to content

updating .gitignore #97

updating .gitignore

updating .gitignore #97

name: Build and Test Docker Images
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore ModularMonolith.sln
- name: Build solution
run: dotnet build ModularMonolith.sln --no-restore --configuration Release
- name: Run unit tests
run: |
dotnet test ECommerce.Modules.Orders.Tests/ECommerce.Modules.Orders.Tests.csproj --no-build --configuration Release --logger "trx;LogFileName=orders_test_results.trx"
dotnet test ECommerce.BusinessEvents.Tests/ECommerce.BusinessEvents.Tests.csproj --no-build --configuration Release --logger "trx;LogFileName=businessevents_test_results.trx"
dotnet test ECommerce.AdminUI.Tests/ECommerce.AdminUI.Tests.csproj --no-build --configuration Release --logger "trx;LogFileName=adminui_unit_test_results.trx"
- name: Run integration tests
run: |
dotnet test ECommerceApp.IntegrationTests/ECommerceApp.IntegrationTests.csproj --no-build --configuration Release --logger "trx;LogFileName=ecommerceapp_integration_test_results.trx"
dotnet test ECommerce.AdminUI.IntegrationTests/ECommerce.AdminUI.IntegrationTests.csproj --no-build --configuration Release --logger "trx;LogFileName=adminui_integration_test_results.trx"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build ECommerceApp Docker image
run: |
if [ -f ./ECommerceApp/Dockerfile ]; then
docker build -t modularmonolith -f ECommerceApp/Dockerfile .
else
echo "ECommerceApp Dockerfile not found, skipping build."
fi
- name: Build ECommerce.AdminUI Docker image
run: |
if [ -f ./ECommerce.AdminUI/Dockerfile ]; then
docker build -t admin-ui -f ECommerce.AdminUI/Dockerfile .
else
echo "ECommerce.AdminUI Dockerfile not found, skipping build."
fi
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.ACCESS_TOKEN }}
- name: Set short SHA
run: echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Tag and push ECommerceApp image
run: |
docker tag modularmonolith ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/modularmonolith:latest
docker tag modularmonolith ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/modularmonolith:${{ env.SHORT_SHA }}
docker push ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/modularmonolith:latest
docker push ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/modularmonolith:${{ env.SHORT_SHA }}
- name: Tag and push ECommerce.AdminUI image
run: |
docker tag admin-ui:latest ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/admin-ui:latest
docker tag admin-ui:latest ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/admin-ui:${{ env.SHORT_SHA }}
docker push ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/admin-ui:latest
docker push ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/admin-ui:${{ env.SHORT_SHA }}
deploy-mock:
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only deploy on main, adjust as needed
steps:
- name: Set short SHA
run: echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Show deployment parameters
env:
IMAGE_TAG: ${{ env.SHORT_SHA }}
ENVIRONMENT: ${{ inputs.environment || 'dev' }}
run: |
echo "Mock Deploying to environment: $ENVIRONMENT"
echo "Using image tag: $IMAGE_TAG"
echo "Would deploy ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/modularmonolith:${IMAGE_TAG}"
echo "Would deploy ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/admin-ui:${IMAGE_TAG}"
- name: Simulate deployment script
run: |
echo "kubectl apply -f k8s/deployment.yaml --dry-run=client"
# Add any commands you want to 'mock' here
- name: Confirm mock deployment success
run: echo "Mock deployment completed successfully."
update-deployment-manifests:
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout infrastructure repository
uses: actions/checkout@v4
with:
repository: ilroberts/DotNetModularMonolith-k8s
token: ${{ secrets.ACCESS_TOKEN }}
path: infra-repo
- name: Set up Git
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
working-directory: infra-repo
- name: Install yq
run: sudo apt-get update && sudo apt-get install -y yq
- name: Set short SHA
run: echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Update ECommerceApp image tag in manifest
run: |
yq -y -i '(.spec.template.spec.containers[] | select(.name == "modularmonolith").image) = "ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/modularmonolith:${{ env.SHORT_SHA }}"' ECommerceApp/k8s/base/deployment.yaml
working-directory: infra-repo
- name: Update AdminUI image tag in manifest
run: |
yq -y -i '(.spec.template.spec.containers[] | select(.name == "admin-ui").image) = "ghcr.io/${{ github.repository_owner }}/dotnetmodularmonolith/admin-ui:${{ env.SHORT_SHA }}"' ECommerce.AdminUI/k8s/base/deployment.yaml
working-directory: infra-repo
- name: Commit and push manifest updates
run: |
git add ECommerceApp/k8s/base/deployment.yaml ECommerce.AdminUI/k8s/base/deployment.yaml
git commit -m "Update ECommerceApp and AdminUI images to ${{ env.SHORT_SHA }} [ci skip]" || echo "No changes to commit"
git push
working-directory: infra-repo