diff --git a/.ebextensions/01.db.config b/.ebextensions/01.db.config new file mode 100644 index 0000000..637e364 --- /dev/null +++ b/.ebextensions/01.db.config @@ -0,0 +1,5 @@ +option_settings: + aws:elasticbeanstalk:application:environment: + NODE_ENV: "develop" + DATABASE_URL: "postgresql://postgres:HqYEvjt6WhIyaDuZxjzm@scale-diary-db-develop.cvs4eam02tzq.ap-northeast-2.rds.amazonaws.com:5432/scalediary" + REDIS_URL: "scale-diary-cache-develop.9hs1lu.ng.0001.apn2.cache.amazonaws.com:6379" \ No newline at end of file diff --git a/.github/workflows/develop.build.yml b/.github/workflows/develop.build.yml index 1b104d3..f114016 100644 --- a/.github/workflows/develop.build.yml +++ b/.github/workflows/develop.build.yml @@ -1,12 +1,16 @@ -name: Deploy Devleopment +name: Deploy Development to Elastic Beanstalk + +env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + on: - push: + pull_request: branches: - develop jobs: build: - # if: "!contains(github.event.head_commit.message, 'NOT DEPLOY')" runs-on: ubuntu-latest permissions: id-token: write @@ -14,18 +18,45 @@ jobs: steps: - name: Checkout source code - uses: actions/checkout@v3 - - # - name: Generate deployment package - # run: zip -r deploy.zip . -x '*.git*' 'node_modules/*' - - # - name: Deploy to EB - # uses: einaregilsson/beanstalk-deploy@v22 - # with: - # aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # application_name: scale-diary-server-develop - # environment_name: scale-diary-server-develop-env - # version_label: develop-${{ github.sha }} - # region: ap-northeast-2 - # deployment_package: deploy.zip + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and Push Docker image + run: | + docker buildx build --platform linux/amd64 -t $DOCKER_USERNAME/muda . + docker push $DOCKER_USERNAME/muda + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + + - name: Deploy to Elastic Beanstalk + run: | + eb init -p docker muda --region $AWS_REGION + eb use develop + eb deploy --staged + + # - name: Generate deployment package + # run: zip -r deploy.zip . -x '*.git*' 'node_modules/*' + + # - name: Deploy to EB + # uses: einaregilsson/beanstalk-deploy@v22 + # with: + # aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # application_name: scale-diary-server-develop + # environment_name: scale-diary-server-develop-env + # version_label: develop-${{ github.sha }} + # region: ap-northeast-2 + # deployment_package: deploy.zip diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e34c36f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Stage 1: Build the application +FROM node:20-alpine AS builder +WORKDIR /app + +# Install dependencies +COPY package*.json ./ +RUN npm install + +# Copy the rest of the application code and build it +COPY . . +RUN npm run build + +# Generate Prisma client +RUN npm exec prisma generate + +# Stage 2: Create production image +FROM node:20-alpine AS runner +WORKDIR /app + +# Copy built application from the builder stage +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/node_modules ./node_modules +COPY package*.json ./ +COPY ./.env ./ + +EXPOSE 5000 +CMD ["npm", "run", "start:prod"]