Merge pull request #2 from KUSITMS-DEVOCEAN/fix/getProject #2
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
# github repository Actions 페이지에 나타낼 이름.. | |
name: devocean A CI/CD with Gradle | |
# event trigger | |
# main, develop 브랜치에 push 시실행되는 트리거 | |
on: | |
# 푸시했을 때 ci/cd | |
push: | |
branches: [ "main", "develop" ] | |
# permissions: write-all | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
## jdk setting | |
- uses: actions/checkout@v3 | |
- name: 🐧Set up JDK 17 | |
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- | |
- name: 🐧application.yml 파일을 생성 합니다. | |
run: | | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.PROPERTIES }}" > ./application.yml | |
shell: bash | |
- name: 🐧gradle build를 위한 권한을 부여합니다. | |
run: chmod +x gradlew | |
- name: 🐧gradle build 중입니다. | |
run: ./gradlew build | |
shell: bash # ci는 여기까지 | |
- name: 🐧docker image build 후 docker hub에 push합니다. | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} . | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} | |
## deploy to production | |
- name: docker hub에서 pull 후 deploy합니다. | |
uses: appleboy/ssh-action@master | |
with: | |
username: ${{ secrets.EC2_USERNAME }} | |
host: ${{ secrets.EC2_HOST }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}:latest | |
sudo docker stop $(sudo docker ps -q) 2>/dev/null || true | |
sudo docker run --rm -d --network='host' -p 80:8080 --name ${{ secrets.DOCKER_IMAGE }} \ | |
-e RDB_HOST=${{ secrets.RDB_HOST }} \ | |
-e RDB_PORT=${{ secrets.RDB_PORT }} \ | |
-e RDB_SCHEMA=${{ secrets.RDB_SCHEMA }} \ | |
-e RDB_USER=${{ secrets.RDB_USER }} \ | |
-e RDB_PASSWORD=${{ secrets.RDB_PASSWORD }} \ | |
${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}:latest | |
sudo docker system prune -f |