added files #136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: frontend-master-workflow | |
on: | |
push: | |
branches: | |
- L00171125_dissertation | |
# pull_request: | |
# types: | |
# - "opened" | |
jobs: | |
ShiftLeft_test: | |
runs-on: ubuntu-latest | |
if: false | |
permissions: | |
actions: write | |
security-events: write | |
steps: | |
- name: Checkout codes | |
uses: actions/checkout@v4 | |
- name: Install Dependencies | |
run: | | |
ls | |
pwd | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master | |
npm install --force --save-dev jest | |
- name: Run Tests | |
run: | | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master | |
npm run test -- --coverage | |
- name: Run Linter | |
run: | | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master | |
npm install eslint --save-dev | |
npx eslint . --fix | |
- name: Run Linter and Generate Report | |
run: | | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master | |
npx eslint . -f json -o eslint-report.json | |
- name: Upload Linting Report | |
uses: actions/upload-artifact@v2 | |
with: | |
name: eslint-report | |
path: /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master/eslint-report.json | |
if-no-files-found: warn | |
- name: Upload Unit Test Coverage Report | |
uses: actions/upload-artifact@v2 | |
with: | |
name: unit-test-coverage | |
path: /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master/coverage/ | |
if-no-files-found: warn | |
# Snyk security scan step for web | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install Snyk CLI | |
run: npm install -g snyk | |
- name: Snyk Security Scans | |
run: snyk test --org=abhi9705 --project-name='L00171125_Dissertationproject' | |
continue-on-error: true | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
working-directory: WWA-backend-master | |
- name: Snyk Monitor | |
run: snyk monitor --project-name='L00171125_Dissertationproject' | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
working-directory: WWA-backend-master | |
- name: Snyk Monitor Frontend | |
run: | | |
npm install --force | |
snyk monitor --org=abhi9705 --project-name='L00171125_Dissertationproject' | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
working-directory: WWA-frontend-master | |
# Snyk security scan step for Code Scanning | |
- name: Run Snyk to check for vulnerabilitie | |
uses: snyk/actions/node@master | |
continue-on-error: true | |
with: | |
args: ./WWA-backend-master --sarif-file-output=snyk.sarif | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
- name: Upload SARIF to GitHub Security Center | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: snyk.sarif | |
category: 'Snyk OpenSource Unique Category' | |
SonarCloudScan: | |
runs-on: ubuntu-latest | |
needs: ShiftLeft_test | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: cd WWA-backend-master && npm install | |
- name: Run Jest tests with coverage | |
run: cd WWA-backend-master && npm test -- --coverage || true | |
# Run tests with coverage, ignoring failures with '|| true' | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '11' | |
distribution: 'adopt' | |
- name: SonarCloud Scan | |
# uses: sonarsource/sonarcloud-github-action@master | |
uses: SonarSource/sonarcloud-github-action@master | |
# uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} | |
with: | |
args: > | |
-Dsonar.organization=abhi9705 | |
-Dsonar.projectKey=Abhi9705_L00171125_Dissertationproject | |
-Dsonar.sources=. | |
-Dsonar.login=${{ secrets.SONARCLOUD_TOKEN }} | |
-Dsonar.javascript.lcov.reportPaths=WWA-backend-master/coverage/lcov.info | |
Build_docker_Images: | |
runs-on: ubuntu-latest | |
# needs: ShiftLeft_test | |
if: false | |
steps: | |
- name: Checkout codes | |
uses: actions/checkout@v4 | |
- name: Sign in to DockerHub | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{secrets.DOCKER_PASSWORD}} | |
- name: Deleting old Images | |
run: | | |
docker rmi -f $(docker image ls -a -q) | |
- name: Docker Frontend Images | |
run: | | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-frontend-master | |
docker build -t wwag3/wednesdaywickedadventures:latest . | |
- name: Build Docker Backend Images | |
run: | | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/WWA-backend-master | |
docker build -t wwag3/wednesdaywickedadvent:backend . | |
- name: Publish Image to docker Hub | |
run: | | |
docker push wwag3/wednesdaywickedadventures:latest | |
docker push wwag3/wednesdaywickedadvent:backend | |
Running_Stagging_Environment: | |
runs-on: self-hosted | |
# needs: Build_docker_Images | |
steps: | |
- name: removing Disk space | |
run: | | |
sudo docker system prune -a -f --volumes | |
- name: Running application on Stagging environment | |
run: | | |
echo "will run when new images is published" | |
# sudo docker pull wwag3/wednesdaywickedadventures:latest | |
- name: Kill and Remove Existing Container | |
run: | | |
if [ "$(sudo docker ps -q -f name=forntend)" ]; then | |
echo "Stopping and removing existing container 'forntend'." | |
sudo docker stop forntend | |
sudo docker rm forntend | |
elif [ "$(sudo docker ps -aq -f name=forntend)" ]; then | |
echo "Removing existing container 'forntend'." | |
sudo docker rm forntend | |
fi | |
echo "Starting new container 'forntend'." | |
sudo docker run -d -p 3000:3000 --name forntend wwag3/wednesdaywickedadventures:latest | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-1 | |
- name: Fetch EC2 Instance Public IP | |
id: ec2_ip | |
run: | | |
INSTANCE_ID=i-0609b0b289067d17d | |
PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].PublicIpAddress' --output text) | |
echo "PUBLIC_IP=$PUBLIC_IP" >> $GITHUB_ENV | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: eu-west-1 | |
- name: Trigger JMeter Tests | |
run: | | |
cd /home/ubuntu/project/.github/workflows | |
gh workflow run Jmeter.yml -f PUBLIC_IP=$PUBLIC_IP | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
Chaos_Engineering: | |
runs-on: ubuntu-latest | |
needs: Running_Stagging_Environment | |
steps: | |
- name: Checkout codes | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-1 | |
- name: Trigger FIS Experiments | |
id: start_fis | |
run: | | |
for i in {1..2}; do | |
echo "Running Chaos Engineering Experiment Iteration #$i" | |
FIS_EXP_ID=$(aws fis start-experiment --experiment-template-id EXTBY5y1A6MqkfjXn --query 'experiment.id' --output text) | |
echo "FIS_EXP_ID=$FIS_EXP_ID" >> $GITHUB_ENV | |
if [ -z "$FIS_EXP_ID" ]; then | |
echo "Failed to start experiment. Exiting." | |
exit 1 | |
fi | |
echo "FIS_EXP_ID=$FIS_EXP_ID" | |
echo "Wait for FIS Experiment to Complete" | |
INSTANCE_ID=i-0609b0b289067d17d | |
INSTANCE_STATUS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].State.Name' --output text) | |
echo "Current instance status: $INSTANCE_STATUS" | |
echo "Start MTTR Scriptss" | |
chmod +x ./measure_mttr.sh | |
./measure_mttr.sh "$FIS_EXP_ID" & | |
while true; do | |
STATUS=$(aws fis get-experiment --id "$FIS_EXP_ID" --query 'experiment.state.status' --output text) | |
if [ -z "$STATUS" ]; then | |
echo "Failed to get experiment status. Exiting." | |
exit 1 | |
fi | |
echo "Current experiment status: $STATUS" | |
INSTANCE_STATUS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].State.Name' --output text) | |
echo "Current instance status: $INSTANCE_STATUS" | |
echo "-----------------------------------------------------------" | |
if [ "$STATUS" == "completed" ]; then | |
break | |
elif [ "$STATUS" == "failed" ] || [ "$STATUS" == "stopped" ]; then | |
echo "Experiment $FIS_EXP_ID did not complete successfully. Status: $STATUS" | |
exit 1 | |
fi | |
sleep 10 | |
done | |
echo "Wait for EC2 Instance to Return to Running" | |
INSTANCE_ID=i-0609b0b289067d17d | |
while true; do | |
INSTANCE_STATUS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].State.Name' --output text) | |
echo "Current instance status: $INSTANCE_STATUS" | |
if [ "$INSTANCE_STATUS" == "running" ]; then | |
echo "Instance $INSTANCE_ID is back to running." | |
break | |
fi | |
sleep 15 | |
done | |
echo "Iteration #$i completed." | |
echo "----------------------------------------------" | |
done | |
Production_Environment: | |
runs-on: ubuntu-latest | |
needs: [Chaos_Engineering] | |
permissions: write-all | |
outputs: | |
target_url: ${{ steps.running-terraform-commands.outputs.target }} | |
steps: | |
- name: Checkout codess | |
uses: actions/checkout@v4 | |
- name: Configure AWS | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}} | |
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}} | |
aws-region: ${{secrets.AWS_REGION}} | |
- name: Setup Terraforms | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: "1.1.7" | |
- name: Running Terraform Commands | |
id: running-terraform-commands | |
working-directory: ./terraform | |
run: | | |
cd /home/runner/work/L00171125_Dissertationproject/L00171125_Dissertationproject/terraform | |
terraform init | |
terraform validate -no-color | |
terraform plan | |
terraform apply -auto-approve | tee terraform_output.txt | |
TARGET_URL=$(terraform output ec2_public_ip) | |
echo "::set-output name=target::$TARGET_URL" | |
echo "EC2 IP Address: $TARGET_URL" # Print EC2 IP in the pipeline | |
echo "##[group]Terraform Output" | |
cat terraform_output.txt | |
echo "##[endgroup]" | |
# terraform destroy -auto-approve | |
# Pulling_docker_image: | |
# runs-on: self-hosted | |
# needs: Build_docker_FrontendImage | |
# steps: | |
# - name: Checkout codess | |
# uses: actions/checkout@v4 | |
#- name: Configure AWS | |
# uses: aws-actions/configure-aws-credentials@v4 | |
#with: | |
# aws-access-key-id: ${{secrets.AWS_ACCESSKEY}} | |
#aws-secret-access-key: ${{secrets.AWS_SECRETEKEY}} | |
# aws-region: ${{secrets.AWS_REGION}} | |
#- name: pulling frontend image from docker hub | |
# run: sudo docker pull wwag3/wednesdaywickedadventures:latest | |
# - name: building backend container | |
# run: sudo docker run --name wwabackendapp -p 5000:5000 -d wwag3/wednesdaywickedadventures:backend | |
# sudo docker system prune --all --force --volumes, docker system prune -a -y | |