Skip to content

Commit

Permalink
chore: CICD 설정
Browse files Browse the repository at this point in the history
chore: Dockerfile 추가

chore:  CICD application.yml 생성 추가

chore:  CICD application.yml 생성 추가

feat: health check api 추가

test: CICD 테스트

test: CICD 테스트

test: CICD 테스트

test: CICD 테스트

test: CICD 테스트

test: CICD 테스트
  • Loading branch information
nohy6630 committed May 8, 2024
1 parent 93cb9b2 commit 7eb9c8b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI CD

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.0

- name: Setup Java JDK
uses: actions/setup-java@v3.13.0
with:
java-version: '17'
distribution: 'temurin'

- name: Cache
uses: actions/cache@v3.3.2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Create application.yml
env:
APPLICATION_YML: ${{secrets.APPLICATION_YML}}
run: |
mkdir -p src/main/resources
echo $APPLICATION_YML | base64 --decode > src/main/resources/application.yml
ls -la src/main/resources
- name: Grant execute permission for gradlew
run: chmod u+x gradlew

- name: Build with Gradle
run: ./gradlew build -x test

- name: Build and push Docker image
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
run: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker build -t $DOCKER_USERNAME/alarm .
docker push $DOCKER_USERNAME/alarm
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.0

- name: SSH Remote Commands
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{secrets.EC2_HOST}}
username: ubuntu
key: ${{secrets.EC2_PRIVATE_KEY}}
port: 22
script: |
sudo chmod 777 ./deploy.sh
sudo ./deploy.sh
sudo docker image prune -f
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM openjdk:17
COPY build/libs/alarm-server-0.0.1-SNAPSHOT.jar app.jar
CMD ["java", "-jar", "app.jar"]
14 changes: 14 additions & 0 deletions src/main/java/com/yeongjin/alarmserver/HealthCheckController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.yeongjin.alarmserver;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/healths")
public class HealthCheckController {
@GetMapping
public String checkHealth() {
return "success";
}
}

0 comments on commit 7eb9c8b

Please sign in to comment.