feat: HTTP 서버로 전환 + Kaniko 이미지 빌드/K8s 배포 파이프라인 추가
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
FROM eclipse-temurin:21-jre
|
||||
WORKDIR /app
|
||||
COPY build/libs/*.jar app.jar
|
||||
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
|
||||
Vendored
+48
-1
@@ -5,19 +5,66 @@ pipeline {
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
serviceAccountName: jenkins-deployer
|
||||
containers:
|
||||
- name: gradle
|
||||
image: eclipse-temurin:21-jdk
|
||||
command: ["sleep"]
|
||||
args: ["99d"]
|
||||
- name: kaniko
|
||||
image: gcr.io/kaniko-project/executor:debug
|
||||
command: ["sleep"]
|
||||
args: ["99d"]
|
||||
volumeMounts:
|
||||
- name: docker-config
|
||||
mountPath: /kaniko/.docker
|
||||
- name: kubectl
|
||||
image: bitnami/kubectl:1.31
|
||||
command: ["sleep"]
|
||||
args: ["99d"]
|
||||
volumes:
|
||||
- name: docker-config
|
||||
secret:
|
||||
secretName: gitea-registry-cred
|
||||
items:
|
||||
- key: .dockerconfigjson
|
||||
path: config.json
|
||||
'''
|
||||
}
|
||||
}
|
||||
environment {
|
||||
IMAGE = "gitea.led.ectech.co.kr/ledmega/cstest:${env.BUILD_NUMBER}"
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
container('gradle') {
|
||||
sh 'chmod +x gradlew && ./gradlew build --console=plain'
|
||||
sh 'chmod +x gradlew && ./gradlew build --console=plain -x test'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Image') {
|
||||
steps {
|
||||
container('kaniko') {
|
||||
sh '''
|
||||
/kaniko/executor \
|
||||
--context `pwd` \
|
||||
--dockerfile Dockerfile \
|
||||
--destination ${IMAGE}
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
container('kubectl') {
|
||||
sh '''
|
||||
sed "s#IMAGE_PLACEHOLDER#${IMAGE}#" k8s/deployment.yaml > /tmp/deployment.yaml
|
||||
kubectl apply -f /tmp/deployment.yaml
|
||||
kubectl apply -f k8s/service.yaml
|
||||
kubectl apply -f k8s/ingress.yaml
|
||||
kubectl -n apps rollout status deployment/cstest --timeout=90s
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: cstest
|
||||
namespace: apps
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: cstest
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: cstest
|
||||
spec:
|
||||
containers:
|
||||
- name: cstest
|
||||
image: IMAGE_PLACEHOLDER
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 8080
|
||||
initialDelaySeconds: 3
|
||||
periodSeconds: 5
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 8080
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 10
|
||||
resources:
|
||||
requests:
|
||||
cpu: "50m"
|
||||
memory: "128Mi"
|
||||
limits:
|
||||
cpu: "250m"
|
||||
memory: "256Mi"
|
||||
@@ -0,0 +1,18 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: cstest
|
||||
namespace: apps
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- host: cstest.led.ectech.co.kr
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: cstest
|
||||
port:
|
||||
number: 8080
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: cstest
|
||||
namespace: apps
|
||||
spec:
|
||||
selector:
|
||||
app: cstest
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
@@ -1,12 +1,37 @@
|
||||
package com.cstest;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class App {
|
||||
|
||||
public String greeting() {
|
||||
return "Hello for real this time from cstest — Gitea/Jenkins CI/CD 연동 테스트용 프로그램";
|
||||
return "Hello for real this time from cstest — Gitea/Jenkins/K8s CI/CD 연동 테스트용 프로그램";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new App().greeting());
|
||||
public static void main(String[] args) throws IOException {
|
||||
App app = new App();
|
||||
int port = 8080;
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
server.createContext("/", exchange -> {
|
||||
byte[] body = app.greeting().getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().add("Content-Type", "text/plain; charset=utf-8");
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
try (OutputStream os = exchange.getResponseBody()) {
|
||||
os.write(body);
|
||||
}
|
||||
});
|
||||
server.createContext("/healthz", exchange -> {
|
||||
byte[] body = "OK".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
try (OutputStream os = exchange.getResponseBody()) {
|
||||
os.write(body);
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
System.out.println("cstest listening on :" + port);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user