Merge pull request #302 from ODOICHON/fix/#301 #85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
on: | |
push: | |
branches: ['main', 'develop'] | |
env: | |
PROJECT_NAME: duaily-client | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code. # Repo checkout | |
uses: actions/checkout@v2 | |
- name: Check Node v # Node v ํ์ธ | |
run: node -v | |
- name: Cache node modules # node modules ์บ์ฑ | |
uses: actions/cache@v1 | |
with: # with ๊ตฌ๋ฌธ์ผ๋ก ์ค์ ํ ์ ์๋๋ฐ, path์ key๋ฅผ ๋ฐ๋์ ์ค์ ํด์ฃผ์ด์ผ ํจ | |
path: node_modules # ์ ์ฅํ๊ณ ๋ถ๋ฌ์ฌ ์บ์ ๋์ ํด๋ | |
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }} # ์ ์ฅํ๊ณ ๋ถ๋ฌ์ฌ ๋ ์๋ณํ ์ ์๋ ํค ๊ฐ | |
restore-keys: | |
| # ์บ์ key๊ฐ ์ผ์นํ๋ ๊ฒ์ด ์์ ๋, ์ฐจ์ ํ์ผ๋ก ์บ์ฑ ํด๋๋ฅผ ์ฐพ๋ key | |
${{ runner.OS }}-build- | |
${{ runner.OS }}- | |
- name: Install Dependencies # ์์กด ํ์ผ ์ค์น | |
run: yarn install --frozen-lockfile | |
- name: Setting .env (Dev) # ํ๊ฒฝ๋ณ์ ์ธํ (DEV) | |
if: contains(github.ref, 'develop') | |
run: echo "${{ secrets.REACT_ENV_DEV }}" >> .env | |
- name: Setting .env (Prod) # ํ๊ฒฝ๋ณ์ ์ธํ (PROD) | |
if: contains(github.ref, 'main') | |
run: | | |
echo "${{ secrets.REACT_ENV }}" >> .env | |
- name: Build # React Build | |
run: yarn build | |
- name: Modify appspec.yml (Dev) | |
if: contains(github.ref, 'develop') | |
run: | | |
sed -i "s|destination: /home/filename/client|destination: /home/${{ secrets.APPSPEC_FILES_FILENAME_DEV }}/client|g" appspec.yml | |
sed -i "s|owner: owner|owner: ${{ secrets.APPSPEC_PERMISSIONS_OWNER_DEV }}|g" appspec.yml | |
sed -i "s|group: group|group: ${{ secrets.APPSPEC_PERMISSIONS_GROUP_DEV}}|g" appspec.yml | |
- name: Modify appspec.yml (Prod) | |
if: contains(github.ref, 'main') | |
run: | | |
sed -i "s|destination: /home/filename/client|destination: /home/${{ secrets.APPSPEC_FILES_FILENAME }}/client|g" appspec.yml | |
sed -i "s|owner: owner|owner: ${{ secrets.APPSPEC_PERMISSIONS_OWNER }}|g" appspec.yml | |
sed -i "s|group: group|group: ${{ secrets.APPSPEC_PERMISSIONS_GROUP}}|g" appspec.yml | |
- name: zip create # zip ํ์ผ์ ๋ง๋ญ๋๋ค | |
run: zip -r ./$GITHUB_SHA.zip ./dist appspec.yml | |
shell: bash | |
- name: Configure AWS credentials (Dev) # AWS ์ธํ (DEV) | |
if: contains(github.ref, 'develop') | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} | |
aws-region: ${{ secrets.AWS_REGION_DEV }} | |
- name: Configure AWS credentials (Prod) # AWS ์ธํ (PROD) | |
if: contains(github.ref, 'main') | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Upload to S3 (Dev) # S3์ ํ์ผ ์ ๋ก๋ (DEV) | |
if: contains(github.ref, 'develop') | |
run: aws s3 cp --region ${{ secrets.S3_REGION_DEV }} ./$GITHUB_SHA.zip s3://${{ secrets.S3_BUCKET_NAME_DEV }}/$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Upload to S3 (Prod) # S3์ ํ์ผ ์ ๋ก๋ (PROD) | |
if: contains(github.ref, 'main') | |
run: aws s3 cp --region ${{ secrets.S3_REGION }} ./$GITHUB_SHA.zip s3://${{ secrets.S3_BUCKET_NAME }}/$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Code Deploy (Dev) # CodeDeploy ๋ฐฐํฌ (DEV) | |
if: contains(github.ref, 'develop') | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ secrets.DEPLOY_APPLICATION_NAME_DEV }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ secrets.DEPLOY_GROUP_DEV }} \ | |
--s3-location bucket=${{ secrets.S3_BUCKET_NAME_DEV }},bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Code Deploy (Prod) # CodeDeploy ๋ฐฐํฌ (PROD) | |
if: contains(github.ref, 'main') | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ secrets.DEPLOY_APPLICATION_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ secrets.DEPLOY_GROUP }} \ | |
--s3-location bucket=${{ secrets.S3_BUCKET_NAME }},bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip |