<nginx 에러 해결>
vi nginx.conf
server {
listen 80;
client_max_body_size 5M;
server_name _;
location /api {
proxy_pass <Backend 주소>; # http 주소 사용
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
location / {
root /usr/share/nginx/html/;
index index.html;
error_page 405 =200 $uri; # 405에러 설정
try_files $uri $uri/ /index.html;
}
}
vi vite.config.js
. . .
server:{
proxy:{
"/api":{
target: "<Backend 주소>/api/", # http 주소 사용
rewrite: (path)=>path.replace(/^\/api/,""),
},
}
}
. . .
📒 아직은 개발이 완료되지 않았기 때문에 파이프라인 구축 후 계속해서 개발이 추가될 것이다.
1 . 설정파일 추가 및 백엔드 연결
2 . Jenkinsfile
pipeline{
agent{
kubernetes{
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: gradle
image: gradle:8.0.2-jdk11 # nodejs가 아닌 gradle 선택
command: ['sleep']
args: ['infinity']
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command: ['sleep']
args: ['infinity']
volumeMounts:
- name: registry-credentials
mountPath: /kaniko/.docker
volumes:
- name: registry-credentials
secret:
secretName: regcred
items:
- key: .dockerconfigjson
path: config.json
'''
}
}
stages{
stage('checkout'){
steps{
container('gradle'){ # gradle에서 작업
git branch: 'main', url:'https://github.com/suhwan12/course-registration-GoormUniversity-admin.git'
}
}
}
stage('npm install & npm Build & Docker Build & Tag Docker image'){
steps{
container('kaniko'){
sh "executor --dockerfile=Dockerfile \
--context=dir://${env.WORKSPACE} \
--destination=suhwan11/frontend:latest \
--destination=suhwan11/frontend:${env.BUILD_NUMBER}"
}
}
}
stage('Update K8s to New Frontend Deployment'){
steps{
container('gradle'){ # gradle에서 작업
git branch: 'main' , url:'https://github.com/suhwan12/finalproject-argocd.git'
sh 'sed -i "s/image:.*/image: suhwan11\\/frontend:${BUILD_NUMBER}/g" front-deployment.yaml'
sh 'git config --global user.name suhwan12'
sh 'git config --global user.email xman0120@naver.com'
sh 'git config --global --add safe.directory /home/jenkins/agent/workspace/Frontend-pipeline'
sh 'git add front-deployment.yaml'
sh 'git commit -m "Jenkins Build Number - ${BUILD_NUMBER}"'
withCredentials([gitUsernamePassword(credentialsId: 'github-credentials', gitToolName: 'Default')]) {
sh 'git push origin main'
}
}
}
}
}
}
📒 내 생각으로는 nodejs를 통해 자동으로 설치된 npm에는 git명령어가 내장되어 있지 않지만, gradle은 git명령어가 내장되어있기 때문이라고 생각한다.
📒 그게 아니라면 stage를 나누지 않고, multi-builder를 이용하여 kaniko 컨테이너에서 모두 작업을 했기 때문에 마지막 stage에서 nodejs컨테이너의 환경에는 필요한 설정들이 존재하지 않기 때문이라고 생각한다.
3 . Dockerfile
FROM node:lts-alpine AS builder # nodejs 이미지 사용
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# npm install & npm build
FROM nginx:stable-alpine # nginx 이미지 사용
COPY ./nginx.conf /etc/nginx/conf.d/default.conf # nginx환경변수 설정파일 전달
COPY --from=builder /app/dist /usr/share/nginx/html
# npm build를 통해 나온 dist파일을 nginx에 전달 = nginx 웹서버에 올리기
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]