Skip to content

Update prod-eureka-deploy.yml #8

Update prod-eureka-deploy.yml

Update prod-eureka-deploy.yml #8

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Eureka
on:
push:
branches: [ "prod-eureka" ]
pull_request:
branches: [ "prod-eureka" ]
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: 'temurin'
- name: Clean Gradle Cache
run: |
cd BE-Eureka-Server
ls
./gradlew clean
- name: Make application.yml
run: |
mkdir -p src/main/resources
echo "$APPLICATION" > src/main/resources/application.yml
env:
APPLICATION: ${{ secrets.APPLICATION_EUREKA }}
- name: Grant execute permission for gradlew
run: |
cd BE-Eureka-Server
ls
chmod +x gradlew
- name: Build with Gradle
run: |
cd BE-Eureka-Server
ls
./gradlew build -x test
- name: Docker build
run: |
cd BE-Eureka-Server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/eureka:latest
docker push ${{ secrets.DOCKER_USERNAME }}/eureka:latest
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD_2 }}
username: ec2-user
key: ${{ secrets.PRIVATE_KEY_2 }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/eureka:latest
docker stop $(docker ps -a -q)
docker run -d --log-driver=syslog -p 8761:8761 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.DOCKER_USERNAME }}/eureka:latest
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f