Skip to content

Commit

Permalink
chore : Github-Actions 스크립트 작성 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuminzi committed Oct 12, 2023
1 parent 4be7e8c commit 6b7fe5b
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions 4Week_Mission/.github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@


# 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: Java CI with Gradle

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

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: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build -x test

- name: Docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t spring-boot-app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest
docker push ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest
- name: Deploy (remote ssh commands using pwd)
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.PRIVATE_KEY }}
# 도커 작업
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest
docker stop $(docker ps -a -q)
docker run -d --log-driver=syslog -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/spring-boot-app:latest
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f
docker-compose down
docker-compose up

0 comments on commit 6b7fe5b

Please sign in to comment.