Recently, I start NestJS project with PNPM.
every steps are very okay but when I deploy project to EC2 I got this AWS CodeDeploy Error
as you can see my EC2 storage got full.
this problem happened every CodeDeploy install event hook...
this is a CI/CD
strategy.
CI with GitAction
-> build
-> compress tar.gz
-> upload S3
-> call CodeDeploy
-> PM2 Deploy
this image is CodeDeployAgent auto decompression tar file form deployment-root
when code deploy execute install event hook the node_modules file size are way bigger than before like this..
inside of node_modules every dependency reinstall they are dependencies.
ex) node_modules 1.5G
- .pnpm 1.5G
- lib 1
- node_modules 500M ..
- lib 2
- node_modules 500M ..
- lib 3
- node_modules 500M ..
...
this is part of GitAction workflow
...
build:
name: Build & S3 Upload
needs: dependency_install
runs-on: ubuntu-latest
strategy:
matrix:
pnpm-version: [ 7.x ]
node-version: [ 18.12.x ]
steps:
- uses: actions/checkout@v3
- name: Setup Environments
uses: ./.github/actions/setup
- name: Use pnpm ${{ matrix.pnpm-version }}
uses: pnpm/action-setup@v2
with:
version: ${{ matrix.pnpm-version }}
- name: Use Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Check dependency cache
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/node_modules
${{ github.workspace }}/common/*/node_modules
${{ github.workspace }}/apps/${{env.SERVICE}}/node_modules
key: ${{ needs.dependency_install.outputs.dependency_cache_key }}
- name: Build
run: pnpm build:${{ env.SERVICE }}
- name: Remove DevDependencies
run: pnpm install --production
- name: AWS access registration
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_IAM_MANAGE_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_IAM_MANAGE_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: add .env
run: aws s3 cp s3://${{env.BUCKET}}/env/.env.${{ env.TARGET_ENVIRONMENT }} ./
- name: tar compress
run: tar -cpzf ./build.tgz --files-from='tar_include.txt' apps/${{ env.SERVICE }}/ecosystem.config.js apps/${{ env.SERVICE }}/dist apps/${{ env.SERVICE }}/node_modules apps/${{ env.SERVICE }}/package.json .env.*
shell: bash
- name: S3 Upload
run: aws s3 cp --region ap-northeast-2 ./build.tgz s3://${{env.BUCKET}}/${{env.TARGET_ENVIRONMENT}}/build.tgz
deploy:
name: Deploy
needs: [test, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Environments
uses: ./.github/actions/setup
- name: AWS access registration
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_IAM_MANAGE_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_IAM_MANAGE_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Code Deploy
run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --file-exists-behavior OVERWRITE --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name ${{env.BUCKET}}-${{env.TARGET_ENVIRONMENT}} --s3-location bucket=$BUCKET,bundleType=tgz,key=${{env.TARGET_ENVIRONMENT}}/build.tgz
...
appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/app/my-project
overwrite: yes
permissions:
- object: /home/ubuntu/app/my-project
owner: ubuntu
group: ubuntu
mode: 755
hooks:
BeforeInstall:
- location: scripts/beforeInstall.sh
timeout: 120
runas: ubuntu
AfterInstall:
- location: scripts/deploy.sh
timeout: 180
runas: ubuntu
beforeInstall.sh
#!/bin/bash
REPOSITORY=/home/ubuntu/app/my-project
if [ -d $REPOSITORY ]; then
rm -rf $REPOSITORY
fi
mkdir -vp $REPOSITORY
how come node_modules storage size bigger and is there any solution to deploy project?
thank you!