Skip to content

Commit

Permalink
Add deployment & service so the application can be deployed in a clus…
Browse files Browse the repository at this point in the history
…ter inside the pipeline. Fix coverage report upload.
  • Loading branch information
DvDty committed Jan 28, 2024
1 parent f2f963e commit 04158c0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/main-branch-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:

linter:
runs-on: ubuntu-latest
needs: [ security ]
permissions:
contents: write
steps:
Expand Down Expand Up @@ -64,6 +65,7 @@ jobs:

tests:
runs-on: ubuntu-latest
needs: [ security ]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -100,6 +102,7 @@ jobs:

static-analysis:
runs-on: ubuntu-latest
needs: [ security ]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -129,6 +132,7 @@ jobs:

SonarCloud:
runs-on: ubuntu-latest
needs: [ security ]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -141,6 +145,7 @@ jobs:

database:
runs-on: ubuntu-latest
needs: [ security ]
services:
mysql-service:
image: mysql:8
Expand Down Expand Up @@ -188,16 +193,11 @@ jobs:
DB_PORT: ${{ job.services.mysql-service.ports[3306]}}
DB_HOST: 127.0.0.1

- name: Get test coverage
- name: Get test coverage and store it
id: coverage
working-directory: ./application
run: XDEBUG_MODE=coverage php artisan test --coverage

- name: Store value
working-directory: ./application
run: |
total_percentage=$(echo "$output" | grep -oP 'Total: \K\d+\.\d+')
total_percentage > code_coverage.txt
XDEBUG_MODE=coverage php artisan test --coverage | grep -oP 'Total: \K\d+\.\d+' > code_coverage.txt
- name: Commit code_coverage.txt
id: auto-commit-action
Expand Down Expand Up @@ -257,3 +257,24 @@ jobs:
context: "{{defaultContext}}:application"
push: true
tags: dvdty/branch-deploy-application:${{ github.head_ref || github.ref_name }}

- name: Deploy to minikube
uses: medyagh/setup-minikube@master

- name: Deploy to minikube
working-directory: ./application
run:
kubectl apply -f k8s/

- name: Wait for Deployment
run: |
kubectl rollout status deployment branch-deploy-application
- name: Expose Service
run: |
minikube service list
curl $(minikube service branch-deploy-application-service --url)
- name: Stop Minikube
run: |
minikube stop
20 changes: 20 additions & 0 deletions application/k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: branch-deploy-application
spec:
replicas: 2
selector:
matchLabels:
app: branch-deploy-application
template:
metadata:
labels:
app: branch-deploy-application
spec:
containers:
- name: branch-deploy-application
image: dvdty/branch-deploy-application:latest
imagePullPolicy: "Always"
ports:
- containerPort: 80
12 changes: 12 additions & 0 deletions application/k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: branch-deploy-application-service
spec:
selector:
app: branch-deploy-application
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort

0 comments on commit 04158c0

Please sign in to comment.