Due to cost I am using a EC-2 where both production and staging reside upon seperate vhosts:
- For Staging I use the following files:
- Nginx Vhost: /etc/nginx/sites-available/staging.conf
- WWW Root: /var/www/staging
- For Production I use the following files:
- Nginx Vhost: /etc/nginx/sites-available/production.conf
- WWW Root: /var/www/production
For my deployment I use a single codeploy app but a seperate deployment group for each environment. And my appspec.yml is:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/staging
hooks:
ApplicationStop:
- location: deploy/application-stop.sh
runas: root
BeforeInstall:
- location: deploy/clean-files.sh
runas: root
AfterInstall:
- location: deploy/install_app.sh
runas: root
ApplicationStart:
- location: deploy/application-start.sh
runas: root
How I can specify the nessesary deployment path based upon the deployment group. Is there a way to have parameterized deployment so I can set the nessesary paths where app will be deployed upon?
An approach I followed is the follwing:
Upon build step I defined a plaintext environmental variable named
ENVIRONMENTthen yupon my build step I did the following (I use aws codebuild):And I placed 2 appspec files:
appspec.production.ymlappspec.staging.ymlAnd upon
ENVIRONMENTvariable I place the appropriate value:productionfor productionstagingfor stagingThen upon my deployed artifacts in my buildspec I placed:
Furthermore In my case each appspec retrieves the nessesary webhook scripts from the following folders:
deploy/productionfor productiondeploy/stagingfor stagingThen upon scripts and the seperate appspec files I place the correct paths for vhost and where app will be deployed upon. I same do upon each script in
deployfolder.For a new environment (named
development) I can:ENVIRONMENTintodevelopmentTo sum up the idea is to use multiple appspec files with a naming convention and copy the correct one into ethe epxected
appspec.ymlfile. Then upon each appspec and webhook script I place the correct paths for vhost and application.Note:
For the build scripts, I think I could have each script load a config file or
sourcea config script that uses the existing environmental variables in order to load the appropriate values. But I have not tested yet.