Skip to content

Commit 0374154

Browse files
authored
Merge pull request #13 from Groom-Team11/chore/#7
[CHORE] CICD 및 인프라 구축
2 parents fafcef6 + 14e1c33 commit 0374154

File tree

6 files changed

+179
-1
lines changed

6 files changed

+179
-1
lines changed

.github/workflows/aws.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Deploy to Amazon EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
# 리전, 버킷 이름, CodeDeploy 앱 이름, CodeDeploy 배포 그룹 이름
9+
env:
10+
AWS_REGION: ap-northeast-2
11+
S3_BUCKET_NAME: bloomgroom-bucket
12+
CODE_DEPLOY_APPLICATION_NAME: bloomgroom-codedeploy-app
13+
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: bloomgroom-codedeploy-deployment-group
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
name: Deploy
21+
runs-on: ubuntu-latest
22+
environment: production
23+
24+
steps:
25+
# (1) 기본 체크아웃
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
# (2) JDK 17 세팅
30+
- name: Set up JDK 17
31+
uses: actions/setup-java@v3
32+
with:
33+
distribution: 'temurin'
34+
java-version: '17'
35+
36+
# (3) YML 파일 생성
37+
- name: Set YML
38+
run: |
39+
mkdir -p src/main/resources/database
40+
echo "${{ secrets.APPLICATION_DATABASE_YML }}" | base64 --decode > src/main/resources/database/application-database.yml
41+
mkdir -p src/main/resources/oauth2
42+
echo "${{ secrets.APPLICATION_OAUTH2_YML }}" | base64 --decode > src/main/resources/oauth2/application-oauth2.yml
43+
mkdir -p src/main/resources/s3
44+
echo "${{ secrets.APPLICATION_S3_YML }}" | base64 --decode > src/main/resources/s3/application-s3.yml
45+
46+
47+
# (4) Gradle build (Test 제외)
48+
- name: Build with Gradle
49+
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
50+
with:
51+
arguments: clean build -x test
52+
53+
# (5) AWS 인증 (IAM 사용자 Access Key, Secret Key 활용)
54+
- name: Configure AWS credentials
55+
uses: aws-actions/configure-aws-credentials@v1
56+
with:
57+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
58+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
59+
aws-region: ap-northeast-2
60+
61+
# (6) 빌드 결과물을 S3 버킷에 업로드
62+
- name: Upload to AWS S3
63+
run: |
64+
aws deploy push \
65+
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
66+
--ignore-hidden-files \
67+
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
68+
--source .
69+
70+
# (7) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행
71+
- name: Deploy to AWS EC2 from S3
72+
run: |
73+
aws deploy create-deployment \
74+
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
75+
--deployment-config-name CodeDeployDefault.AllAtOnce \
76+
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
77+
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip

src/main/java/com/bloomgroom/BloomGroomApplication.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
@PropertySource(value = { "classpath:database/application-database.yml" }, factory = YamlPropertySourceFactory.class)
1515
@PropertySource(value = { "classpath:oauth2/application-oauth2.yml" }, factory = YamlPropertySourceFactory.class)
16-
//@PropertySource(value = { "classpath:s3/application-s3.yml" }, factory = YamlPropertySourceFactory.class)
16+
@PropertySource(value = { "classpath:s3/application-s3.yml" }, factory = YamlPropertySourceFactory.class)
17+
1718
public class BloomGroomApplication {
1819

1920
public static void main(String[] args) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.bloomgroom.global.config;
2+
3+
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.client.RestTemplate;
7+
8+
@Configuration
9+
public class AppConfig {
10+
11+
@Bean
12+
public RestTemplate restTemplate() {
13+
return new RestTemplate();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.bloomgroom.global.config;
2+
3+
import com.amazonaws.auth.AWSStaticCredentialsProvider;
4+
import com.amazonaws.auth.BasicAWSCredentials;
5+
import com.amazonaws.services.s3.AmazonS3Client;
6+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
public class S3Config {
13+
@Value("${cloud.aws.credentials.access-key}")
14+
private String accessKey;
15+
@Value("${cloud.aws.credentials.secret-key}")
16+
private String secretKey;
17+
@Value("${cloud.aws.region.static}")
18+
private String region;
19+
20+
@Bean
21+
public AmazonS3Client amazonS3Client() {
22+
BasicAWSCredentials awsCredentials= new BasicAWSCredentials(accessKey, secretKey);
23+
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
24+
.withRegion(region)
25+
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
26+
.build();
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.bloomgroom.global.config;
2+
3+
import io.swagger.v3.oas.models.Components;
4+
import io.swagger.v3.oas.models.OpenAPI;
5+
import io.swagger.v3.oas.models.info.Info;
6+
import io.swagger.v3.oas.models.security.SecurityRequirement;
7+
import io.swagger.v3.oas.models.security.SecurityScheme;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
public class SwaggerConfig {
13+
private SecurityScheme createAPIKeyScheme() {
14+
return new SecurityScheme().type(SecurityScheme.Type.HTTP)
15+
.bearerFormat("JWT")
16+
.scheme("bearer");
17+
}
18+
@Bean
19+
public OpenAPI openAPI(){
20+
return new OpenAPI().addSecurityItem(new SecurityRequirement().addList("JWT"))
21+
.components(new Components().addSecuritySchemes("JWT", createAPIKeyScheme()))
22+
.info(apiInfo());
23+
}
24+
25+
private Info apiInfo() {
26+
return new Info()
27+
.title("BloomGroom API") // API의 제목
28+
.description("BloomGroom에 대한 api입니다.") // API에 대한 설명
29+
.version("1.0.0"); // API의 버전
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.bloomgroom.global.config;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7+
8+
@Configuration
9+
public class WebMvcConfig implements WebMvcConfigurer {
10+
11+
private final long MAX_AGE_SECS = 3600;
12+
13+
@Value("${app.cors.allowed-origins}")
14+
private String[] allowedOrigins;
15+
16+
@Override
17+
public void addCorsMappings(CorsRegistry registry) {
18+
registry.addMapping("/**")
19+
.allowedOrigins(allowedOrigins)
20+
.allowedOriginPatterns()
21+
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
22+
.allowedHeaders("*")
23+
.allowCredentials(true)
24+
.maxAge(MAX_AGE_SECS);
25+
}
26+
}

0 commit comments

Comments
 (0)