Skip to content

Imporve_version_3.02 #45

Imporve_version_3.02

Imporve_version_3.02 #45

Workflow file for this run

name: Build And Deploy
on:
pull_request:
branches:
- main
types:
- closed
jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create secrets
run: |
echo "${{ secrets.SECRET }}" > src/main/resources/secrets.properties
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build with Jib
run: |
source .bashrc
rm src/main/resources/secrets.properties
rm .bashrc
./gradlew jib -Djib.to.image=${{secrets.DOCKER_USERNAME}}/${{secrets.REPOSITORY_NAME}} -Djib.to.tags=${{ github.event.pull_request.number }},latest
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
sudo sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log'
sudo echo "${{ secrets.SECRET }}" > .env
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest
sudo docker stop ${{ secrets.REPOSITORY_NAME }} || true
sudo docker rm ${{ secrets.REPOSITORY_NAME }} || true
sudo docker run -d --name ${{ secrets.REPOSITORY_NAME }} -p 8080:8080 --env-file .env ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest