For deploying an node.js app with CodePipepline, here are the templates for config files:
appspec.yml:
version: 0.0
os: linux
files:
- source: /
destination: /var/roger_server #where to store the artifacts
hooks:
AfterInstall:
- location: bin/npm_install.sh
runas: root
timeout: 300
ApplicationStart:
- location: bin/npm_start.sh #start script for the server
timeout: 10
runas: root
bin/npm_install.sh:
#!/bin/bash
cd /var/roger_server
npm install
bin/npm_start.sh:
#!/bin/bash
#[ -s "/.nvm/nvm.sh" ] && \. "/.nvm/nvm.sh"
killall node
cd /var/roger_server
# npm run prod
nohup npm run prod > /dev/null 2>&1 &
buildspec.yml:
# Do not change version. This is the version of aws buildspec, not the version of your buldspec file.
version: 0.2phases:
post_build:
commands:
- echo Build completed on `date`
# Include only the files required for your application to run.
# Do not use recursively include artifacts from node_modules directory as it will include unnecessary packages
# used only for building and testing.
# ExpressJS apps will need other artifact directories included (bin/*, public/*, routes/*, views/* etc).
artifacts:
files:
- '**/*'
tip: use a yaml beautifier