Skip to content

Commit

Permalink
feat: CI/CD 파이프라인 구축
Browse files Browse the repository at this point in the history
feat: CI/CD 파이프라인 구축
  • Loading branch information
yslle authored Sep 27, 2024
2 parents 0f7f3ab + c58389f commit 13ba636
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 60 deletions.
79 changes: 19 additions & 60 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -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 src/main/java/com/web/stard/domain/admin/api/TestController.java
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!";
}
}

0 comments on commit 13ba636

Please sign in to comment.