-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (108 loc) · 3.74 KB
/
frontendCICD.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI/CD
on:
push:
branches: [ "infra" ]
pull_request:
branches: [ "infra" ]
permissions:
contents: read
jobs: # job 설정
react: # job id
name: 리액트 build & deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./fe # 기본 워킹 디렉토리 설정
steps:
- name: checkout Github Action
uses: actions/checkout@v3 # github actions 가상 환경에 해당 레포 소스 가져오기
- name: install npm dependencies
run: npm install
- name: React build
run: npm run build
# aws user 연결
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY_ID }}
aws-region: ap-northeast-2
# react 빌드한 /build를 s3로 업로드
- name: Upload to S3
env:
BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME}}
run: |
aws s3 sync \
./build s3://$BUCKET_NAME
# 업로드한 s3 파일을 각 CDN 캐시 무효화하여 리프레시 하기
- name: CloudFront Invalidation
env:
CLOUD_FRONT_ID: ${{ secrets.AWS_CLOUDFRONT_ID}}
run: |
aws cloudfront create-invalidation \
--distribution-id $CLOUD_FRONT_ID --paths /*
#jobs:
# build:
# runs-on: ubuntu-latest
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: ${{ secrets.AWS_REGION }}
#
# steps:
# - name: Checkout source code.
# uses: actions/checkout@master
#
# - name: Upload binary to S3 bucket
# uses: jakejarvis/s3-sync-action@master
# with:
# args: --acl public-read --exclude '*' --include 'index.html'
# env:
# AWS_S3_BUCKET: ${{ secrets.BUCKET_NAME }}
#
# - name: Invalidate cache CloudFront
# uses: chetan/invalidate-cloudfront-action@master
# env:
# AWS_DISTRIBUTION_ID: ${{ secrets.AWS_DISTRIBUTION_ID }}
# PATHS: '/index.html'
# continue-on-error: true
#jobs:
# build:
#
# runs-on: ubuntu-latest
#
# strategy:
# matrix:
# node-version: [18.17.1]
# # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
#
# steps:
# - uses: actions/checkout@v3
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'npm'
# cache-dependency-path: ./fe/package-lock.json
#
# - name: build
# working-directory: ./fe
# run: |
# npm install
# npm run build
# npm test
#
# - name: S3 Deploy
# run: aws s3 sync ./build s3://csr-test-1-bucket/ --acl bucket-owner-full-control # 현재 build된 폴더에 접근 후 s3 버킷인 csr-test-1-bucket에 파일 업로드
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: ${{ secrets.AWS_REGION }}
# - name: Invalidate CloudFront Cache # 새로 리소스를 업데이트할 때 기존 캐시 무효화
# uses: chetan/invalidate-cloudfront-action@master
# env:
# AWS_DISTRIBUTION: ${{ secrets.AWS_DISTRIBUTION_ID }}
# PATHS: '/index.html'
# continue-on-error: true