Skip to content

Commit

Permalink
Merge pull request #1 from wndlthsk/feat/kakao-tech-campus-2nd-step3#8-…
Browse files Browse the repository at this point in the history
…ci-cd

weekly ci 테스트
  • Loading branch information
wndlthsk authored Oct 3, 2024
2 parents 2e1f22f + 66394b2 commit 3c4c223
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
name: Java CI with Gradle

# Master, develop 브랜치에 push 혹은 pull request가 발생할 경우 동작한다.
# Master, develop, weekly/* 브랜치에 push가 발생할 경우 동작한다.
on:
push:
branches: [ "Master", "develop" ]
pull_request:
branches: [ "Master", "develop" ]
branches: [ "Master", "develop", "weekly/*" ]

permissions:
contents: read

jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정
build-docker-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
# 1. Java 17 세팅
# Java 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Gradle Wrapper 파일 실행 권한 주기
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew

# 2. Spring Boot 애플리케이션 빌드
# Spring Boot 애플리케이션 빌드
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: clean bootJar

# 3. Docker 이미지 빌드
# 테스트 실행
- name: Run tests
run: ./gradlew test

# Docker 이미지 빌드
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/inplace .

# 4. DockerHub 로그인
# DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# 5. Docker Hub 이미지 푸시
# Docker Hub 이미지 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/inplace

Expand All @@ -55,6 +58,9 @@ jobs:
needs: build-docker-image
runs-on: self-hosted

# weekly/* 브랜치에서는 실행되지 않도록 조건 추가
if: startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/develop')

steps:
# 1. 최신 이미지를 pull
- name: docker pull
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Dockerfile

# jdk17 Image Start
#FROM --platform=linux/amd64 ubuntu:latest
FROM openjdk:17

# 인자 설정 - Jar_File
ARG JAR_FILE=build/libs/*.jar

# jar 파일 복제
COPY ${JAR_FILE} app.jar

# 인자 설정 부분과 jar 파일 복제 부분 합쳐서 진행해도 무방
#COPY build/libs/*.jar app.jar

# 실행 명령어
ENTRYPOINT ["java", "-jar", "app.jar"]
13 changes: 13 additions & 0 deletions src/main/java/team7/inplace/cicd/TestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team7.inplace.cicd;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
@GetMapping("/cicd")
public ResponseEntity test() {
return ResponseEntity.ok("ci/cd 테스트");
}
}

0 comments on commit 3c4c223

Please sign in to comment.