Before you release new features, you always want to test them in a working, remote environment that closely resembles your production to make sure everything works as expected (not only on your machine). Working in teams makes this task a bit more complicated - if you have just one testing environment, sometimes you have to wait until your colleagues finish testing their features before you can test yours.
In this guide, you will learn how to make a full use of Qovery Environments
to speed up your development cycle and make your life as a developer more pleasurable and simple.
Before you begin, this page assumes the following:
- You have installed the Qovery CLI
- You have already deployed an application with Qovery
Your application
Let's suppose you're working in a team. You and your colleagues are adding new features to one of your applications. For simplicity of the guide, let's suppose that this is your application:
const http = require('http');const hostname = '0.0.0.0';const port = 3333;const server = http.createServer((req, res) => {res.statusCode = 200;res.setHeader('Content-Type', 'text/plain');res.end(`Hello from ${process.env.QOVERY_BRANCH_NAME} environment!`);});server.listen(port, hostname, () => {console.log(`Server running at http://${hostname}:${port}/`);});
It's a simple Node.js server that returns text in HTTP body response.
Adding new features
Your colleague had a task - adding jokes about Chuck Norris to server responses. He is a great programmer - he created a new branch and developed a new feature:
const http = require('http');const https = require('https');const hostname = '0.0.0.0';const port = 3333;const server = http.createServer((req, res) => {myColleaguesFeature(res)});server.listen(port, hostname, () => {console.log(`Server running at http://${hostname}:${port}/`);});const myColleaguesFeature = (r) => {https.get('https://api.chucknorris.io/jokes/random', (resp) => {let data = ''resp.on('data', (chunk) => {data += chunk})resp.on('end', () => {r.end(`Hello from ${process.env.QOVERY_BRANCH_NAME} environment!\n\nEnjoy a high quality joke: ${JSON.parse(data).value}`)})}).on('error', (err) => {r.statusCode = 500r.end(`Something has gone wrong in ${process.env.QOVERY_BRANCH_NAME} environment!`)})}
He tested his code locally:
$ curl http://localhost:3333Hello from undefined environment!Enjoy a high quality joke: Chuck Norris can unscramble an egg⏎
It works! A great joke appears in the response. Great! But your colleague is a smart guy - he wanted to make sure that his feature also
works well in the deployed, testing environment. He wants to avoid saying IT WORKS - on my machine
later on (if for some reason his feature didn't work in production).
Testing in deployed environments
Typically, software teams have a few environments. A common pattern is having something close to production
, staging
and testing
environment.
So, your colleague has deployed his app to the testing
environment.
The problem
Unluckily, at the same time, you have finished your own important feature (adding the current Bitcoin price to the response!), and you also want to test it in a remote environment.
const http = require('http');const https = require('https');const hostname = '0.0.0.0';const port = 3333;const server = http.createServer((req, res) => {myFeature(res)});server.listen(port, hostname, () => {console.log(`Server running at http://${hostname}:${port}/`);});const myFeature = (r) => {https.get('https://api.coindesk.com/v1/bpi/currentprice/btc.json', (resp) => {let data = ''resp.on('data', (chunk) => {data += chunk})resp.on('end', () => {r.end(`Hello from ${process.env.QOVERY_BRANCH_NAME} environment!\n\nCurrent Bitcoin price: $${JSON.parse(data).bpi.USD.rate}`.split(".")[0])})}).on('error', (err) => {r.statusCode = 500r.end(`Something has gone wrong in ${process.env.QOVERY_BRANCH_NAME} environment!`)})}
You have your own separate Git branch, so your changes are not a part of your friend's version of the application.
You can't test your changes at the same time with your colleague in one environment! During the time your friend tests his code, your feature can not be finished and delivered to the production.
Qovery Environments to the rescue
To solve this issue and enable software developers to work independently, Qovery introduces the concept of Environments
.
On Qovery, after you create a new branch for your new feature, you automatically get a completely separated, exact copy of your production environment (including all applications, databases, data, storage, and brokers).
As you see, you also get separate URLs to your versions of applications, so you can test your apps freely and independently. Now, you can test your features in parallel. No more time wasted!
Test it yourself
To see how it works, simply fork this repository
by clicking the Fork
button:
and then, clone the repository:
$ cd qovery-environments-demo
Now, you can use qovery environment list
command to see the status of all environments (for each branch of Git repository, Qovery created a separate environment):
You can now test different versions of the application using your endpoints and curl
or a web browser:
$ curl https://main-rsgnoj93ssqdyohq-gtw.qovery.io/Hello from my-colleagues-feature environment!Enjoy a high quality joke: Chuck Norris never had a condom, thus the glad force flex bag was invented.
$ curl https://main-p5jtnf0sphc3frsb-gtw.qovery.io/Hello from my-new-feature environment!Current Bitcoin price: $7,107
and finally:
$ curl https://main-gezg7nlejmutwjsn-gtw.qovery.io/Hello from master environment!
Now, you can play a bit and make some changes. After you commit and push, your application is automatically updated in the appropriate environment, depending on which branch you are working in.