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
112 changes: 112 additions & 0 deletions .github/workflows/inventory-service-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Inventory Service CI/CD

on:
push:
branches: [main]
paths:
- 'src/Services/Product/**'
- 'src/Shared/**'
- 'deploy/helm/inventory-service/**'
pull_request:
branches: [main]
paths:
- 'src/Services/Product/**'
- 'src/Shared/**'
- 'deploy/helm/inventory-service/**'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/inventory-service

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore src/Services/Product/Product.API/Product.API.csproj

- name: Build
run: dotnet build src/Services/Product/Product.API/Product.API.csproj --no-restore --configuration Release

- name: Test
run: |
if [ -d "src/Services/Product/Product.Tests" ]; then
dotnet test src/Services/Product/Product.Tests --no-build --configuration Release
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 CI test step uses --no-build but the test project was never built

The test step at line 41 runs dotnet test src/Services/Product/Product.Tests --no-build --configuration Release. The --no-build flag requires the project to already be compiled, but the preceding build step (line 36) only builds Product.API.csproj, not the test project. If the test directory exists, dotnet test will fail because no compiled test assemblies are found. Either remove --no-build or add a build step for the test project.

Suggested change
dotnet test src/Services/Product/Product.Tests --no-build --configuration Release
dotnet test src/Services/Product/Product.Tests --configuration Release
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

else
echo "No test project found, skipping tests"
fi

docker:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./src
file: ./src/Services/Product/Product.API/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

helm-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.13.0

- name: Lint Helm chart
run: helm lint deploy/helm/inventory-service

deploy-dev:
runs-on: ubuntu-latest
needs: [build, docker]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment: dev
steps:
- uses: actions/checkout@v4

- name: Deploy to dev
run: |
echo "Triggering ArgoCD sync for inventory-service-dev"
# ArgoCD CLI sync would go here
# argocd app sync inventory-service-dev --server $ARGOCD_SERVER

deploy-staging:
runs-on: ubuntu-latest
needs: [build, docker, deploy-dev]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment: staging
steps:
- uses: actions/checkout@v4

- name: Deploy to staging
run: |
echo "Triggering ArgoCD sync for inventory-service-staging"
# ArgoCD CLI sync would go here
# argocd app sync inventory-service-staging --server $ARGOCD_SERVER
23 changes: 23 additions & 0 deletions deploy/argocd/dev/inventory-service-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: inventory-service-dev
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/Cognition-Partner-Workshops/app_dotnet_angular_containerized_decomposition_microservices
targetRevision: main
path: deploy/helm/inventory-service
helm:
valueFiles:
- values-dev.yaml
destination:
server: https://kubernetes.default.svc
namespace: dev
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
20 changes: 20 additions & 0 deletions deploy/argocd/staging/inventory-service-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: inventory-service-staging
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/Cognition-Partner-Workshops/app_dotnet_angular_containerized_decomposition_microservices
targetRevision: main
path: deploy/helm/inventory-service
helm:
valueFiles:
- values-staging.yaml
destination:
server: https://kubernetes.default.svc
namespace: staging
syncPolicy:
syncOptions:
- CreateNamespace=true
6 changes: 6 additions & 0 deletions deploy/helm/inventory-service/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: inventory-service
description: Helm chart for the Inventory (Product) microservice
type: application
version: 0.1.0
appVersion: "1.0.0"
10 changes: 10 additions & 0 deletions deploy/helm/inventory-service/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "inventory-service.fullname" . }}-config
labels:
app: {{ include "inventory-service.name" . }}
data:
ASPNETCORE_ENVIRONMENT: {{ .Values.env.ASPNETCORE_ENVIRONMENT | quote }}
ASPNETCORE_URLS: {{ .Values.env.ASPNETCORE_URLS | quote }}
Logging__LogLevel__Default: {{ .Values.logging.level | quote }}
59 changes: 59 additions & 0 deletions deploy/helm/inventory-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "inventory-service.fullname" . }}
labels:
app: {{ include "inventory-service.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
app: {{ include "inventory-service.name" . }}
template:
metadata:
labels:
app: {{ include "inventory-service.name" . }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
envFrom:
- configMapRef:
name: {{ include "inventory-service.fullname" . }}-config
- secretRef:
name: {{ include "inventory-service.fullname" . }}-secret
livenessProbe:
httpGet:
path: /healthz
port: http
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
port: http
initialDelaySeconds: 5
periodSeconds: 10
resources:
{{- toYaml .Values.resources | nindent 12 }}

{{- define "inventory-service.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "inventory-service.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s" $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
22 changes: 22 additions & 0 deletions deploy/helm/inventory-service/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "inventory-service.fullname" . }}
labels:
app: {{ include "inventory-service.name" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "inventory-service.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
44 changes: 44 additions & 0 deletions deploy/helm/inventory-service/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if .Values.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "inventory-service.fullname" . }}
labels:
app: {{ include "inventory-service.name" . }}
spec:
podSelector:
matchLabels:
app: {{ include "inventory-service.name" . }}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: api-gateway
ports:
- protocol: TCP
port: {{ .Values.service.port }}
egress:
- to:
- podSelector:
matchLabels:
app: postgresql
ports:
- protocol: TCP
port: {{ .Values.postgresql.port }}
- to:
- podSelector:
matchLabels:
app: rabbitmq
ports:
- protocol: TCP
port: {{ .Values.rabbitmq.port }}
- to: []
ports:
- protocol: TCP
port: 53
- protocol: UDP
port: 53
{{- end }}
9 changes: 9 additions & 0 deletions deploy/helm/inventory-service/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "inventory-service.fullname" . }}-secret
labels:
app: {{ include "inventory-service.name" . }}
type: Opaque
data:
ConnectionStrings__DefaultConnection: {{ printf "Host=%s;Port=%s;Database=%s;Username=%s;Password=changeme" .Values.postgresql.host (toString .Values.postgresql.port) .Values.postgresql.database .Values.postgresql.username | b64enc | quote }}
15 changes: 15 additions & 0 deletions deploy/helm/inventory-service/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "inventory-service.fullname" . }}
labels:
app: {{ include "inventory-service.name" . }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app: {{ include "inventory-service.name" . }}
16 changes: 16 additions & 0 deletions deploy/helm/inventory-service/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "inventory-service.fullname" . }}
labels:
app: {{ include "inventory-service.name" . }}
spec:
selector:
matchLabels:
app: {{ include "inventory-service.name" . }}
endpoints:
- port: http
path: {{ .Values.serviceMonitor.path }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
22 changes: 22 additions & 0 deletions deploy/helm/inventory-service/values-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
replicaCount: 1

image:
tag: "latest"

env:
ASPNETCORE_ENVIRONMENT: Development
ASPNETCORE_URLS: "http://+:5004"

logging:
level: Debug

autoscaling:
enabled: false

resources:
limits:
cpu: 250m
memory: 256Mi
requests:
cpu: 50m
memory: 64Mi
25 changes: 25 additions & 0 deletions deploy/helm/inventory-service/values-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
replicaCount: 2

image:
tag: "latest"

env:
ASPNETCORE_ENVIRONMENT: Staging
ASPNETCORE_URLS: "http://+:5004"

logging:
level: Information

autoscaling:
enabled: true
minReplicas: 2
maxReplicas: 5
targetCPUUtilizationPercentage: 70

resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 128Mi
Loading
Loading