Refactor/directory #23
Workflow file for this run
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
## https://zzang9ha.tistory.com/404 참고해서 작성 | |
name: PeerNA CI/CD | |
on: | |
pull_request: | |
branches: [ "main" ] | |
types: [closed] | |
permissions: | |
contents: read | |
jobs: | |
if_merged: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
if: ${{ github.event.pull_request.merged == true }} | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
## gradle caching | |
# - name: Gradle Caching | |
# uses: actions/cache@v3 | |
# with: | |
# path: | | |
# ~/.gradle/caches | |
# ~/.gradle/wrapper | |
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
# restore-keys: | | |
# ${{ runner.os }}-gradle- | |
## create application.yml (현재 private repository 로 yml 파일이 다 올라와 있으므로 일단 생략) | |
# - name: make application.yml | |
# if: contains(github.ref, 'main') | |
# run: | | |
# cd ./src/main/resources | |
# touch ./application.yml | |
# echo "${{ secrets.YML }}" > ./application.yml | |
# shell: bash | |
## create application-oauth.yml | |
# - name: make application-oauth.yml | |
# if: contains(github.ref, 'main') | |
# run: | | |
# cd ./src/main/resources | |
# touch ./application-oauth.yml | |
# echo "${{ secrets.YML_OAUTH }}" > ./application-oauth.yml | |
# shell: bash | |
## gradle build | |
- name: Build with Gradle | |
if: ${{ github.event.pull_request.merged == true }} | |
working-directory: ./ | |
run: ./gradlew build -x test | |
## docker build & push to dockerhub | |
- name: Docker build & push to prod | |
if: ${{ github.event.pull_request.merged == true }} | |
working-directory: ./ | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile -t seunghso/peerna . | |
docker push seunghso/peerna | |
## deploy to production (appleboy 는 ssh 연결을 도와주는 오픈소스 SW 인듯) | |
- name: Deploy to ec2 | |
if: ${{ github.event.pull_request.merged == true }} | |
uses: appleboy/ssh-action@master | |
id: deploy-ec2 | |
with: | |
host: ${{ secrets.HOST_PROD }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
port: 22 | |
script: | | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull seunghso/peerna | |
docker-compose up -d | |
docker image prune -f | |
## deploy to develop (개발 배포가 따로 없으니까 일단 생략) | |
## time | |
# current-time: | |
# needs: build | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Get Current Time | |
# uses: 1466587594/get-current-time@v2 | |
# id: current-time | |
# with: | |
# format: YYYY-MM-DDTHH:mm:ss | |
# utcOffset: "+09:00" # 기준이 UTC이기 때문에 한국시간인 KST를 맞추기 위해 +9시간 추가 | |
# - name: Print Current Time | |
# run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}" # current-time 에서 지정한 포맷대로 현재 시간 출력 | |
# shell: bash | |
## slack 생략 |