Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #161

Merged
merged 18 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
271e50d
Feat: #156 오픈채팅방 정보 조회(for user) API 추가
LeeJae-H Sep 10, 2024
ad1d1ed
Feat: #156 오픈채팅방 정보 수정(for admin) API 추가
LeeJae-H Sep 10, 2024
6a44e51
Fix: #156 시크릿키 header명 변경, url 수정 로직 삭제, security 관련 수정, 생년 예외 로직 수정
LeeJae-H Sep 11, 2024
38fc390
Update: #158 개발서버 private subnet 이동
BYEONGRYEOL Sep 11, 2024
ff5a197
Update: #158 cicd 파이프라인 내 오타 수정
BYEONGRYEOL Sep 11, 2024
01d6a65
Merge pull request #159
BYEONGRYEOL Sep 11, 2024
ae0663e
Update: #158 login-ecr staging에도 반영
BYEONGRYEOL Sep 11, 2024
a1dba25
Merge pull request #160
BYEONGRYEOL Sep 11, 2024
84a66e3
Fix: #156 생년 숫자 변환 로직 수정, SecurityConfig 수정
LeeJae-H Sep 12, 2024
d06a9b5
Fix: #156 OpenChatType에서 NONE 객체 삭제, 시크릿키 @Value 사용, 어드민컨트롤러 기타 수정
LeeJae-H Sep 12, 2024
b4962d1
Update: #158 cicd 파이프라인 내 오타 수정
BYEONGRYEOL Sep 12, 2024
3b5035c
Merge branch 'staging' of https://github.com/Genti2024/GenTI-BE into …
BYEONGRYEOL Sep 12, 2024
82fccfc
Fix: #156
LeeJae-H Sep 12, 2024
7403eb4
Update: #158 S3 버킷 운영과 공유
BYEONGRYEOL Sep 12, 2024
aadd26f
Merge pull request #157 from Genti2024/feat/kakao-open-chat
BYEONGRYEOL Sep 12, 2024
55438e7
Merge branch 'dev' into staging
BYEONGRYEOL Sep 12, 2024
a313b10
Fix: SecurityConfig의 cors 설정에 PATCH 메소드 추가
LeeJae-H Sep 12, 2024
8dc903d
Fix: file-appender.xml
LeeJae-H Sep 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 92 additions & 55 deletions .github/workflows/cicd-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: genti-deploy
CODE_DEPLOY_APPLICATION_NAME: genti
CODE_DEPLOY_APPLICATION_NAME_STAGING: genti-dev

permissions:
contents: read
Expand Down Expand Up @@ -105,13 +106,13 @@ jobs:
run: |
chmod +x ./gradlew
./gradlew clean build -x test



- name: Get Github action IP
if: contains(github.ref, 'staging')
id: ip
uses: haythem/[email protected]

# - name: Get Github action IP
# if: contains(github.ref, 'staging')
# id: ip
# uses: haythem/[email protected]
#
- name: Setting environment variables
run: |
echo "AWS_DEFAULT_REGION=ap-northeast-2" >> $GITHUB_ENV
Expand All @@ -123,18 +124,18 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Add Github Actions IP to Security group
if: contains(github.ref, 'staging')
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2
# - name: Add Github Actions IP to Security group
# if: contains(github.ref, 'staging')
# run: |
# aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ap-northeast-2


- name: Login to aws ECR
if: contains(github.ref, 'main')
if: contains(github.ref, 'staging') || contains(github.ref, 'main')
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

Expand All @@ -148,6 +149,15 @@ jobs:
docker build -f ./Dockerfile_deploy -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Build, tag, and push image to aws ECR
if: contains(github.ref, 'staging')
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: genti-staging
IMAGE_TAG: latest
run: |
docker build -f ./Dockerfile_staging -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Upload docker-compose, appspec, afterInstall file to S3
if: contains(github.ref, 'main')
Expand All @@ -169,16 +179,36 @@ jobs:
# Clean up the temporary directory
rm -rf temp_dir

- name: Upload docker compose file to staging server
- name: Upload docker-compose, appspec, afterInstall file to S3
if: contains(github.ref, 'staging')
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_STAGING }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
port: 22
source: "./docker/staging/*"
target: "/home/ubuntu/workspace/"
run: |
# Create a temporary directory for the zip contents
mkdir -p temp_dir/scripts
cp -r ./scripts/* temp_dir/scripts/
cp appspec.yml temp_dir/
cp ./docker/staging/docker-compose.yml temp_dir/docker-compose.yml

# Navigate to the temporary directory and create the zip file
cd temp_dir
zip -r ../$GITHUB_SHA.zip ./*

# Move back to the initial directory and upload the zip file to S3
cd ..
aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME

# Clean up the temporary directory
rm -rf temp_dir

# - name: Upload docker compose file to staging server
# if: contains(github.ref, 'staging')
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.HOST_STAGING }}
# username: ubuntu
# key: ${{ secrets.EC2_KEY }}
# port: 22
# source: "./docker/staging/*"
# target: "/home/ubuntu/workspace/"

# docker build & push to deploy server
- name: Deploy to EC2 with CodeDeploy
Expand All @@ -189,38 +219,45 @@ jobs:
--deployment-group-name ${{ secrets.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip

# docker build & push to staging
- name: Docker build & push to staging
- name: Staging Deploy to EC2 with CodeDeploy
if: contains(github.ref, 'staging')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile_staging -t ${{ secrets.DOCKER_USERNAME }}/genti-staging .
docker push ${{ secrets.DOCKER_USERNAME }}/genti-staging
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME_STAGING }} \
--deployment-group-name genti-tg-staging \
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip
# docker build & push to staging
# - name: Docker build & push to staging
# if: contains(github.ref, 'staging')
# run: |
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# docker build -f Dockerfile_staging -t ${{ secrets.DOCKER_USERNAME }}/genti-staging .
# docker push ${{ secrets.DOCKER_USERNAME }}/genti-staging

## deploy to staging server
- name: Deploy to staging server
uses: appleboy/ssh-action@master
id: deploy-staging
if: contains(github.ref, 'staging')
with:
host: ${{ secrets.HOST_STAGING }} # EC2 퍼블릭 IPv4 DNS
username: ubuntu
password: ${{ secrets.PASSWORD }}
port: 22
key: ${{ secrets.EC2_KEY }}
script: |
sudo docker ps
cd /home/ubuntu/workspace/docker/staging
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/genti-staging
sudo docker-compose up -d
sudo docker image prune -f

- name: delete github actions ip from aws security group
if: contains(github.ref, 'staging')
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2
# - name: Deploy to staging server
# uses: appleboy/ssh-action@master
# id: deploy-staging
# if: contains(github.ref, 'staging')
# with:
# host: ${{ secrets.HOST_STAGING }} # EC2 퍼블릭 IPv4 DNS
# username: ubuntu
# password: ${{ secrets.PASSWORD }}
# port: 22
# key: ${{ secrets.EC2_KEY }}
# script: |
# sudo docker ps
# cd /home/ubuntu/workspace/docker/staging
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# sudo docker pull ${{ secrets.DOCKER_USERNAME }}/genti-staging
# sudo docker-compose up -d
# sudo docker image prune -f

# - name: delete github actions ip from aws security group
# if: contains(github.ref, 'staging')
# run: |
# aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: ap-northeast-2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ firebase-genti.json

AuthKey_ZRZMQQX883.p8
/genti-api/src/main/resources/static/swagger.json
update-github-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gt.genti.openchat.api;

import com.gt.genti.openchat.model.OpenChat;
import com.gt.genti.openchat.model.OpenChatType;
import com.gt.genti.response.GentiResponse.ApiResult;
import com.gt.genti.swagger.AuthorizedAdmin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

@AuthorizedAdmin
@Tag(name = "[AdminOpenChatController] 어드민의 오픈채팅방 정보 수정", description = "카카오톡 오픈채팅방 정보 수정")
public interface AdminOpenChatApi {

@Operation(summary = "오픈채팅방 정보 수정", description = "오픈채팅방의 인원 수를 수정합니다.")
ResponseEntity<ApiResult<OpenChat>> modifyOpenChatInfo(
@RequestHeader(value = "Admin-Secret-Key") String secretKey,
@PathVariable(value = "type") String type,
@RequestParam(value = "count") Long count
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.gt.genti.openchat.api;

import com.gt.genti.openchat.dto.response.OpenChatInfoResponseDto;
import com.gt.genti.response.GentiResponse.ApiResult;
import com.gt.genti.swagger.AuthorizedUser;
import com.gt.genti.user.model.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;

@AuthorizedUser
@Tag(name = "[UserOpenChatController] 유저의 오픈채팅방 요청", description = "카카오톡 오픈채팅방 정보 요청")
public interface UserOpenChatApi {

@Operation(summary = "오픈채팅방 정보 조회", description = "오픈채팅방 url과 인원 수를 조회합니다.")
ResponseEntity<ApiResult<OpenChatInfoResponseDto>> getOpenChatUrl(
@AuthUser Long userId
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.gt.genti.openchat.controller;

import com.gt.genti.error.ExpectedException;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.openchat.api.AdminOpenChatApi;
import com.gt.genti.openchat.model.OpenChat;
import com.gt.genti.openchat.model.OpenChatType;
import com.gt.genti.openchat.service.OpenChatService;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.response.GentiResponse.ApiResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/open-chat")
@RequiredArgsConstructor
public class AdminOpenChatController implements AdminOpenChatApi {

private final OpenChatService openChatService;

@Value("${openchat.admin-secret-key}")
private String ADMIN_SECRET_KEY;

@PatchMapping("/{type}")
public ResponseEntity<ApiResult<OpenChat>> modifyOpenChatInfo(
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey,
@PathVariable(value = "type") String type,
@RequestParam(value = "count") Long count
){
OpenChatType openChatType = OpenChatType.fromString(type);
if (!ADMIN_SECRET_KEY.equals(adminSecretKey)) {
throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey);
} else{
return GentiResponse.success(openChatService.modifyOpenChatInfo(openChatType, count));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.gt.genti.openchat.controller;

import com.gt.genti.openchat.api.UserOpenChatApi;
import com.gt.genti.openchat.dto.response.OpenChatInfoResponseDto;
import com.gt.genti.openchat.service.OpenChatService;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.response.GentiResponse.ApiResult;
import com.gt.genti.user.model.AuthUser;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/open-chat")
@RequiredArgsConstructor
public class UserOpenChatController implements UserOpenChatApi {

private final OpenChatService openChatService;

@GetMapping
public ResponseEntity<ApiResult<OpenChatInfoResponseDto>> getOpenChatUrl(
@AuthUser Long userId
) {
return GentiResponse.success(openChatService.getOpenChatUrl(userId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.gt.genti.openchat.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(name = "[OpenChat][User] 오픈채팅방 정보 응답 dto")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OpenChatInfoResponseDto {

@Schema(description = "오픈 채팅방 대상 여부", example = "true")
Boolean accessible;

@Schema(description = "오픈 채팅방 사람 수")
Long count;

@Schema(description = "오픈 채팅방 url")
String url;

@Builder
public OpenChatInfoResponseDto(Boolean accessible, Long count, String url) {
this.accessible = accessible;
this.count = count;
this.url = url;
}
}
Loading
Loading