Skip to content

Commit 53c599c

Browse files
committed
Setup github actions for stage/prod
1 parent 93ce716 commit 53c599c

File tree

7 files changed

+94
-7
lines changed

7 files changed

+94
-7
lines changed

.github/workflows/dev.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy Serverless SSR (Dev)
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
deploy:
10+
name: deploy
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Get yarn cache
15+
id: yarn-cache
16+
run: echo "::set-output name=dir::$(yarn cache dir)"
17+
18+
- uses: actions/cache@v1
19+
with:
20+
path: ${{ steps.yarn-cache.outputs.dir }}
21+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
22+
restore-keys: |
23+
${{ runner.os }}-yarn-
24+
- name: yarn install
25+
uses: borales/[email protected]
26+
with:
27+
cmd: install
28+
- name: npm run build:ci
29+
run: npm run build:ci
30+
env:
31+
REACT_APP_API_HOST: 'https://v2dev.velog.io/'
32+
PUBLIC_URL: 'https://d3v0gm8v6v8olv.cloudfront.net/'
33+
STAGE: true
34+
- name: s3 sync
35+
uses: jakejarvis/s3-sync-action@master
36+
with:
37+
args: --follow-symlinks --delete
38+
env:
39+
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_DEV }}
40+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
41+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
42+
AWS_REGION: 'ap-northeast-2'
43+
SOURCE_DIR: 'build'
44+
45+
- name: serverless deploy
46+
uses: serverless/github-action@master
47+
with:
48+
args: deploy --stage production
49+
env:
50+
# or if using AWS creds directly
51+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
52+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
53+
REACT_APP_API_HOST: 'https://v2dev.velog.io/'
54+
PUBLIC_URL: 'https://d3v0gm8v6v8olv.cloudfront.net/'
55+
STAGE: true
56+
- name: Deploy Completion Webhook
57+
uses: joelwmale/webhook-action@master
58+
env:
59+
WEBHOOK_URL: ${{ secrets.SSR_COMPLETE_WEBHOOK }}
60+
data: "{'deployment': 'finished'}"
61+
- name: Slack Notification
62+
uses: rtCamp/[email protected]
63+
env:
64+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
65+
SLACK_USERNAME: 'Github Actions'
66+
SLACK_ICON: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
67+
SLACK_MESSAGE: '벨로그 웹 클라이언트 배포가 끝났어요! :rocket:'

.github/workflows/main.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
cmd: install
2828
- name: npm run build:ci
2929
run: npm run build:ci
30+
env:
31+
REACT_APP_API_HOST: 'https://v2dev.velog.io/'
32+
PUBLIC_URL: 'https://static.velog.io/'
3033
- name: s3 sync
3134
uses: jakejarvis/s3-sync-action@master
3235
with:
@@ -41,11 +44,13 @@ jobs:
4144
- name: serverless deploy
4245
uses: serverless/github-action@master
4346
with:
44-
args: deploy
47+
args: deploy --stage production
4548
env:
4649
# or if using AWS creds directly
4750
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
4851
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
52+
REACT_APP_API_HOST: 'https://v2dev.velog.io/'
53+
PUBLIC_URL: 'https://static.velog.io/'
4954
- name: Deploy Completion Webhook
5055
uses: joelwmale/webhook-action@master
5156
env:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
"build:server": "node scripts/build.server.js",
155155
"start:server:local": "node ./dist/server.js",
156156
"test": "node scripts/test.js",
157-
"download:stats": "curl -o ./build/loadable-stats.json \"https://static.velog.io/loadable-stats.json\" --create-dirs"
157+
"upload:s3": "aws s3 sync ./build s3://$S3_BUCKET --delete"
158158
},
159159
"eslintConfig": {
160160
"extends": [

scripts/activate

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
export PUBLIC_URL=https://static.velog.io/
3+
export REACT_APP_API_HOST=https://v2.velog.io/
4+
export S3_BUCKET=static.velog.io

scripts/activate.dev

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
export PUBLIC_URL=https://d3v0gm8v6v8olv.cloudfront.net/
3+
export REACT_APP_API_HOST=https://v2dev.velog.io/
4+
export STAGE=true
5+
export S3_BUCKET=dev.static.velog.io

scripts/keepChunks.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ const assetHistoryDir = path.join(buildDir, 'asset-history.json');
1414
const readFileAsync = promisify(fs.readFile);
1515
const writeFileAsync = promisify(fs.writeFile);
1616

17+
function replaceLastSlash(url) {
18+
if (url.charAt(url.length - 1) === '/') {
19+
return url.slice(0, url.length - 1);
20+
}
21+
return url;
22+
}
23+
const PUBLIC_URL = replaceLastSlash(process.env.PUBLIC_URL);
24+
1725
/**
1826
* Loads current asset-history from CDN
1927
*/
2028
async function getAssetHistory() {
2129
try {
22-
const response = await client.get(
23-
'https://static.velog.io/asset-history.json',
24-
);
30+
const response = await client.get(`${PUBLIC_URL}/asset-history.json`);
2531
return response.data;
2632
} catch (e) {
2733
return {
@@ -68,8 +74,7 @@ function downloadUrls(urls) {
6874
urls.map(url => {
6975
const downloadPath = url
7076
.slice(0, url.lastIndexOf('/'))
71-
.replace('https://static.velog.io', '');
72-
77+
.replace(PUBLIC_URL, '');
7378
return download(url, path.join(buildDir, downloadPath));
7479
}),
7580
);

serverless.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ provider:
4848
environment:
4949
REDIS_HOST: ${ssm:/velog-v2/redis-host}
5050
DEBUG: ioredis:*
51+
STAGE: ${env:STAGE}
5152

5253
vpc:
5354
securityGroupIds:

0 commit comments

Comments
 (0)