Merge pull request #10 from SM-LCK/feature/history #48
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: Java CD with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
# pull_request: | |
# branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest # ubuntu 최신 버전에서 script를 실행 | |
steps: | |
# 지정한 저장소(현재 REPO)에서 코드를 워크플로우 환경으로 가져오도록 하는 github action | |
- uses: actions/checkout@v3 | |
# open jdk 17 버전 환경을 세팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: "adopt" | |
- uses: actions/checkout@v3 | |
- run: | | |
mkdir -p ./src/main/resources | |
touch ./src/main/resources/application.properties | |
echo "${{ secrets.PROPERTIES }}" > ./src/main/resources/application.properties | |
cat ./src/main/resources/application.properties | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
# gradle을 통해 소스를 빌드 | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Docker build & push to docker repo | |
run: | | |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PWD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} . | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | |
# appleboy/ssh-action@master 액션을 사용해 배포할 서버에 ssh로 접속하고 script를 실행 | |
# script의 내용: 서버의 기존 도커 컨테이너와 이미지들을 제거하고 | |
# docker repo로부터 방금 위에서 push한 내용을 pull 받아 | |
# docker-compose를 사용해 실행 | |
- name: Deploy to server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | |
sudo docker-compose -f "docker-compose.yml" up -d --build | |