๐ Merge pull request #27 from juwon-code/main #101
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 & React CI/CD | |
on: | |
push: | |
branches: [ "main", "release" ] | |
pull_request: | |
branches: [ "main", "release" ] | |
jobs: | |
build: | |
if: github.repository == 'prgrms-be-devcourse/NBB1_2_3_Team10' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# application-prod.properties ์ํธํ | |
- name: add secrets into properties | |
run: | | |
echo "${{ secrets.APPLICATION_PROD }}" | base64 --decode >> ./src/main/resources/application-prod.properties | |
# ํ๊ฒฝ ์ค์ | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 | |
# ์คํ ๊ถํ ๋ถ์ฌ | |
- name: Grant execute permission for Gradlew | |
run: chmod +x gradlew | |
# ํ๋ก์ ํธ ๋น๋ (clean bootJar๋ก ๋น๋๋ง ์ํ) | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build | |
# Docker Hub ๋ก๊ทธ์ธ | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Docker ์ด๋ฏธ์ง ๋น๋ ๋ฐ ํธ์ | |
- name: Build and push Docker image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/bitta-kotlin:latest . | |
docker push ${{ secrets.DOCKER_USERNAME }}/bitta-kotlin:latest | |
deploy: | |
if: github.repository == 'prgrms-be-devcourse/NBB1_2_3_Team10' && github.ref == 'refs/heads/release' | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# EC2 ์๋ฒ ๋ฐฐํฌ | |
- name: Deploy to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
docker pull ${{ secrets.DOCKER_USERNAME }}/bitta-kotlin:latest | |
docker stop my-container || true | |
docker rm my-container || true | |
docker run -d --name my-container -p 80:80 ${{ secrets.DOCKER_USERNAME }}/bitta-kotlin:latest |