Answers: <p>We do this at work.</p>
  
  <p>We have a small server, let's call it the receiver, it's the target of the <a href="https://developer.github.com/webhooks/" rel="noreferrer">GitHub webhook events</a>. It runs a small application that parses the payload and incorporates logic around how to proceed e.g. create a new server on the infrastructure provider, update the load balancer, deploy to an existing server, destroy the server etc. This could be a traditional web application serving up an API or it could be a serverless application, up to you how you want to approach it.</p>
  
  <p>The receiver is relatively straightforward to handle, the other necessary supporting systems you'll need are an approach to configuration management/provisioning (how does the server have the packages necessary to run the application), secrets management (how does the server get access to sensitive information) and routing  (how do the subdomains get updated and route to the correct server).</p>
  
  <p>It could be worthwhile looking at preparing an <a href="https://aws.amazon.com/answers/configuration-management/aws-ami-design/" rel="noreferrer">AMI</a> with the necessary services configured, a <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html" rel="noreferrer">CloudFormation</a> template with the infrastructure provisioning logic and <a href="http://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html" rel="noreferrer">CodeDeploy</a> could handle deployments for you.</p>
  
  <p><strong>Configuration Management</strong></p>
  
  <p>This is really up to you and your team, there are a multitude of tools you can use or you can simply rely on shell scripting. At what point in the servers lifecycle you apply the changes is what's discussed in the AMI design <a href="https://aws.amazon.com/answers/configuration-management/aws-ami-design/" rel="noreferrer">article</a> I linked. </p>
  
  <p><strong>Secrets Management</strong></p>
  
  <p>This is a challenging topic to address with the information at hand, in the interest of brevity I'll leave that up to you and your team.</p>
  
  <p><strong>Routing</strong></p>
  
  <p>There are a few ways you can handle routing, the Application Load Balancer (not to be confused with the ELB/NLB) offered by AWS supports <a href="http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#host-conditions" rel="noreferrer">host based routing</a>. Alternatively you could use a reverse proxy like NGINX or HAProxy, when you provision a new environment you will need to update this routing (ideally automatically) irrespective of what approach you take.</p>
  
  <p>Don't forget to consider how you'll handle the database/persistence layer &amp; zero down time deployments. The question to ask with the persistence layer is whether the team will share a database and how that will interact with things like migrations. On the topic of zero downtime deployments, CodeDeploy should handle that nicely for you. One more thing, you mentioned a single mobile application pointing to different environments, how will you point these applications to the environments.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-11-19T07:51:07.703Z
Answers: There is a lot of juice in your answer. Can you break it down a bit though? For example in the different sections you mentioned.. can you give me something to start with in each if them?
Answers: abbood
Answers: CC BY-SA 3.0
Answers: 2017-11-19T10:49:24.427Z
Answers: Is there any relationship between [the user who posted this answer](https://devops.stackexchange.com/users/5269/dom-hutton), and [this user](https://devops.stackexchange.com/users/670/dom-hutton)? I bet they are from the same "user" ... If so please have both accounts merged ...
Answers: Pierre.Vriens
Answers: CC BY-SA 3.0
Answers: 2017-11-19T04:41:17.197Z
Answers: 2017-11-19T10:39:38.640Z
Answers: 2017-11-19T10:39:38.640Z
Answers: dom_hutton
Answers: <p>this setup worked perfectly for me using aws code deploy:</p>
  
  <p><a href="https://i.sstatic.net/mo6zT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mo6zT.png" alt="enter image description here"></a></p>
  
Answers: CC BY-SA 4.0
Answers: 2018-08-02T16:47:57.550Z
Answers: 2018-08-02T16:47:57.550Z
Answers: abbood
Body: <h1>Background</h1>
  
  <p>I got a team of untechnical QA's who have to do testing on iOS/android apps for every Pull Request (PR) that gets created by my backend team. </p>
  
  <h1>Question</h1>
  
  <p>This is what I want to do: everytime a backend engineer creates a PR on bitbucket, I would like a script to automatically deploy the code of that PR git branch into a subdomain of our dev server that matches the JIRA issue created. </p>
  
  <p>For example suppose the jira issue that the PR addresses is BAC-421, then as soon as the engineer creates a PR, the script deploys the code they created into AWS EC2 so that the QA can point their apps to www.bac421.mydevdomain.com</p>
  
  <p>What is the best way to do this? I'm a devops technical nube. </p>
  
  <h1>Update - Environment Specs</h1>
  
  <p>so here is a breakup of our env
  - the backend uses laravel 5.3
  - it's deployed on AWS EC2
  - we use <a href="https://forge.laravel.com/auth/login" rel="noreferrer">forge</a> for auto deployment (nothing fancy.. we just run this script:</p>
  
  <pre><code>cd /home/forge/default
  git fetch --tags 
  git pull origin master
  git describe
  composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
  echo "" | sudo -S service php7.1-fpm reload
  
  if [ -f artisan ]
  then
      php artisan migrate --force
      php artisan config:cache
      php artisan queue:restart
  fi
  </code></pre>
  
  <p>that we run as soon as we merge dev unto master branch)
  - besides that we don't use any CI/CD tools although I'm open for recommendations
  - DNS provider is GoDaddy
  - our application server is nginx
  - our database is in a separate RDS instance</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-11-19T01:09:32.827Z
Comments: How do you currently deploy your software? What CI or CD tools do you use? Who is your DNS provider?
Comments: user2640621
Comments: CC BY-SA 3.0
Comments: 2017-11-19T01:28:53.943Z
Comments: Yes. There are plenty of ways to skin this cat - including but not limited to updating a hosts file, but we would need to know more about your environment.
Comments: James Shewey
Comments: CC BY-SA 3.0
Comments: 2017-11-19T06:46:55.043Z
Comments: answer updated @user2640621
Comments: abbood
Tags: <git><deployment><bitbucket><git-hooks>
Title: how to automatically create a subdomain for every pull request
UserDisplayName: abbood
ThreadText: # how to automatically create a subdomain for every pull request
  
  (Asked by: username_0 on 2017-11-18)
  
  # Background
  
  I got a team of untechnical QA's who have to do testing on iOS/android apps for every Pull Request (PR) that gets created by my backend team.
  
  # Question
  
  This is what I want to do: everytime a backend engineer creates a PR on bitbucket, I would like a script to automatically deploy the code of that PR git branch into a subdomain of our dev server that matches the JIRA issue created.
  
  For example suppose the jira issue that the PR addresses is BAC-421, then as soon as the engineer creates a PR, the script deploys the code they created into AWS EC2 so that the QA can point their apps to www.bac421.mydevdomain.com
  
  What is the best way to do this? I'm a devops technical nube.
  
  # Update - Environment Specs
  
  so here is a breakup of our env
  - the backend uses laravel 5.3
  - it's deployed on AWS EC2
  - we use [forge](https://forge.laravel.com/auth/login) for auto deployment (nothing fancy.. we just run this script:
  
  ```
  cd /home/forge/default
  git fetch --tags 
  git pull origin master
  git describe
  composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
  echo "" | sudo -S service php7.1-fpm reload
  
  if [ -f artisan ]
  then
      php artisan migrate --force
      php artisan config:cache
      php artisan queue:restart
  fi
  
  ```
  
  that we run as soon as we merge dev unto master branch)
  - besides that we don't use any CI/CD tools although I'm open for recommendations
  - DNS provider is GoDaddy
  - our application server is nginx
  - our database is in a separate RDS instance
  
  **Tags:** git, deployment, bitbucket, git-hooks
  
  > **Comments:**
  > **username_1**: How do you currently deploy your software? What CI or CD tools do you use? Who is your DNS provider?  
  > **username_2**: Yes. There are plenty of ways to skin this cat - including but not limited to updating a hosts file, but we would need to know more about your environment.  
  > **username_0**: answer updated @username_1  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-08-02. Score: 3 | Accepted answer
  
  this setup worked perfectly for me using aws code deploy:
  
  [![enter image description here](https://i.sstatic.net/mo6zT.png)](https://i.sstatic.net/mo6zT.png)
  
  
  ---
  
  ### Answer by username_3 on 2017-11-19. Score: 7
  
  We do this at work.
  
  We have a small server, let's call it the receiver, it's the target of the [GitHub webhook events](https://developer.github.com/webhooks/). It runs a small application that parses the payload and incorporates logic around how to proceed e.g. create a new server on the infrastructure provider, update the load balancer, deploy to an existing server, destroy the server etc. This could be a traditional web application serving up an API or it could be a serverless application, up to you how you want to approach it.
  
  The receiver is relatively straightforward to handle, the other necessary supporting systems you'll need are an approach to configuration management/provisioning (how does the server have the packages necessary to run the application), secrets management (how does the server get access to sensitive information) and routing (how do the subdomains get updated and route to the correct server).
  
  It could be worthwhile looking at preparing an [AMI](https://aws.amazon.com/answers/configuration-management/aws-ami-design/) with the necessary services configured, a [CloudFormation](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) template with the infrastructure provisioning logic and [CodeDeploy](http://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html) could handle deployments for you.
  
  **Configuration Management**
  
  This is really up to you and your team, there are a multitude of tools you can use or you can simply rely on shell scripting. At what point in the servers lifecycle you apply the changes is what's discussed in the AMI design [article](https://aws.amazon.com/answers/configuration-management/aws-ami-design/) I linked.
  
  **Secrets Management**
  
  This is a challenging topic to address with the information at hand, in the interest of brevity I'll leave that up to you and your team.
  
  **Routing**
  
  There are a few ways you can handle routing, the Application Load Balancer (not to be confused with the ELB/NLB) offered by AWS supports [host based routing](http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#host-conditions). Alternatively you could use a reverse proxy like NGINX or HAProxy, when you provision a new environment you will need to update this routing (ideally automatically) irrespective of what approach you take.
  
  Don't forget to consider how you'll handle the database/persistence layer & zero down time deployments. The question to ask with the persistence layer is whether the team will share a database and how that will interact with things like migrations. On the topic of zero downtime deployments, CodeDeploy should handle that nicely for you. One more thing, you mentioned a single mobile application pointing to different environments, how will you point these applications to the environments.
  
  > **Comments:**
  > **username_0**: There is a lot of juice in your answer. Can you break it down a bit though? For example in the different sections you mentioned.. can you give me something to start with in each if them?  
  > **username_4**: Is there any relationship between [the user who posted this answer](https://devops.stackexchange.com/users/5269/username_3), and [this user](https://devops.stackexchange.com/users/670/username_3)? I bet they are from the same "user" ... If so please have both accounts merged ...  
  
  ---
  
  