diff --git a/.elasticbeanstalk/config.yml b/.elasticbeanstalk/config.yml new file mode 100644 index 0000000..93a7979 --- /dev/null +++ b/.elasticbeanstalk/config.yml @@ -0,0 +1,9 @@ +branch-defaults: + develop: + environment: Routebox-dev-env + main: + environment: Routebox-prod-env +global: + application_name: routebox + default_region: ap-northeast-2 + platform: Docker diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml index ac96e92..f00d714 100644 --- a/.github/workflows/dev-deploy.yml +++ b/.github/workflows/dev-deploy.yml @@ -1,16 +1,15 @@ -name: Dev Deploy to Amazon ECS +name: Dev Deploy to Elastic Beanstalk on: push: - branches: [ "develop" ] + branches: [ "feature/#143" ] env: AWS_REGION: ap-northeast-2 ECR_REPOSITORY: routebox-dev - ECS_SERVICE: routebox-service-dev - ECS_CLUSTER: routebox-dev-cluster - ECS_TASK_DEFINITION: routebox-task-definition-dev.json - CONTAINER_NAME: routebox-dev + EB_APP_NAME: routebox + EB_ENV_NAME: Routebox-dev-env + DOCKER_IMAGE_TAG: ${{ github.sha }} permissions: contents: read @@ -36,7 +35,7 @@ jobs: - name: Copy Secret env: - CREATE_SECRET: ${{secrets.ENV_DEV}} + CREATE_SECRET: ${{ secrets.ENV_DEV }} CREATE_SECRET_DIR: src/main/resources CREATE_SECRET_DIR_FILE_NAME: env.properties run: echo $CREATE_SECRET | base64 --decode > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME @@ -45,41 +44,38 @@ jobs: run: ./gradlew build - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v2 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ env.AWS_REGION }} + - name: Copy dev compose file + run: cp docker-compose.dev.yml docker-compose.yml + - name: Login to Amazon ECR id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 + run: | + aws ecr get-login-password --region $AWS_REGION | \ + docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com - - name: Build, tag, and push image to Amazon ECR + - name: Build, tag, and push Docker image to Amazon ECR id: build-image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - IMAGE_TAG: ${{ github.sha }} run: | - # Build a docker container and - # push it to ECR so that it can - # be deployed to ECS. - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT - - - name: Fill in the new image ID in the Amazon ECS task definition - id: task-def - uses: aws-actions/amazon-ecs-render-task-definition@v1 - with: - task-definition: ${{ env.ECS_TASK_DEFINITION }} - container-name: ${{ env.CONTAINER_NAME }} - image: ${{ steps.build-image.outputs.image }} + IMAGE_URI=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$DOCKER_IMAGE_TAG + docker build -t $IMAGE_URI . + docker push $IMAGE_URI + echo "image=$IMAGE_URI" >> $GITHUB_OUTPUT - - name: Deploy Amazon ECS task definition - uses: aws-actions/amazon-ecs-deploy-task-definition@v1 - with: - task-definition: ${{ steps.task-def.outputs.task-definition }} - service: ${{ env.ECS_SERVICE }} - cluster: ${{ env.ECS_CLUSTER }} - wait-for-service-stability: true + - name: Install EB CLI + run: | + pip install --upgrade --user awsebcli + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: EB Init + run: | + eb init ${{ env.EB_APP_NAME }} --platform "Docker running on 64bit Amazon Linux 2023" --region ${{ env.AWS_REGION }} + eb use ${{ env.EB_ENV_NAME }} + + - name: Deploy to Elastic Beanstalk + run: eb deploy --staged --verbose diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..0a99696 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,14 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + image: routebox-dev:latest + ports: + - "8080:8080" + environment: + SPRING_PROFILES_ACTIVE: dev + TZ: Asia/Seoul + restart: always diff --git a/src/main/kotlin/com/routebox/routebox/controller/route/RouteController.kt b/src/main/kotlin/com/routebox/routebox/controller/route/RouteController.kt index bb3124e..77439f9 100644 --- a/src/main/kotlin/com/routebox/routebox/controller/route/RouteController.kt +++ b/src/main/kotlin/com/routebox/routebox/controller/route/RouteController.kt @@ -99,8 +99,7 @@ class RouteController( @Operation( summary = "루트 구매하기", description = "
루트를 구매합니다. 루트는 쿠폰과 포인트를 사용하여 구매할 수 있습니다." + - "
쿠폰을 사용하여 루트를 구매할 경우, 이용 종료일이 얼마 남지 않은 쿠폰이 자동으로 사용됩니다" + - "
포인트를 사용하여 루트를 구매하는 기능은 현재 미구현 상태입니다. (추후 구현 예정)", + "
쿠폰을 사용하여 루트를 구매할 경우, 이용 종료일이 얼마 남지 않은 쿠폰이 자동으로 사용됩니다", security = [SecurityRequirement(name = "access-token")], ) @ApiResponses( diff --git a/src/main/kotlin/com/routebox/routebox/domain/user/UserService.kt b/src/main/kotlin/com/routebox/routebox/domain/user/UserService.kt index 5763cd3..56c781d 100644 --- a/src/main/kotlin/com/routebox/routebox/domain/user/UserService.kt +++ b/src/main/kotlin/com/routebox/routebox/domain/user/UserService.kt @@ -140,7 +140,7 @@ class UserService( @Transactional fun usePoint(userId: Long, point: Int): User { val user = getUserById(userId) - if (user.canPurchase(point)) { + if (!user.canPurchase(point)) { throw InsufficientPointException() } user.usePoint(point)