개발 환경
1. Github 계정 생성하기: https://github.com/signup
GitHub · Build and ship software on a single, collaborative platform
Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advances humanity.
github.com
2. APP 소스 코드 생성 혹은 복사 -> 배포하고자 하는 github repository를 fork
https://github.com/k8s-1pro/kubernetes-anotherclass-api-tester/tree/3.0.0
fork를 하게 되면 동일한 프로젝트가 내 github repository로 복사된다.
3. Intellij 설치 및 프로젝트 설정: https://www.jetbrains.com/ko-kr/idea/
IntelliJ IDEA – 전문적인 Java 및 Kotlin 개발을 위한 IDE
www.jetbrains.com
설치가 완료되면 일단 새로운 프로젝트를 생성한다. ▶ New Project > Empty Project
어차피 설정 후 삭제할 예정이니 아무 이름으로 생성하면 된다.
이후 Intellij에 내 Git과 GitHub을 연동한다.
▶ Win : File > Settings [ctrl+alt+s] > Version Control > Git > Test 버튼 클릭 후 > [Git version is 2.42.x] 확인
▶ File > Settings > Version Control > Github > Add > Log In via GitHub...
▶ 메뉴에 Git 버튼 활성화
- VCS > Enable Version Control Intergration > Git
메뉴에 Git을 추가하여 간편하게 기능을 사용할 수 있음
▶ Git > [Clone...] 클릭 > GitHub username 선택 > Repository 선택 > [Clone] 클릭
git clone을 통해 fork한 repository를 프로젝트로 생성한다.
4. OpenJDK 설정
▶ OpenJDK 다운로드 Site : https://jdk.java.net/archive/
▶ 다운로드 링크 (17 GA 버전)
▶ File > Project Structure > Project Settings > Projects > SDK > [Add JDK...] 선택
OpenJDK가 없다면 설치해주고, 프로젝트에서 사용할 JDK 버전 선택해준다.
5. GitHub으로 Commit하기
오른쪽 탭에서 Commit을 선택하고, 수정사항과 commit message를 확인 후 commit and push하면 된다.
6. Gradle 빌드 설정
▶ Run > Edit Configurations.. > Run/Debug Configurations > [+] > Gradle
Run 명령어에 bootJar bootRun를 넣으면 실행 시 자동으로 build 하여 jar 파일을 생성하고, 해당 jar 파일을 실행한다.
▶ build > libs > app-0.0.1-SNAPSHOT.jar 파일 생성 확인
▶ Run 창을 통해 실행 확인 (alt + 4)
테스트 환경
1. Docker Desktop 설치
▶ 설치 URL : https://docs.docker.com/get-docker/
2. Intellij에서 Docker plugins 설치
▶ File > Settings > Plugins > Marketplace > 검색 : Docker 후 [Install] 클릭 > OK
3. Intellij에서 Docker Desktop 연결
▶ File > Settings [ctrl+alt+s] > Build, Execution, Deployment > Docker > [Refresh] > [Connection successful] 문구 확인
오른쪽 위의 refresh 버튼을 누르면 Connection Successful이 뜬다. Docker desktop이 실행 중인지 확인.
▶ View > Tool Windows > Services [alt+8] > [▶] 클릭
4. Intellij에서 Docker Image Build
▶ Project 상위폴더 > 마우스 우클릭 > New > File > Dockerfile 생성
FROM openjdk:17
COPY ./build/libs/app-0.0.1-SNAPSHOT.jar /usr/src/myapp/app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=${spring_profiles_active}", "-Dapplication.role=${application_role}", "-Dpostgresql.filepath=${postgresql_filepath}", "-jar", "/usr/src/myapp/app.jar"]
EXPOSE 8080
WORKDIR /usr/src/myapp
▶ Run > Edit Configurations..
▶ [+] > Docker > Dockefile 선택
▶ Name 입력 및 [Modify options]에서 Bind ports, Bind mounts, Environment variables 선택
Name : api-tester
Dockerfile : Dockerfile [자동 선택되어 있음] -> 안되어 있으면 직접 지정해주기
Container name : [미입력] -> 컨테이너 이름 자동 생성됨
# Bind ports 값
Host port : 18080
Contaienr Port : 8080
# Bind Mounts 값
Host path : C:\volume\container\pv
Container path : /usr/src/myapp/files/dev
# Environment Variables 값
application_role: ALL
spring_profiles_active: container
postgresql_filepath: "/usr/src/myapp/datasource/postgresql-info.yaml"
실행하면 image가 빌드되고 컨테이너가 실행된다.
'인프라' 카테고리의 다른 글
[쿠버네티스] Application 개발자가 꼭 알아야하는 Kubernetes Pod 기능 (2) - Pod 종료 시 안정적으로 Application 종료하기 (0) | 2025.03.08 |
---|---|
[쿠버네티스] Application 개발자가 꼭 알아야하는 Kubernetes Pod 기능 (1) - Pod 정보 조회하기 (1) | 2025.03.08 |
쿠버네티스에서의 컨테이너, 가상화 기술 정리 (0) | 2025.03.04 |
[Docker] Dockerfile 명령어 및 작성예시 (1) | 2024.12.17 |
Prometheus+Grafana로 Triton Inference Server 모니터링 하기 (0) | 2024.12.03 |