Skip to content

Merge pull request #205 from Funssion-SWM/recovery-shell #12

Merge pull request #205 from Funssion-SWM/recovery-shell

Merge pull request #205 from Funssion-SWM/recovery-shell #12

Workflow file for this run

name: Java CI/CD with Gradle In Temp EC2
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Add properties
run: echo "${{ secrets.APPLICATION_PROD_TEMP }}" > ./src/main/resources/application.yml
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.5.1
arguments: build -x test
- name: Docker build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_REPO }} .
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_REPO }}
- name: Deploy to dev & Add recovery shell script when reboot
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ec2-user
key: ${{ secrets.NEW_PRIVATE_KEY }}
script: |
sudo bash -c 'cat << EOF > /var/lib/cloud/scripts/per-boot/recover.sh
#!/bin/bash
docker restart nginx
docker restart frontend
docker restart backend
EOF'
sudo bash -c 'chmod +x /var/lib/cloud/scripts/per-boot/recover.sh'
docker stop backend
docker rm backend
docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_REPO }}
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_REPO }}
docker run -dp 8080:8080 --name=backend ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_REPO }}