π [FIX] μκ° μλ¬ ν΄κ²° #203
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: CD with Gradle | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: | |
- closed | |
permissions: | |
contents: read | |
jobs: | |
handle-events: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
# pull_requestκ° λ«ν κ²½μ°μλ§ μ€ν | |
- name: Handle Pull Request Closed | |
if: github.event_name == 'pull_request' && github.event.action == 'closed' | |
run: echo "Pull request closed! Handling pull_request event." | |
# push μ΄λ²€νΈμΈ κ²½μ°μλ§ μ€ν | |
- name: Handle Push Event | |
if: github.event_name == 'push' | |
run: echo "Code pushed to main! Handling push event." | |
# jdk 17 λ²μ νκ²½μ μΈν | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: "adopt" | |
# κΉμ μλ application.yml νμΌ μμ± | |
- name: Make application.yml | |
run: | | |
cd ./src/main | |
mkdir resources | |
cd resources | |
touch ./application.yml | |
echo "${{ secrets.YML }}" > ./application.yml | |
shell: bash | |
# μμ€ λΉλ | |
- name: Build with Gradle | |
run: | | |
chmod +x ./gradlew | |
./gradlew clean build -x test | |
# dockerfileμ ν΅ν΄ μ΄λ―Έμ§λ₯Ό λΉλνκ³ , μ΄λ₯Ό docker repoλ‘ push | |
- name: Docker build & push to docker repo | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/carely . | |
docker push ${{ secrets.DOCKER_REPO }}/carely | |
# κΈ°μ‘΄μ μ€νλλ 컨ν μ΄λ λͺ¨λ λ©μΆ€ | |
# μλ²μ μ μνμ¬ pull ν ν μ€ν | |
# docker-compposeμ μμ±ν΄λ 컨ν μ΄λ λ°±κ·ΈλΌμ΄λλ‘ μ€ν | |
- name: Deploy to server | |
uses: appleboy/ssh-action@master | |
id: deploy | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker stop $(docker ps -a -q) | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/carely | |
sudo docker-compose up --build -d | |
sudo docker image prune -f |