클라이언트 배포자동화 .env파일 추가하는방법

박진현·2021년 12월 23일
0

에러핸들링

목록 보기
22/28
name: deploy-to-lumiereClientS3

on:
  push:
    branches: [dev]

jobs:
  build:
    runs-on: ubuntu-18.04
    steps:
      - name: git clone
        uses: actions/checkout@v2

      # - name : add Env
        # run: |
        #   echo "REACT_APP_ACCESS_ID=$REACT_APP_ACCESS_ID" >> .env
        #   echo "REACT_APP_ACCESS_KEY=$REACT_APP_ACCESS_KEY" >> .env
        #   echo "REACT_APP_BUCKET_NAME=$REACT_APP_BUCKET_NAME" >> .env
        #   echo "REACT_APP_REGION=$REACT_APP_REGION" >> .env
        #   echo "REACT_APP_REDIRECT_URI=$REACT_APP_REDIRECT_URI" >> .env
        #   echo "REACT_APP_KAKAO=$REACT_APP_KAKAO" >> .env
        #   echo "REACT_APP_IMPORT=$REACT_APP_IMPORT" >> .env
        #   echo "REACT_APP_IMPORT_REST_API=$REACT_APP_IMPORT_REST_API" >> .env
        #   echo "REACT_APP_IMPORT_REST_API_SECRET=$REACT_APP_IMPORT_REST_API_SECRET" >> .env
        #   echo "GENERATE_SOURCEMAP=false >> .env
      - name: npm install for eslint
        run: npm install

      - name: npm install
        run: npm install
        working-directory: ./client

      - name: build
        env:
          REACT_APP_ACCESS_ID: ${{ secrets.REACT_APP_ACCESS_ID }}
          REACT_APP_ACCESS_KEY: ${{ secrets.REACT_APP_ACCESS_KEY }}
          REACT_APP_BUCKET_NAME: ${{ secrets.REACT_APP_BUCKET_NAME }}
          REACT_APP_REGION: ${{ secrets.REACT_APP_REGION }}
          REACT_APP_REDIRECT_URI: ${{ secrets.REACT_APP_REDIRECT_URI }}
          REACT_APP_KAKAO: ${{ secrets.REACT_APP_KAKAO }}
          REACT_APP_IMPORT: ${{ secrets.REACT_APP_IMPORT }}
          REACT_APP_IMPORT_REST_API: ${{ secrets.REACT_APP_IMPORT_REST_API }}
          REACT_APP_IMPORT_REST_API_SECRET: ${{ secrets.REACT_APP_IMPORT_REST_API_SECRET }}
        run: CI='' npm run build
        working-directory: ./client

      # - name: ls in client
      #   run: ls -la
      #   working-directory: ./client

      # - name: ls in build
      #   run: ls -la
      #   working-directory: ./client/build

      # - name: pwd in build
      #   run: pwd
      #   working-directory: ./client/build

      # - name: test aws
      #   run: aws configure list

      # - name: deploy
      #   env:
      #     AWS_ACCESS_KEY_ID: '${{ secrets.AWS_ACCESS_KEY_ID }}'
      #     AWS_SECRET_ACCESS_KEY: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
      #   run: |
      #     aws s3 cp \
      #       --recursive \
      #       --region ap-northeast-2 \
      # /home/runner/work/Lumiere/Lumiere/client/build s3://www.lumieregallery.site

      - name: Transfer to S3 for serving static
        uses: jakejarvis/s3-sync-action@master
        with:
          args: --acl public-read --follow-symlinks --delete
        env:
          AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_IAM_MANAGER_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_IAM_MANAGER_SECRET_ACCESS_KEY }}
          AWS_REGION: ${{ secrets.AWS_BUCKET_REGION }}
          SOURCE_DIR: '/home/runner/work/Lumiere/Lumiere/client/build'

      # - name: Add profile credentials to ~/.aws/credentials
      #   run: |
      #       aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --profile www.lumieregallery.site
      #       aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile www.lumieregallery.site
      # - name: aws configure test
      #   run: aws configure list
      #   env:
      #     AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
      #     AWS_ACCESS_KEY_ID: ${{ secrets.AWS_IAM_MANAGER_KEY_ID }}
      #     AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_IAM_MANAGER_SECRET_ACCESS_KEY }}
      #     AWS_REGION: ${{ secrets.AWS_BUCKET_REGION }}
      - name: 캐시 무효화
        env:
          AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_IAM_MANAGER_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_IAM_MANAGER_SECRET_ACCESS_KEY }}
          AWS_REGION: ${{ secrets.AWS_BUCKET_REGION }}
        run: aws cloudfront create-invalidation --distribution-id=E8FWNYKAA3DOV --paths "/*"
        # aws cloudfront create-invalidation --distribution-id distribution_ID --paths "/*"

처음엔 add Env란에 있는 것 처럼
echo '변수명=$환경변수명' >> .env 로 했었는데 안되길래
위에처럼 빌드할때 밑에다가 env 로 적어주면 될 것 같아서 해봤더니 되었다. (여기서 중요한건 run위에 env를 설정해줘야 한다는거!)

profile
👨🏻‍💻 호기심이 많고 에러를 좋아하는 프론트엔드 개발자 박진현 입니다.

0개의 댓글