-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CI/CD 파이프라인 구축
- Loading branch information
Showing
2 changed files
with
31 additions
and
60 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,9 @@ name: CI/CD | |
# event trigger | ||
on: | ||
push: | ||
branches: | ||
- "master" # master 브랜치일 때 배포 수행 | ||
- "develop" # develop 브랜치일 때 테스트 수행 | ||
pull_request: | ||
branches: [ "master" ] | ||
# pull_request: | ||
# branches: [ "master" ] | ||
|
||
permissions: | ||
contents: read | ||
|
@@ -23,51 +21,7 @@ jobs: | |
with: | ||
java-version: '11' | ||
distribution: 'temurin' # https://github.com/actions/setup-java | ||
|
||
## 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: Grant execute permission for gradlew | ||
run: | ||
chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build -x test | ||
shell: bash | ||
|
||
test: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
|
||
## Gradle test | ||
- name: Run tests | ||
run: ./gradlew test | ||
shell: bash | ||
if: github.ref == 'refs/heads/develop' | ||
|
||
deploy: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
|
||
## gradle caching | ||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
|
@@ -78,36 +32,42 @@ jobs: | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Grant execute permission for gradlew | ||
run: | ||
run: | ||
chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build -x test | ||
shell: bash | ||
|
||
## create application-prod.yml | ||
- name: Create application-prod.yml | ||
## create application-prod.yml | ||
- name: create application-prod.yml | ||
if: contains(github.ref, 'master') | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application-prod.yml | ||
cd ./src/main | ||
mkdir -p resources | ||
cd ./resources | ||
touch ./application.properties | ||
echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.yml | ||
shell: bash | ||
if: github.ref == 'refs/heads/master' | ||
|
||
|
||
- name: Build With Gradle | ||
if: contains(github.ref, 'master') | ||
run: ./gradlew build -x test | ||
|
||
## docker build & push to production | ||
- name: Docker build & push to prod | ||
if: contains(github.ref, 'master') | ||
run: | | ||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} . | ||
docker push ${{ secrets.DOCKER_REPO }} | ||
if: github.ref == 'refs/heads/master' | ||
|
||
## deploy to production | ||
- name: Deploy to prod | ||
uses: appleboy/[email protected] | ||
id: deploy-prod | ||
if: contains(github.ref, 'master') | ||
with: | ||
host: ${{ secrets.EC2_HOST_PROD }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
|
@@ -119,5 +79,4 @@ jobs: | |
sudo docker rm -f $(docker ps -qa) | ||
sudo docker pull ${{ secrets.DOCKER_REPO }} | ||
docker-compose up -d | ||
docker image prune -f | ||
if: github.ref == 'refs/heads/master' | ||
docker image prune -f |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/web/stard/domain/admin/api/TestController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.web.stard.domain.admin.api; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
@GetMapping("/health") | ||
public String healthCheck() { | ||
return "I'm healthy!"; | ||
} | ||
} |