Update home.js #208
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: Deploy to Google Cloud VM | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- 'ReadMe.md' | |
- 'epoch_tests_results/**' | |
- 'epoch_tests_results/*' | |
- 'epoch_tests_results/' | |
- 'epoch_tests_results' | |
- 'epoch_project_documents/**' | |
- 'epoch_project_documents/*' | |
- 'epoch_project_documents/' | |
- 'epoch_project_documents' | |
jobs: | |
security-scan: | |
permissions: write-all | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: SonarCloud Scan | |
uses: sonarsource/sonarcloud-github-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
with: | |
args: | |
-Dsonar.projectKey=Aymanhki_Epoch | |
-Dsonar.organization=aymanhki | |
local-test-new-build: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
needs: security-scan | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Install SSH Client and sshpass | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y openssh-client sshpass | |
- name: SSH into Google Cloud VM for testing | |
run: | | |
set -e | |
sshpass -p ${{ secrets.TESTER_SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.TESTER_SSH_USERNAME }} << EOF | |
echo "Current directory path: $(pwd)" | |
cd | |
rm -rf Epoch | |
git clone https://github.com/Aymanhki/Epoch.git | |
cd | |
cp credentials/db_params.json Epoch/epoch_backend/assets/ | |
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_backend/assets/ | |
cp credentials/fullchain.pem Epoch/epoch_backend/assets/ | |
cp credentials/privkey.pem Epoch/epoch_backend/assets/ | |
cp credentials/db_params.json Epoch/epoch_frontend/ | |
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_frontend/ | |
cp credentials/fullchain.pem Epoch/epoch_frontend/ | |
cp credentials/privkey.pem Epoch/epoch_frontend/ | |
cd Epoch/epoch_frontend/ | |
npm install | |
cd .. | |
pkill selenium | |
pkill chromedriver | |
pkill geckodriver | |
pkill firefox | |
export CI=true | |
if ! pytest --cov=epoch_backend -rA --color=yes --disable-warnings --disable-pytest-warnings --show-capture=no ./epoch_backend/tests/integration_tests.py ./epoch_backend/tests/webserver_tests.py ./epoch_backend/tests/following_unit_tests.py; then | |
echo "Webserver Backend Test(s) failed. Exiting with status 1." | |
exit 1 | |
fi | |
sudo fuser -k -n tcp 443 | |
sudo fuser -k -n tcp 8080 | |
sudo fuser -k -n tcp 80 | |
sudo fuser -k -n tcp 8000 | |
lsof -t -i:8080 | xargs kill -9 | |
lsof -t -i:80 | xargs kill -9 | |
lsof -t -i:443 | xargs kill -9 | |
lsof -t -i:8000 | xargs kill -9 | |
cd epoch_frontend/ | |
if ! npm test; then | |
echo "Frontend server Test(s) failed. Exiting with status 1." | |
exit 1 | |
fi | |
exit 0 | |
EOF | |
clean-old-build: | |
needs: local-test-new-build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Install SSH Client and sshpass | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y openssh-client sshpass | |
- name: SSH into Google Cloud VM for cleanup | |
run: | | |
sshpass -p ${{ secrets.SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }} << EOF | |
echo "Current directory path: $(pwd)" | |
cd | |
rm -rf Epoch | |
sudo fuser -k -n tcp 443 | |
sudo fuser -k -n tcp 8080 | |
sudo fuser -k -n tcp 80 | |
sudo fuser -k -n tcp 8000 | |
docker stop \$(docker ps -q) | |
docker rm \$(docker ps -aq) | |
docker rmi \$(docker images -q) | |
git clone https://github.com/Aymanhki/Epoch.git | |
cd | |
cp credentials/db_params.json Epoch/epoch_backend/assets/ | |
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_backend/assets/ | |
cp credentials/fullchain.pem Epoch/epoch_backend/assets/ | |
cp credentials/privkey.pem Epoch/epoch_backend/assets/ | |
cp credentials/db_params.json Epoch/epoch_frontend/assets/ | |
cp credentials/virtual-bonito-412515-d7dae3104a12.json Epoch/epoch_frontend/assets/ | |
cp credentials/fullchain.pem Epoch/epoch_frontend/ | |
cp credentials/privkey.pem Epoch/epoch_frontend/ | |
cd | |
cp credentials/get_version.sh Epoch/epoch_backend/ | |
cp credentials/get_version.sh Epoch/epoch_frontend/ | |
exit | |
EOF | |
deploy-new-build: | |
permissions: write-all | |
needs: clean-old-build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Install SSH Client and sshpass | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y openssh-client sshpass | |
- name: Get Docker Version for Backend | |
id: get_version_backend | |
run: | | |
version="v2.0.9" | |
latest_tag=$(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_frontend/tags/?page_size=1" | jq -r '.results[0].name') | |
if [ -z "$latest_tag" ]; then | |
version="v2.0.9" | |
elif [ "$latest_tag" == "latest" ]; then | |
version="v2.0.9" | |
else | |
major=$(echo "$latest_tag" | awk -F '.' '{print $1}') | |
minor=$(echo "$latest_tag" | awk -F '.' '{print $2}') | |
patch=$(echo "$latest_tag" | awk -F '.' '{print $3}') | |
major=$(echo $major | sed 's/v//') | |
new_patch=0 | |
new_minor=0 | |
new_major=0 | |
if [ "$patch" -lt 9 ]; then | |
new_patch=$((patch+1)) | |
version="v$major.$minor.$new_patch" | |
else | |
new_patch=0 | |
if [ "$minor" -lt 9 ]; then | |
new_minor=$((minor+1)) | |
version="v$major.$new_minor.$new_patch" | |
else | |
new_minor=0 | |
new_major=$((major+1)) | |
version="v$new_major.$new_minor.$new_patch" | |
fi | |
fi | |
fi | |
echo "::set-output name=version::$version" | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
- name: Get Docker Version for Frontend | |
id: get_version_frontend | |
run: | | |
version="v2.0.9" | |
latest_tag=$(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_frontend/tags/?page_size=1" | jq -r '.results[0].name') | |
if [ -z "$latest_tag" ]; then | |
version="v2.0.9" | |
elif [ "$latest_tag" == "latest" ]; then | |
version="v2.0.9" | |
else | |
major=$(echo "$latest_tag" | awk -F '.' '{print $1}') | |
minor=$(echo "$latest_tag" | awk -F '.' '{print $2}') | |
patch=$(echo "$latest_tag" | awk -F '.' '{print $3}') | |
major=$(echo $major | sed 's/v//') | |
new_patch=0 | |
new_minor=0 | |
new_major=0 | |
if [ "$patch" -lt 9 ]; then | |
new_patch=$((patch+1)) | |
version="v$major.$minor.$new_patch" | |
else | |
new_patch=0 | |
if [ "$minor" -lt 9 ]; then | |
new_minor=$((minor+1)) | |
version="v$major.$new_minor.$new_patch" | |
else | |
new_minor=0 | |
new_major=$((major+1)) | |
version="v$new_major.$new_minor.$new_patch" | |
fi | |
fi | |
fi | |
echo "::set-output name=version::$version" | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
- name: Is This Major Version | |
id: is_major | |
run: | | |
major=$(echo "${{ steps.get_version_frontend.outputs.version }}" | awk -F '.' '{print $1}') | |
minor=$(echo "${{ steps.get_version_frontend.outputs.version }}" | awk -F '.' '{print $2}') | |
patch=$(echo "${{ steps.get_version_frontend.outputs.version }}" | awk -F '.' '{print $3}') | |
major=$(echo $major | sed 's/v//') | |
if [ "$patch" -eq 0 ] && [ "$minor" -eq 0 ]; then | |
echo "This is a major version" | |
echo "::set-output name=is_major::true" | |
else | |
echo "This is not a major version" | |
echo "::set-output name=is_major::false" | |
fi | |
- name: Create Release | |
if: always() | |
uses: actions/create-release@v1 | |
id: create_release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.get_version_backend.outputs.version }} | |
release_name: ${{ steps.get_version_backend.outputs.version }} | |
- name: Deploying Backend (Build and Run Backend Docker Container) | |
run: | | |
sshpass -p ${{ secrets.SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }} << EOF | |
echo "Current directory path: $(pwd)" | |
cd | |
cd Epoch/epoch_backend/ | |
echo "Version for backend Docker image: $VERSION" | |
docker build -t epoch_backend:$VERSION ./ | |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
docker tag epoch_backend:$VERSION $DOCKER_USERNAME/epoch_backend:$VERSION | |
docker push $DOCKER_USERNAME/epoch_backend:$VERSION | |
docker run -d -p 8080:8080 epoch_backend:$VERSION | |
exit | |
EOF | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
VERSION: ${{ steps.get_version_backend.outputs.version }} | |
if: success() | |
- name: Deploying Frontend (Build and Run Frontend Docker Container) | |
run: | | |
sshpass -p ${{ secrets.SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }} << EOF | |
echo "Current directory path: $(pwd)" | |
cd | |
cd Epoch/epoch_frontend/ | |
echo "Version for backend Docker image: $VERSION" | |
docker build -t epoch_frontend:$VERSION ./ | |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
docker tag epoch_frontend:$VERSION $DOCKER_USERNAME/epoch_frontend:$VERSION | |
docker push $DOCKER_USERNAME/epoch_frontend:$VERSION | |
docker run -d -p 443:443 epoch_frontend:$VERSION | |
exit | |
EOF | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
VERSION: ${{ steps.get_version_frontend.outputs.version }} | |
if: success() | |
server-test-new-build: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
needs: deploy-new-build | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Install SSH Client and sshpass | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y openssh-client sshpass | |
- name: SSH into Google Cloud VM for testing | |
run: | | |
set -e | |
sshpass -p ${{ secrets.TESTER_SSH_PASSWORD }} ssh -t -o StrictHostKeyChecking=no ${{ secrets.TESTER_SSH_USERNAME }} << EOF | |
echo "Current directory path: $(pwd)" | |
cd | |
rm -rf epoch_tests_results | |
mkdir epoch_tests_results | |
jmeter -n -t EpochLoadTestPlan.jmx -l ./epoch_tests_results/test_results_$(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_frontend/tags/?page_size=1" | jq -r '.results[0].name')_$(date +%Y-%m-%d_%H-%M-%S).csv | |
cd Epoch/ | |
rm -rf epoch_tests_results | |
cd .. | |
mv epoch_tests_results Epoch/ | |
cd Epoch/ | |
git add epoch_tests_results | |
git commit -m "Load Test results for $(curl -s "https://registry.hub.docker.com/v2/repositories/$DOCKER_USERNAME/epoch_backend/tags/?page_size=1" | jq -r '.results[0].name')_$(date +%Y-%m-%d_%H-%M-%S).csv" | |
git config --global user.email $EMAIL | |
git config --global user.name $NAME | |
git push https://$NAME:${{ secrets.GIT_PAT }}@github.com/$NAME/Epoch | |
exit | |
EOF | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
GIT_PAT: ${{ secrets.GIT_PAT }} | |
EMAIL: ${{ secrets.EMAIL }} | |
NAME: ${{ secrets.NAME }} | |