mirror of
https://github.com/won-ktds/smarketing-backend.git
synced 2025-12-06 07:06:24 +00:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # smarketing-ai/app.py # smarketing-ai/deployment/manifest/deployment.yaml # smarketing-ai/deployment/manifest/secret.yaml # smarketing-ai/deployment/manifest/service.yaml # smarketing-ai/models/request_models.py # smarketing-ai/services/sns_content_service.py # smarketing-java/ai-recommend/src/main/java/com/won/smarketing/recommend/application/service/MarketingTipService.java # smarketing-java/ai-recommend/src/main/resources/application.yml # smarketing-java/build.gradle # smarketing-java/store/src/main/java/com/won/smarketing/store/dto/MenuUpdateRequest.java
This commit is contained in:
commit
c939561083
@ -74,8 +74,11 @@ def create_app():
|
||||
platform=data.get('platform'),
|
||||
images=data.get('images', []),
|
||||
requirement=data.get('requirement'),
|
||||
toneAndManner=data.get('toneAndManner'),
|
||||
emotionIntensity=data.get('emotionIntensity'),
|
||||
storeName=data.get('storeName'),
|
||||
storeType=data.get('storeType'),
|
||||
target=data.get('target'),
|
||||
#toneAndManner=data.get('toneAndManner'),
|
||||
#emotionIntensity=data.get('emotionIntensity'),
|
||||
menuName=data.get('menuName'),
|
||||
eventName=data.get('eventName'),
|
||||
startDate=data.get('startDate'),
|
||||
|
||||
157
smarketing-ai/deployment/Jenkinsfile
vendored
Normal file
157
smarketing-ai/deployment/Jenkinsfile
vendored
Normal file
@ -0,0 +1,157 @@
|
||||
def PIPELINE_ID = "${env.BUILD_NUMBER}"
|
||||
|
||||
def getImageTag() {
|
||||
def dateFormat = new java.text.SimpleDateFormat('yyyyMMddHHmmss')
|
||||
def currentDate = new Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
|
||||
podTemplate(
|
||||
label: "${PIPELINE_ID}",
|
||||
serviceAccount: 'jenkins',
|
||||
containers: [
|
||||
containerTemplate(name: 'podman', image: "mgoltzsche/podman", ttyEnabled: true, command: 'cat', privileged: true),
|
||||
containerTemplate(name: 'azure-cli', image: 'hiondal/azure-kubectl:latest', command: 'cat', ttyEnabled: true),
|
||||
containerTemplate(name: 'envsubst', image: "hiondal/envsubst", command: 'sleep', args: '1h')
|
||||
],
|
||||
volumes: [
|
||||
emptyDirVolume(mountPath: '/run/podman', memory: false),
|
||||
emptyDirVolume(mountPath: '/root/.azure', memory: false)
|
||||
]
|
||||
) {
|
||||
node(PIPELINE_ID) {
|
||||
def props
|
||||
def imageTag = getImageTag()
|
||||
def manifest = "deploy.yaml"
|
||||
def namespace
|
||||
|
||||
stage("Get Source") {
|
||||
checkout scm
|
||||
props = readProperties file: "deployment/deploy_env_vars"
|
||||
namespace = "${props.namespace}"
|
||||
|
||||
echo "Registry: ${props.registry}"
|
||||
echo "Image Org: ${props.image_org}"
|
||||
echo "Team ID: ${props.teamid}"
|
||||
}
|
||||
|
||||
stage("Setup AKS") {
|
||||
container('azure-cli') {
|
||||
withCredentials([azureServicePrincipal('azure-credentials')]) {
|
||||
sh """
|
||||
az login --service-principal -u \$AZURE_CLIENT_ID -p \$AZURE_CLIENT_SECRET -t \$AZURE_TENANT_ID
|
||||
az aks get-credentials --resource-group rg-digitalgarage-02 --name aks-digitalgarage-02 --overwrite-existing
|
||||
kubectl create namespace ${namespace} --dry-run=client -o yaml | kubectl apply -f -
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build & Push Docker Image') {
|
||||
container('podman') {
|
||||
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
|
||||
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'acr-credentials',
|
||||
usernameVariable: 'ACR_USERNAME',
|
||||
passwordVariable: 'ACR_PASSWORD'
|
||||
)]) {
|
||||
sh """
|
||||
echo "=========================================="
|
||||
echo "Building smarketing-ai Python Flask application"
|
||||
echo "Image Tag: ${imageTag}"
|
||||
echo "=========================================="
|
||||
|
||||
# ACR 로그인
|
||||
echo \$ACR_PASSWORD | podman login ${props.registry} --username \$ACR_USERNAME --password-stdin
|
||||
|
||||
# Docker 이미지 빌드
|
||||
podman build \
|
||||
-f deployment/container/Dockerfile \
|
||||
-t ${props.registry}/${props.image_org}/smarketing-ai:${imageTag} .
|
||||
|
||||
# 이미지 푸시
|
||||
podman push ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}
|
||||
|
||||
echo "Successfully built and pushed: ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Generate & Apply Manifest') {
|
||||
container('envsubst') {
|
||||
withCredentials([
|
||||
string(credentialsId: 'secret-key', variable: 'SECRET_KEY'),
|
||||
string(credentialsId: 'claude-api-key', variable: 'CLAUDE_API_KEY'),
|
||||
string(credentialsId: 'openai-api-key', variable: 'OPENAI_API_KEY'),
|
||||
string(credentialsId: 'azure-storage-account-name', variable: 'AZURE_STORAGE_ACCOUNT_NAME'),
|
||||
string(credentialsId: 'azure-storage-account-key', variable: 'AZURE_STORAGE_ACCOUNT_KEY')
|
||||
]) {
|
||||
sh """
|
||||
export namespace=${namespace}
|
||||
export replicas=${props.replicas}
|
||||
export resources_requests_cpu=${props.resources_requests_cpu}
|
||||
export resources_requests_memory=${props.resources_requests_memory}
|
||||
export resources_limits_cpu=${props.resources_limits_cpu}
|
||||
export resources_limits_memory=${props.resources_limits_memory}
|
||||
export upload_folder=${props.upload_folder}
|
||||
export max_content_length=${props.max_content_length}
|
||||
export allowed_extensions=${props.allowed_extensions}
|
||||
export server_host=${props.server_host}
|
||||
export server_port=${props.server_port}
|
||||
export azure_storage_container_name=${props.azure_storage_container_name}
|
||||
|
||||
# 이미지 경로 환경변수 설정
|
||||
export smarketing_image_path=${props.registry}/${props.image_org}/smarketing-ai:${imageTag}
|
||||
|
||||
# Sensitive 환경변수 설정 (Jenkins Credentials에서)
|
||||
export secret_key=\$SECRET_KEY
|
||||
export claude_api_key=\$CLAUDE_API_KEY
|
||||
export openai_api_key=\$OPENAI_API_KEY
|
||||
export azure_storage_account_name=\$AZURE_STORAGE_ACCOUNT_NAME
|
||||
export azure_storage_account_key=\$AZURE_STORAGE_ACCOUNT_KEY
|
||||
|
||||
# manifest 생성
|
||||
envsubst < deployment/${manifest}.template > deployment/${manifest}
|
||||
echo "Generated manifest file:"
|
||||
cat deployment/${manifest}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
container('azure-cli') {
|
||||
sh """
|
||||
kubectl apply -f deployment/${manifest}
|
||||
|
||||
echo "Waiting for smarketing deployment to be ready..."
|
||||
kubectl -n ${namespace} wait --for=condition=available deployment/smarketing --timeout=300s
|
||||
|
||||
echo "=========================================="
|
||||
echo "Getting LoadBalancer External IP..."
|
||||
|
||||
# External IP 확인 (최대 5분 대기)
|
||||
for i in {1..30}; do
|
||||
EXTERNAL_IP=\$(kubectl -n ${namespace} get service smarketing-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
|
||||
if [ "\$EXTERNAL_IP" != "" ] && [ "\$EXTERNAL_IP" != "null" ]; then
|
||||
echo "External IP assigned: \$EXTERNAL_IP"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for External IP... (attempt \$i/30)"
|
||||
sleep 10
|
||||
done
|
||||
|
||||
# 서비스 상태 확인
|
||||
kubectl -n ${namespace} get pods -l app=smarketing
|
||||
kubectl -n ${namespace} get service smarketing-service
|
||||
|
||||
echo "=========================================="
|
||||
echo "Deployment Complete!"
|
||||
echo "Service URL: http://\$EXTERNAL_IP:${props.server_port}"
|
||||
echo "Health Check: http://\$EXTERNAL_IP:${props.server_port}/health"
|
||||
echo "=========================================="
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
170
smarketing-ai/deployment/Jenkinsfile_ArgoCD
Normal file
170
smarketing-ai/deployment/Jenkinsfile_ArgoCD
Normal file
@ -0,0 +1,170 @@
|
||||
def PIPELINE_ID = "${env.BUILD_NUMBER}"
|
||||
|
||||
def getImageTag() {
|
||||
def dateFormat = new java.text.SimpleDateFormat('yyyyMMddHHmmss')
|
||||
def currentDate = new Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
|
||||
podTemplate(
|
||||
label: "${PIPELINE_ID}",
|
||||
serviceAccount: 'jenkins',
|
||||
containers: [
|
||||
containerTemplate(name: 'podman', image: "mgoltzsche/podman", ttyEnabled: true, command: 'cat', privileged: true),
|
||||
containerTemplate(name: 'git', image: 'alpine/git:latest', command: 'cat', ttyEnabled: true)
|
||||
],
|
||||
volumes: [
|
||||
emptyDirVolume(mountPath: '/run/podman', memory: false)
|
||||
]
|
||||
) {
|
||||
node(PIPELINE_ID) {
|
||||
def props
|
||||
def imageTag = getImageTag()
|
||||
|
||||
stage("Get Source") {
|
||||
checkout scm
|
||||
props = readProperties file: "deployment/deploy_env_vars"
|
||||
}
|
||||
|
||||
stage('Build & Push Docker Image') {
|
||||
container('podman') {
|
||||
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
|
||||
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'acr-credentials',
|
||||
usernameVariable: 'ACR_USERNAME',
|
||||
passwordVariable: 'ACR_PASSWORD'
|
||||
)]) {
|
||||
sh """
|
||||
echo "=========================================="
|
||||
echo "Building smarketing-ai for ArgoCD GitOps"
|
||||
echo "Image Tag: ${imageTag}"
|
||||
echo "=========================================="
|
||||
|
||||
# ACR 로그인
|
||||
echo \$ACR_PASSWORD | podman login ${props.registry} --username \$ACR_USERNAME --password-stdin
|
||||
|
||||
# Docker 이미지 빌드
|
||||
podman build \
|
||||
-f deployment/container/Dockerfile \
|
||||
-t ${props.registry}/${props.image_org}/smarketing-ai:${imageTag} .
|
||||
|
||||
# 이미지 푸시
|
||||
podman push ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}
|
||||
|
||||
echo "Successfully built and pushed: ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Update Manifest Repository') {
|
||||
container('git') {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'github-credentials-${props.teamid}',
|
||||
usernameVariable: 'GIT_USERNAME',
|
||||
passwordVariable: 'GIT_PASSWORD'
|
||||
)]) {
|
||||
sh """
|
||||
# Git 설정
|
||||
git config --global user.email "jenkins@company.com"
|
||||
git config --global user.name "Jenkins CI"
|
||||
|
||||
# Manifest 저장소 클론 (팀별 저장소로 수정 필요)
|
||||
git clone https://\${GIT_USERNAME}:\${GIT_PASSWORD}@github.com/your-team/smarketing-ai-manifest.git
|
||||
cd smarketing-ai-manifest
|
||||
|
||||
echo "=========================================="
|
||||
echo "Updating smarketing-ai manifest repository:"
|
||||
echo "New Image: ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}"
|
||||
|
||||
# smarketing deployment 파일 업데이트
|
||||
if [ -f "smarketing/smarketing-deployment.yaml" ]; then
|
||||
# 이미지 태그 업데이트
|
||||
sed -i "s|image: ${props.registry}/${props.image_org}/smarketing-ai:.*|image: ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}|g" \
|
||||
smarketing/smarketing-deployment.yaml
|
||||
|
||||
echo "Updated smarketing deployment to image tag: ${imageTag}"
|
||||
cat smarketing/smarketing-deployment.yaml | grep "image:"
|
||||
else
|
||||
echo "Warning: smarketing-deployment.yaml not found"
|
||||
echo "Creating manifest directory structure..."
|
||||
|
||||
# 기본 구조 생성
|
||||
mkdir -p smarketing
|
||||
|
||||
# 기본 deployment 파일 생성
|
||||
cat > smarketing/smarketing-deployment.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: smarketing
|
||||
namespace: smarketing
|
||||
labels:
|
||||
app: smarketing
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: smarketing
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: smarketing
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: acr-secret
|
||||
containers:
|
||||
- name: smarketing
|
||||
image: ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 5001
|
||||
resources:
|
||||
requests:
|
||||
cpu: 256m
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: 1024m
|
||||
memory: 2048Mi
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: smarketing-config
|
||||
- secretRef:
|
||||
name: smarketing-secret
|
||||
volumeMounts:
|
||||
- name: upload-storage
|
||||
mountPath: /app/uploads
|
||||
- name: temp-storage
|
||||
mountPath: /app/uploads/temp
|
||||
volumes:
|
||||
- name: upload-storage
|
||||
emptyDir: {}
|
||||
- name: temp-storage
|
||||
emptyDir: {}
|
||||
EOF
|
||||
echo "Created basic smarketing-deployment.yaml"
|
||||
fi
|
||||
|
||||
# 변경사항 커밋 및 푸시
|
||||
git add .
|
||||
git commit -m "Update smarketing-ai image tag to ${imageTag}
|
||||
|
||||
Image: ${props.registry}/${props.image_org}/smarketing-ai:${imageTag}
|
||||
Build: ${env.BUILD_NUMBER}
|
||||
Branch: ${env.BRANCH_NAME}
|
||||
Commit: ${env.GIT_COMMIT}"
|
||||
|
||||
git push origin main
|
||||
|
||||
echo "=========================================="
|
||||
echo "ArgoCD GitOps Update Completed!"
|
||||
echo "Updated Service: smarketing-ai:${imageTag}"
|
||||
echo "ArgoCD will automatically detect and deploy these changes."
|
||||
echo "=========================================="
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
113
smarketing-ai/deployment/deploy.yaml.template
Normal file
113
smarketing-ai/deployment/deploy.yaml.template
Normal file
@ -0,0 +1,113 @@
|
||||
# ConfigMap
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: smarketing-config
|
||||
namespace: ${namespace}
|
||||
data:
|
||||
SERVER_HOST: "${server_host}"
|
||||
SERVER_PORT: "${server_port}"
|
||||
UPLOAD_FOLDER: "${upload_folder}"
|
||||
MAX_CONTENT_LENGTH: "${max_content_length}"
|
||||
ALLOWED_EXTENSIONS: "${allowed_extensions}"
|
||||
AZURE_STORAGE_CONTAINER_NAME: "${azure_storage_container_name}"
|
||||
|
||||
---
|
||||
# Secret
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: smarketing-secret
|
||||
namespace: ${namespace}
|
||||
type: Opaque
|
||||
stringData:
|
||||
SECRET_KEY: "${secret_key}"
|
||||
CLAUDE_API_KEY: "${claude_api_key}"
|
||||
OPENAI_API_KEY: "${openai_api_key}"
|
||||
AZURE_STORAGE_ACCOUNT_NAME: "${azure_storage_account_name}"
|
||||
AZURE_STORAGE_ACCOUNT_KEY: "${azure_storage_account_key}"
|
||||
|
||||
---
|
||||
# Deployment
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: smarketing
|
||||
namespace: ${namespace}
|
||||
labels:
|
||||
app: smarketing
|
||||
spec:
|
||||
replicas: ${replicas}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: smarketing
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: smarketing
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: acr-secret
|
||||
containers:
|
||||
- name: smarketing
|
||||
image: ${smarketing_image_path}
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 5001
|
||||
resources:
|
||||
requests:
|
||||
cpu: ${resources_requests_cpu}
|
||||
memory: ${resources_requests_memory}
|
||||
limits:
|
||||
cpu: ${resources_limits_cpu}
|
||||
memory: ${resources_limits_memory}
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: smarketing-config
|
||||
- secretRef:
|
||||
name: smarketing-secret
|
||||
volumeMounts:
|
||||
- name: upload-storage
|
||||
mountPath: /app/uploads
|
||||
- name: temp-storage
|
||||
mountPath: /app/uploads/temp
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 5001
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 5001
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 3
|
||||
volumes:
|
||||
- name: upload-storage
|
||||
emptyDir: {}
|
||||
- name: temp-storage
|
||||
emptyDir: {}
|
||||
|
||||
---
|
||||
# Service (LoadBalancer type for External IP)
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: smarketing-service
|
||||
namespace: ${namespace}
|
||||
labels:
|
||||
app: smarketing
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- port: 5001
|
||||
targetPort: 5001
|
||||
protocol: TCP
|
||||
name: http
|
||||
selector:
|
||||
app: smarketing
|
||||
27
smarketing-ai/deployment/deploy_env_vars
Normal file
27
smarketing-ai/deployment/deploy_env_vars
Normal file
@ -0,0 +1,27 @@
|
||||
# Team Settings
|
||||
teamid=won
|
||||
root_project=smarketing-ai
|
||||
namespace=smarketing
|
||||
|
||||
# Container Registry Settings
|
||||
registry=acrdigitalgarage02.azurecr.io
|
||||
image_org=won
|
||||
|
||||
# Application Settings
|
||||
replicas=1
|
||||
|
||||
# Resource Settings
|
||||
resources_requests_cpu=256m
|
||||
resources_requests_memory=512Mi
|
||||
resources_limits_cpu=1024m
|
||||
resources_limits_memory=2048Mi
|
||||
|
||||
# Flask App Settings (non-sensitive)
|
||||
upload_folder=/app/uploads
|
||||
max_content_length=16777216
|
||||
allowed_extensions=png,jpg,jpeg,gif,webp
|
||||
server_host=0.0.0.0
|
||||
server_port=5001
|
||||
|
||||
# Azure Storage Settings (non-sensitive)
|
||||
azure_storage_container_name=ai-content
|
||||
@ -19,7 +19,7 @@ spec:
|
||||
- name: acr-secret
|
||||
containers:
|
||||
- name: smarketing
|
||||
image: dg0408cr.azurecr.io/smarketing-ai:latest
|
||||
image: acrdigitalgarage02.azurecr.io/smarketing-ai:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 5001
|
||||
|
||||
@ -5,6 +5,10 @@ metadata:
|
||||
namespace: smarketing
|
||||
type: Opaque
|
||||
stringData:
|
||||
SECRET_KEY: "your-secret-key-change-in-production"
|
||||
CLAUDE_API_KEY: "your-claude-api-key"
|
||||
OPENAI_API_KEY: "your-openai-api-key"
|
||||
SECRET_KEY:
|
||||
CLAUDE_API_KEY:
|
||||
OPENAI_API_KEY:
|
||||
AZURE_STORAGE_ACCOUNT_NAME: "stdigitalgarage02"
|
||||
AZURE_STORAGE_ACCOUNT_KEY:
|
||||
AZURE_STORAGE_CONTAINER_NAME: "ai-content"
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ metadata:
|
||||
labels:
|
||||
app: smarketing
|
||||
spec:
|
||||
type: ClusterIP
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- port: 5001
|
||||
targetPort: 5001
|
||||
|
||||
@ -16,9 +16,12 @@ class SnsContentGetRequest:
|
||||
contentType: str
|
||||
platform: str
|
||||
images: List[str] # 이미지 URL 리스트
|
||||
target : Optional[str] = None # 타켓
|
||||
requirement: Optional[str] = None
|
||||
toneAndManner: Optional[str] = None
|
||||
emotionIntensity: Optional[str] = None
|
||||
storeName: Optional[str] = None
|
||||
storeType: Optional[str] = None
|
||||
#toneAndManner: Optional[str] = None
|
||||
#emotionIntensity: Optional[str] = None
|
||||
menuName: Optional[str] = None
|
||||
eventName: Optional[str] = None
|
||||
startDate: Optional[date] = None # LocalDate -> date
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user