Skip to content

Commit

Permalink
chore: 개발 서버 이전 #551 (#557)
Browse files Browse the repository at this point in the history
* chore: dev cd workflow 수정

* chore: log 파일 저장 경로 오류 수정

Co-authored-by: YoonJuHo <[email protected]>, BurningFalls <[email protected]>

* refactor: 서버 이전에 따른 S3 설정 변경

Co-authored-by: BurningFalls <[email protected]>, YoonJuHo <[email protected]>

* refactor: 서버 이전에 따른 S3 폴더 경로 수정

Co-authored-by: BurningFalls <[email protected]>, YoonJuHo <[email protected]>

* chore: gradle 캐싱 적용

Co-authored-by: BurningFalls <[email protected]>, YoonJuHo <[email protected]>

* chore: gradle 캐싱 적용

Co-authored-by: YoonJuHo <[email protected]>, BurningFalls <[email protected]>

* chore: 도커 이미지 제거 명령어 추가

Co-authored-by: YoonJuHo <[email protected]>, BurningFalls <[email protected]>

---------

Co-authored-by: YoonJuHo <[email protected]>, BurningFalls <[email protected]>
Co-authored-by: BurningFalls <[email protected]>, YoonJuHo <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent d5c83b2 commit 7730421
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 45 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/backend-ci-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew

Expand Down Expand Up @@ -58,16 +68,9 @@ jobs:
sudo docker login --username ${{ secrets.DOCKERHUB_DEPLOY_USERNAME }} --password ${{ secrets.DOCKERHUB_DEPLOY_TOKEN }}
sudo docker pull staccato/staccato:dev
- name: Stop and remove existing container
run: |
sudo docker stop staccato-backend-app || true
sudo docker rm staccato-backend-app || true
- name: Docker Compose up
run: sudo docker-compose -f /home/ubuntu/staccato/docker-compose.yml up -d

- name: Docker run
run: |
sudo docker run --env-file /home/ubuntu/staccato/.env \
-v /home/ubuntu/staccato/logs:/logs \
-p 8080:8080 \
-d --name staccato-backend-app staccato/staccato:dev
sudo docker image prune -af
- name: Docker image Prune
run: sudo docker image prune -af

10 changes: 10 additions & 0 deletions .github/workflows/backend-ci-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
Expand All @@ -20,11 +20,14 @@ public class S3ObjectClient {
public S3ObjectClient(
@Value("${cloud.aws.s3.bucket}") String bucketName,
@Value("${cloud.aws.s3.endpoint}") String endPoint,
@Value("${cloud.aws.cloudfront.endpoint}") String cloudFrontEndPoint
@Value("${cloud.aws.cloudfront.endpoint}") String cloudFrontEndPoint,
@Value("${cloud.aws.access-key}") String accessKey,
@Value("${cloud.aws.secret-access-key}") String secretAccessKey
) {
this.s3Client = software.amazon.awssdk.services.s3.S3Client.builder()
AwsBasicCredentials awsCredentials = AwsBasicCredentials.create(accessKey, secretAccessKey);
this.s3Client = S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
.region(Region.AP_NORTHEAST_2)
.credentialsProvider(InstanceProfileCredentialsProvider.create())
.build();
this.bucketName = bucketName;
this.endPoint = endPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
@Service
@RequiredArgsConstructor
public class ImageService {
private static final String TEAM_FOLDER_NAME = "staccato/";
private final S3ObjectClient s3ObjectClient;
@Value("${image.folder.name}")
private String imageFolderName;

public ImageUrlResponse uploadImage(MultipartFile image) {
String imageExtension = getImageExtension(image);
String key = TEAM_FOLDER_NAME + imageFolderName + UUID.randomUUID() + imageExtension;
String key = imageFolderName + UUID.randomUUID() + imageExtension;
String contentType = ImageExtension.getContentType(imageExtension);
byte[] imageBytes = getImageBytes(image);

Expand Down
12 changes: 7 additions & 5 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ security:
token: ${ADMIN_TOKEN}
cloud:
aws:
access-key: ${AWS_ACCESS_KEY}
secret-access-key: ${AWS_SECRET_ACCESS_KEY}
s3:
bucket: techcourse-project-2024
endpoint: https://techcourse-project-2024.s3.ap-northeast-2.amazonaws.com
bucket: ${AWS_S3_BUCKET}
endpoint: ${AWS_S3_ENDPOINT}
cloudfront:
endpoint: https://d25aribbn0gp8k.cloudfront.net
endpoint: ${AWS_CLOUDFRONT_ENDPOINT}
region:
static: ap-northeast-2
static: ${AWS_REGION_STATIC}
stack:
auto: false
image:
folder:
name: image/
name: dev/

management:
server:
Expand Down
12 changes: 7 additions & 5 deletions backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ security:
token: ${ADMIN_TOKEN}
cloud:
aws:
access-key: accessKey
secret-access-key: secretAccessKey
s3:
bucket: techcourse-project-2024
endpoint: https://techcourse-project-2024.s3.ap-northeast-2.amazonaws.com
bucket: bucket
endpoint: endpoint
cloudfront:
endpoint: https://d25aribbn0gp8k.cloudfront.net
endpoint: endpoint
region:
static: ap-northeast-2
static: static
stack:
auto: false
image:
folder:
name: image/
name: local/

management:
server:
Expand Down
4 changes: 3 additions & 1 deletion backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ security:
token: ${ADMIN_TOKEN}
cloud:
aws:
access-key: ${AWS_ACCESS_KEY}
secret-access-key: ${AWS_SECRET_ACCESS_KEY}
s3:
bucket: ${AWS_S3_BUCKET}
endpoint: ${AWS_S3_ENDPOINT}
Expand All @@ -76,7 +78,7 @@ cloud:
auto: false
image:
folder:
name: image-prod/
name: prod/

management:
server:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/error-appender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] [%thread] [request_id=%X{request_id:-startup}] %-5level [%C.%M.-%L] - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>./backup/error/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>./logs/error/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>15</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/info-appender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] [%thread] [request_id=%X{request_id:-startup}] %-5level - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>./backup/info/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>./logs/info/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>15</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
Expand Down
12 changes: 0 additions & 12 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
</root>
</springProfile>

<springProfile name="stage">
<include resource="error-appender.xml"/>
<include resource="warn-appender.xml"/>
<include resource="info-appender.xml"/>

<root level="info">
<appender-ref ref="INFO"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="WARN"/>
</root>
</springProfile>

<springProfile name="prod">
<include resource="error-appender.xml"/>
<include resource="warn-appender.xml"/>
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/warn-appender.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] [%thread] [request_id=%X{request_id:-startup}] %-5level [%C.%M.-%L] - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>./backup/warn/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>./logs/warn/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>15</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class FakeS3ObjectClient extends S3ObjectClient {
public FakeS3ObjectClient() {
super("fakeBuket", "fakeEndPoint", "fakeCloudFrontEndPoint");
super("fakeBuket", "fakeEndPoint", "fakeCloudFrontEndPoint", "fakeAccessKey", "fakeSecretAccessKey");
}

@Override
Expand Down

0 comments on commit 7730421

Please sign in to comment.