AWS REACT 도커

신상우·2023년 12월 20일

쿠버네티스

목록 보기
10/26

.dockerignore

package-lock.json
node_modules

docker-compose-dev.yml

version: "3"
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "3000:3000"
    volumes:
      - /app/node_modules
      - .:/app
  tests:
    stdin_open: true
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - .:/app
    command: ["npm", "run", "test"]

docker-compose.yml

version: "3"
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "3000:3000"
    volumes:
      - /app/node_modules
      - .:/app
  tests:
    stdin_open: true
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - .:/app
    command: ["npm", "run", "test"]

Dockerfile

FROM node:16-alpine as builder

WORKDIR '/app'

COPY package.json .
RUN npm install

COPY . .
RUN npm run build

FROM nginx

COPY --from=builder /app/build /usr/share/nginx/html

Dockerfile.dev

FROM node:16-alpine

WORKDIR '/app'

COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "start"]

IAM 생성

AWSElasticBeanstalkMulticontainerDocker
AWSElasticBeanstalkWebTier
AWSElasticBeanstalkWorkerTier

ElasticBeanstalk 생성

플랫폼 Docker

플랫폼 브랜치
Docker running on 64bit Amazon Linux 2

ec2인스턴스 프로파일 iam에서 생성한 거 선택 후 검토단계로건너뛰기

IAM > 사용자

직접 정책 연결
AdministratorAccess-AWSElasticBeanstalk

후 보안 자격 증명
액세스 키 생성
Command Line Interface(CLI)

AKIATNTPNECOSRLDMTHP
MgCGaw/YKFGlaerrhH9CpkGaQzf+L7KuXJAEC6r0

S3

만들어진 파일에서 객체소유권 편집에서 ACL 활성화됨 으로 바꾸고
객체 라이터로 바꿈

.github\workflows 폴더에
deploy.yaml 파일에

name: Deploy Frontend
on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
      - run: docker build -t shinsang97/react-test -f Dockerfile.dev .
      - run: docker run -e CI=true shinsang97/react-test npm test

      - name: Generate deployment package
        run: zip -r deploy.zip . -x '*.git*'

      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v18
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
          aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
          application_name: react-docker-gh-test
          environment_name: React-docker-gh-test-env
          existing_bucket_name: elasticbeanstalk-ap-northeast-2-235383103645
          region: ap-northeast-2
          version_label: ${{ github.sha }}
          deployment_package: deploy.zip

Actions secrets and variables > Actions에
AWS_ACCESS_KEY, AWS_SECRET_KEY, DOCKER_PASSWORD, DOCKER_USERNAME
추가

Elastic Beanstalk > 환경

application_name 어플리케이션 이름
environment_name 환경이름
existing_bucket_name S3 이름

profile
기록 남기기

0개의 댓글