Search our documentation:
Docker is a popular and powerful method for packaging and deploying your modern web application. In this tutorial we're going to look at a couple different ways we can test our containerized applications using Ghost Inspector.
Before we get started we are going to need the following:
We offer two different Docker images to aide in testing your containerized app:
ghostinspector/test-runner-node) - image for testing your application within a single Docker container.
ghostinspector/test-runner-standalone) - standalone image for testing within an existing Docker cluster.
The base image test runner is designed for you to extend with your source files for the purpose of testing your application. This can be useful if you have a fairly simple Docker setup or are working in a CI environment that does not support multi-container Docker (such as Bitbucket Pipelines). The image includes all the utilities and scripts needed to execute your Ghost Inspector test suite against your Node.js application.
Let's have a look at an example
FROM ghostinspector/test-runner-node # Copy your source code COPY . . # Install your app RUN npm install . # Configure the test runner ENV APP_PORT 3000 ENV GI_API_KEY <ghostinspector-api-key> ENV GI_SUITE <ghostinspector-suite-id> ENV GI_PARAM_myVar some-custom-value ENV NGROK_TOKEN <your-ngrok-token> # Pass your application entrypoint into our test runner script CMD ["index.js"]
Dockerfile simple extends our
ghostinspector/test-runner-node image, copies our application files, and installs the application. Next we will need to adjust the environment variables for the test runner to execute properly, and then adjust our
In order for this image to successfully interact with your application we will need to provide some configuration at runtime, either for the test running script, or for your Ghost Inspector test suite.
Some of the environment variables are required:
APP_PORT- tells the test running script which port your application is running on.
GI_API_KEY- available in your Ghost Inspector account.
GI_SUITE- the ID of the Ghost Inspector test suite you wish to run against your app.
NGROK_TOKEN- available from your ngrok account
STARTUP_DELAY(optional) - seconds to wait for application and ngrok each to start up, defaults to 3 seconds.
GI_PARAM_myVar(optional) - additional URL parameter to send to our API, the value of which will be accessible in your test under
myVar. You may additional parameters as are required by your tests.
Note that all environment variables will also be available to your application in the
The last line of our
Dockerfile is going to be the
CMD. This should be the Node.js entrypoint of your application, in our case it looks like:
Note that it could be
myapp/start.js or whatever Node.js script fires up your app, as long as it is a Node.js file.
Also, if you require additional parameters on startup, you are not restricted by the number of parameters that you pass into
CMD ["index.js", "--sky=blue"]
Any additional parameters past the
index.js position will be passed to your application when it is started up.
Now, assuming everything is configured correctly, we should be able to build and run our container and watch it's progress:
$ docker build -t my-app . $ docker run my-app
The container will now start your application, open a tunnel using ngrok, and execute your Ghost Inspector suite via the API using the API key and suite ID you've provided, along with any custom parameters defined in the Environment Variables.
Continue to the next section to learn about executing your test suite within a more complex Docker environment.
This Docker image will allow you to execute your Ghost Inspector test suite against another running Docker container within your cluster by using Docker container networking.
First, pull down the
ghostinspector/test-runner-standalone image to your local environment:
$ docker pull ghostinspector/test-runner-standalone
Next we will create a new network in Docker-land so we can link the applications at runtime:
$ docker network create my-test-network
This will create a network that we can attach to our Docker containers at runtime to give them the ability to communicate privately.
Then we can start your application in the background (
-d), noting that
<my-image> will need to be changed to the name of your application Docker image:
$ docker run -d --name my-app --network my-test-network <my-image>
Here we have named the new container
my-app and connected it to the network
Once that's up and running, we can fire up the Ghost Inspector
test-runner-standalone image which will run our suite against our running app:
$ docker run \ -e NGROK_TOKEN=<my-ngrok-token> \ -e GI_API_KEY=<my-api-key> \ -e GI_SUITE=<my-suite-id> \ -e GI_PARAM_myVar=foo \ -e APP_PORT=my-app:8000 \ --network my-test-network \ ghostinspector/test-runner-standalone
Make sure you change out all the environment variables to your own custom values for
GI_SUITE. Notice that for
APP_PORT we've passed in
my-app will resolve to our running docker container that we named
8000 assumes that is the port that our application is running on. Finally we also connect this new container to the same
my-test-network so all the DNS and networking magic can happen. Also note that you can send custom variables to the API call when we execute your test suite by using a custom environment variable named
varName is the name of your variable. This will be available in your Ghost Inspector tests under
Once this container fires up, it will perform the exact same set of actions as before:
ngrokdaemon and open a tunnel to
passingstatus until a result is provided.
0) or fail (
That's it! If everything went well you should be able to visit your dashboard and check on the status of your test suite.
If you run into issues setting up this tutorial, or any other problems with our product, feel free to drop us a line in support and we'll be happy to answer any questions for you.