Skip to content

Commit e9bead8

Browse files
committed
chore: add AWS_S3_KEY_PREFIX environment variable support.
1 parent 13db771 commit e9bead8

File tree

9 files changed

+46
-11
lines changed

9 files changed

+46
-11
lines changed

.env.example

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# -------------------------------
66
# General / Logs
77
# -------------------------------
8-
# 클론시 유일한 환경변수 값
8+
# 클론시 유일한 환경변수 값 (*)
99
COMPOSE_PROJECT_NAME=code-push-server
1010
LOG_LEVEL=debug
1111
LOG_FORMAT=text
1212

1313
# -------------------------------
14-
# Database (MySQL)
14+
# Database (MySQL) (*)
1515
# - 유저/앱/패키지 메타데이터 저장
1616
# -------------------------------
1717
RDS_USERNAME=codepush
@@ -21,12 +21,12 @@ RDS_HOST=127.0.0.1
2121
RDS_PORT=3306
2222

2323
# -------------------------------
24-
# Storage Settings
24+
# Storage Settings (*)
2525
# storageType: local | s3 | qiniu | oss | tencentcloud
2626
# -------------------------------
2727
STORAGE_TYPE=local
2828

29-
# Local storage (default)
29+
# Local storage (default) (*)
3030
# 저장 파일이 위치할 경로 (미설정 시 OS tmpdir 사용)
3131
STORAGE_DIR=./storage
3232

@@ -38,22 +38,25 @@ LOCAL_DOWNLOAD_URL=http://127.0.0.1:3000/download
3838
DOWNLOAD_URL=http://127.0.0.1:3000/download
3939

4040
# -------------------------------
41-
# JWT Token
41+
# JWT Token (*)
4242
# -------------------------------
4343
TOKEN_SECRET=REPLACE_WITH_RANDOM_LONG_SECRET
4444

4545
# -------------------------------
46-
# Common Behavior
46+
# Common Behavior
4747
# -------------------------------
48+
# 프로덕션 배포 및 계정생성 후 false 로 수정
4849
ALLOW_REGISTRATION=true
4950
TRY_LOGIN_TIMES=4
5051
DIFF_NUMS=3
51-
DATA_DIR=./data
52+
# DATA_DIR=./data
53+
# 클라우드 배포시 보통 data 디렉토리에 쓰기 권한이 없음
54+
DATA_DIR=
5255
UPDATE_CHECK_CACHE=false
5356
ROLLOUT_CLIENT_UNIQUE_ID_CACHE=false
5457

5558
# -------------------------------
56-
# Redis (optional: only needed for login attempt limit or caching)
59+
# Redis (optional: only needed for login attempt limit or caching) (*)
5760
# -------------------------------
5861
REDIS_HOST=127.0.0.1
5962
REDIS_PORT=6379
@@ -77,12 +80,15 @@ QINIU_SECRET_KEY=
7780
QINIU_BUCKET_NAME=
7881
QINIU_DOWNLOAD_URL=
7982

83+
# AWS IAM - admin_codepush with the customS3BucketAccessForCodePush policy (*)
8084
AWS_ACCESS_KEY_ID=
8185
AWS_SECRET_ACCESS_KEY=
8286
AWS_SESSION_TOKEN=
8387
AWS_BUCKET_NAME=
8488
AWS_REGION=
8589
AWS_DOWNLOAD_URL=
90+
# 버킷내 경로 프리픽스 (optional)
91+
AWS_S3_KEY_PREFIX=codepush/
8692

8793
OSS_ACCESS_KEY_ID=
8894
OSS_SECRET_ACCESS_KEY=

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ node_modules/
1919
.idea
2020

2121
# environment variables
22-
.env
22+
!.env.example
23+
.env
24+
.env.*

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm start

README.ko.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Microsoft 공식 CodePush 서비스는 아시아 지역에서 속도가 느린
1111

1212
- Node.js v24.6.0
1313
- npm install -g install @shm-open/code-push-cli
14+
- data, storage 이름으로 디렉토리 생성후 서버 구동
1415

1516
## 이 포크(Fork)에 대하여
1617

data/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

src/core/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const config = {
5353
region: process.env.AWS_REGION,
5454
// binary files download host address.
5555
downloadUrl: process.env.AWS_DOWNLOAD_URL || process.env.DOWNLOAD_URL,
56+
prefix: process.env.AWS_S3_KEY_PREFIX, // (optional)
5657
},
5758
// Config for Aliyun OSS (https://www.aliyun.com/product/oss) when storageType value is "oss".
5859
oss: {

src/core/utils/storage.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ function uploadFileToLocal(key: string, filePath: string, logger: Logger): Promi
7878
function uploadFileToS3(key: string, filePath: string, logger: Logger): Promise<void> {
7979
return new Promise((resolve, reject) => {
8080
logger.info('try uploadFileToS3', { key });
81+
82+
// config.s3.prefix에서 prefix 읽기
83+
let prefix = _.get(config, 's3.prefix', '') as string | undefined;
84+
prefix = (prefix || '').trim();
85+
86+
if (prefix.length > 0 && !prefix.endsWith('/')) {
87+
prefix += '/';
88+
}
89+
90+
const finalKey = prefix ? `${prefix}${key}` : key;
91+
logger.info('uploadFileToS3 resolved finalKey', { key: finalKey });
92+
8193
AWS.config.update({
8294
accessKeyId: _.get(config, 's3.accessKeyId'),
8395
secretAccessKey: _.get(config, 's3.secretAccessKey'),
@@ -92,7 +104,7 @@ function uploadFileToS3(key: string, filePath: string, logger: Logger): Promise<
92104
}
93105
s3.upload(
94106
{
95-
Key: key,
107+
Key: finalKey, // prefix 적용된 key
96108
Body: data,
97109
ACL: 'public-read',
98110
Bucket: _.get(config, 's3.bucketName'),
@@ -101,7 +113,7 @@ function uploadFileToS3(key: string, filePath: string, logger: Logger): Promise<
101113
if (error) {
102114
reject(new AppError(error));
103115
} else {
104-
logger.info('uploadFileToS3 success', { key });
116+
logger.info('uploadFileToS3 success', { key: finalKey });
105117
resolve();
106118
}
107119
},

storage/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!README.md
3+
!.gitignore

storage/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## 다운로드 에셋 저장용 디렉토리
2+
3+
- storageType = 'local' 한정 사용
4+
- 런타임 오류 해결용
5+
```
6+
[dev:run] level=error, time=2025-11-16 14:34:04.503, msg=Please create dir ./storage, name=Error, stack=Error: Please create dir ./storage
7+
```

0 commit comments

Comments
 (0)