diff --git a/.github/workflows/develop_pull_request.yml b/.github/workflows/develop_push.yml similarity index 55% rename from .github/workflows/develop_pull_request.yml rename to .github/workflows/develop_push.yml index 04fd787..cefa5e7 100644 --- a/.github/workflows/develop_pull_request.yml +++ b/.github/workflows/develop_push.yml @@ -1,40 +1,40 @@ -name: Test and Build Docker Image to ECR +name: Build and Deploy to EC2 with Docker Compose on: - pull_request: + push: branches: - - main + - chore/deploy-to-ec2 jobs: - build-and-test: + build-and-push: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18] + # strategy: + # matrix: + # node-version: [18] steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Node ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} + # - name: Set up Node ${{ matrix.node-version }} + # uses: actions/setup-node@v3 + # with: + # node-version: ${{ matrix.node-version }} - - name: Cache node_modules - uses: actions/cache@v3 - with: - path: | - **/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- + # - name: Cache node_modules + # uses: actions/cache@v3 + # with: + # path: | + # **/node_modules + # key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + # restore-keys: ${{ runner.os }}-node- - - name: Install dependencies - run: npm ci + # - name: Install dependencies + # run: npm ci - - name: Build - run: npm run build + # - name: Build + # run: npm run build - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v2 diff --git a/Dockerfile b/Dockerfile index 1ff60f7..7357733 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,23 @@ # Dockerfile for factoreal-FE -FROM node:18 +# Stage 1: Build the application +FROM node:18-alpine AS builder WORKDIR /app COPY package.json package-lock.json ./ -RUN npm install +RUN npm ci COPY . . -ENV NODE_ENV=development -ENV HOST=0.0.0.0 +RUN npm run build -EXPOSE 5173 +# Stage 2: Serve application with Nginx +FROM nginx:stable-alpine -CMD ["npm", "run", "dev", "--", "--host" ] \ No newline at end of file +COPY --from=builder /app/dist /usr/share/nginx/html + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..3bcc1e9 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,26 @@ +server { + listen 80; + server_name 43.200.39.139; + + # 프론트엔드 정적 파일 서비스 + location / { + root /usr/share/nginx/html; + index index.html index.html; + try_files $uri $uri/ /index.html; + } + + # 백엔드 API 프록시 설정 + # /api/ 로 시작하는 모든 요청을 백엔드 서버로 전달 + location /api { + proxy_pass http://backend:8080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # WebSocket을 사용한다면 다음 설정 추가 + # proxy_http_version 1.1; + # proxy_set_header Upgrade $http_upgrade; + # proxy_set_header Connection "upgrade"; + } +} \ No newline at end of file