File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed
Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change 2828
2929 build-trivy-scan-and-push :
3030 runs-on : ubuntu-latest
31- # needs: sonarq-integration # Uncomment to ensure SonarQube analysis completes before the build
31+ needs : sonarq-integration # Uncomment to ensure SonarQube analysis completes before the build
3232
3333 steps :
3434 - name : Checkout code
@@ -113,3 +113,36 @@ jobs:
113113 with :
114114 name : zap-alerts
115115 path : ./report_html.html
116+ deploy-to-ec2 :
117+ runs-on : ubuntu-latest
118+ needs : build-and-zap-scan
119+ steps :
120+ - name : Checkout code
121+ uses : actions/checkout@v2
122+
123+ - name : Configure SSH for EC2
124+ run : |
125+ echo "${{ secrets.EC2_PRIVATE_KEY }}" > ec2_key.pem
126+ chmod 600 ec2_key.pem
127+ echo "Connecting to EC2 Host: ${{ secrets.K8S_HOST }}"
128+
129+ - name : SSH into EC2 and deploy
130+ run : |
131+ scp -i ec2_key.pem configmap.yaml ubuntu@${{ secrets.K8S_HOST }}:/home/ubuntu/
132+ scp -i ec2_key.pem secret.yaml ubuntu@${{ secrets.K8S_HOST }}:/home/ubuntu/
133+ scp -i ec2_key.pem db-deployment.yaml ubuntu@${{ secrets.K8S_HOST }}:/home/ubuntu/
134+ scp -i ec2_key.pem web-deployment.yaml ubuntu@${{ secrets.K8S_HOST }}:/home/ubuntu/
135+ scp -i ec2_key.pem db-service.yaml ubuntu@${{ secrets.K8S_HOST }}:/home/ubuntu/
136+ scp -i ec2_key.pem web-service.yaml ubuntu@${{ secrets.K8S_HOST }}:/home/ubuntu/
137+ ssh -v -o StrictHostKeyChecking=no -i ec2_key.pem ubuntu@${{ secrets.K8S_HOST }} << EOF
138+ minikube stop
139+ minikube start
140+ kubectl create -f configmap.yaml
141+ kubectl create -f secret.yaml
142+ kubectl create -f db-deployment.yaml
143+ kubectl create -f web-deployment.yaml
144+ kubectl create -f db-service.yaml
145+ kubectl create -f web-service.yaml
146+ sleep 50
147+ kubectl get pods
148+ EOF
You can’t perform that action at this time.
0 commit comments