Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Docker push postpublish script #1397

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9617f0c
Added docker folder that contains the docker files for ubuntu1404 and…
rishivikram Jan 24, 2018
1c4f156
Added .dockerignore file so that not everything (like nodejs modules)…
rishivikram Jan 24, 2018
e6d1d1f
Added the main script that runs after successful tag build on newman,…
rishivikram Jan 24, 2018
6965ca9
Added after_success routine to trigger the ./docker/scripts/run.sh sc…
rishivikram Jan 24, 2018
7556c24
Removed unnecessary echo statements
rishivikram Jan 24, 2018
6de27b5
Updated Dockerfile so that local collections can run now
rishivikram Jan 24, 2018
316a4b3
Used travis environment variables to determine the node version and o…
rishivikram Jan 24, 2018
28b3a39
Updated docker build command to include the latest tag
rishivikram Jan 25, 2018
fadfdb8
Removed after success routine from .travis.yml and added postpublish …
rishivikram Jan 30, 2018
d714412
Updated dockerfiles and script so that newman version to be installed…
rishivikram Jan 30, 2018
7378d20
Renamed the run.sh script and moved it to npm folder so that script i…
rishivikram Jan 31, 2018
46b9c79
Added options to apt-get update so that the docker image builds corre…
rishivikram Jan 31, 2018
ffb0902
Updated repository.test.js to account for .sh files also being presen…
rishivikram Jan 31, 2018
74f29bf
Merge branch 'develop' into feature/automate-newman-dockerimage-versi…
kunagpal Jan 31, 2018
74a7862
Made the code in system tests a little cleaner
rishivikram Jan 31, 2018
213a7c6
Merge branch 'feature/automate-newman-dockerimage-version-bump' of gi…
rishivikram Jan 31, 2018
c7747b6
Updated the dockerfile to not use a fallback default value. Also upda…
rishivikram Feb 1, 2018
806474d
Merge branch 'develop' into feature/automate-newman-dockerimage-versi…
shamasis Feb 14, 2018
099b659
Updated Newman alpine 3.3 Dockerfile for automated postpublish
kunagpal May 8, 2018
10b4b15
Updated Newman alpine 3.3 Dockerfile for automated postpublish
kunagpal May 8, 2018
da2e1ec
Cleaned up postpublish script :art:
kunagpal May 8, 2018
9a45abe
Merge branch 'develop' into feature/automate-newman-dockerimage-versi…
kunagpal May 8, 2018
fd73890
Fixed broken system tests :white_check_mark:
kunagpal May 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# PLATFORM
# ========
# All exclusions that are specific to the NPM, GIT, IDE and Operating Systems.

# - Do not allow installed node modules to be committed. Doing `npm install -d` will bring them in root or other places.
node_modules

# - Do not commit any log file from anywhere
*.log
*.log.*

# - Prevent addition of OS specific file explorer files
Thumbs.db
.DS_Store

# Prevent IDE stuff
.idea
.vscode

# PROJECT
# =======
# Configuration pertaining to project specific repository structure.

# - Prevent Sublime text IDE files from being commited to repository
*.sublime-*

# - Allow sublime text project file to be commited in the development directory.
!/develop/*.sublime-project

# - Prevent CI output files from being Added
/out/
/newman/

# - Prevent diff backups from SourceTree from showing as commit.
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*.orig

# Prevent unit test coverage reports from being added
.coverage
40 changes: 40 additions & 0 deletions docker/images/alpine33/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM alpine:3.3
MAINTAINER Postman Labs <help@getpostman.com>

ARG newman_version
# Bail out early if NODE_VERSION is not provided
RUN if [ ! $(echo $newman_version | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+$") ]; then \
echo "\033[0;31mA valid semver Newman version is required in the newman_version build-arg\033[0m"; \
exit 1; \
fi

# Can't upgrade to node v8 because it isn't supported in alpine 3.3
ENV NODE_VERSION 4.3.2

# Install node
RUN echo -e "http://nl.alpinelinux.org/alpine/v3.3/main\nhttp://nl.alpinelinux.org/alpine/v3.3/community" > /etc/apk/repositories && \
apk add --update nodejs=${NODE_VERSION}-r1;

# Set environment variables
ENV LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" NEWMAN_VERSION=$newman_version

# Install newman
RUN npm install -g newman@${NEWMAN_VERSION};

# Set workdir to /etc/newman
# When running the image, mount the directory containing your collection to this location
#
# docker run -v <path to collections directory>:/etc/newman ...
#
# In case you mount your collections directory to a different location, you will need to give absolute paths to any
# collection, environment files you want to pass to newman, and if you want newman reports to be saved to your disk.
# Or you can change the workdir by using the -w or --workdir flag
WORKDIR /etc/newman

# Set newman as the default container command
# Now you can run the container via
#
# docker run -v /home/collections:/etc/newman -t postman/newman_alpine33 -c YourCollection.json.postman_collection \
# -e YourEnvironment.postman_environment \
# -H newman_report.html
ENTRYPOINT ["newman"]
38 changes: 38 additions & 0 deletions docker/images/alpine33/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# newman_alpine33

This image runs newman on node 4.3.2 on Alpine 3.3

Build the image:

```terminal
docker build -t postman/newman_alpine33 .
```

Or get it from [Docker Hub](https://registry.hub.docker.com/u/postman/newman_alpine33/):

```terminal
docker pull postman/newman_alpine33
```

Then run it:

```terminal
docker --volume="/home/postman/collections:/etc/newman" -t postman/newman_alpine33 --collection="JSONBlobCoreAPI.json.postman_collection" --html="newman-report.html"
```
For newman-docker to be able to use collections and environment files saved on the host machine, and to save reports generated by newman, a directory containing the collection and environment needs to be mounted on to the docker instance on run time, preferably at `/etc/newman`, which is the default working directory. If you mount to a different location, then:
- You can pass the full path to your collection and environment files to newman. For instance, if you mount to `/var/newman`,

```terminal
docker --volume="/home/postman/collection:/var/newman" -t postman/newman_alpine33 --collection="/var/newman/JSONBlobCoreAPI.json.postman_collection" --html="/var/newman/newman-report.html"
```
- You can change the working directory while running the image to the location you mounted to, using the `-w` or `--workdir` flag.

```terminal
docker run --volume="/home/postman/collections:/var/newman" --workdir="/var/newman" -t postman/newman_alpine33 --collection="JSONBlobCoreAPI.json.postman_collection" --html="newman-report.html"
```

In case you don't need to save newman's report to the host, and your collection is available online and does not require any environment, then you can forgo mounting your collections directory and directly pass the collection URL to newman:

```terminal
docker run -t postman/newman_alpine33 --url="https://www.getpostman.com/collections/8a0c9bc08f062d12dcda"
```
40 changes: 40 additions & 0 deletions docker/images/ubuntu1404/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:14.04.2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use ubuntu:14.04 to keep track on upstream changes

MAINTAINER Postman Labs <help@getpostman.com>

ARG newman_version
# Bail out early if NODE_VERSION is not provided
RUN if [ ! $(echo $newman_version | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+$") ]; then \
echo "\033[0;31mA valid semver Newman version is required in the newman_version build-arg\033[0m"; \
exit 1; \
fi

# Set node version
ENV NODE_VERSION 8

# Install node
ADD https://deb.nodesource.com/setup_$NODE_VERSION.x /opt/install_node.sh
RUN bash /opt/install_node.sh && apt-get install -y nodejs

# Set environment variables
ENV LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" NEWMAN_VERSION=$newman_version

# Install newman
RUN npm install -g newman@${NEWMAN_VERSION};

# Set workdir to /etc/newman
# When running the image, mount the directory containing your collection to this location
#
# docker run -v <path to collections directory>:/etc/newman ...
#
# In case you mount your collections directory to a different location, you will need to give absolute paths to any
# collection, environment files you want to pass to newman, and if you want newman reports to be saved to your disk.
# Or you can change the workdir by using the -w or --workdir flag
WORKDIR /etc/newman

# Set newman as the default container command
# Now you can run the container via
#
# docker run -v /home/collections:/etc/newman -t postman/newman_ubuntu1404 -c YourCollection.json.postman_collection \
# -e YourEnvironment.postman_environment \
# -H newman_report.html
ENTRYPOINT ["newman"]
38 changes: 38 additions & 0 deletions docker/images/ubuntu1404/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# newman_ubuntu1404

This image runs newman on node v8 on Ubuntu 14.04.2

Build the image,

```terminal
docker build -t postman/newman_ubuntu1404 .
```

Or get it from [docker hub](https://registry.hub.docker.com/u/postman/newman_ubuntu1404/)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the path on the Docker Hub


```terminal
docker pull postman/newman_ubuntu1404
```

then run it

```terminal
docker --volume="/home/postman/collections:/etc/newman" -t postman/newman_ubuntu1404 --collection="JSONBlobCoreAPI.json.postman_collection" --html="newman-report.html"
```
For newman-docker to be able to use collections and environment files saved on the host machine, and to save reports generated by newman, a directory containing the collection and environment needs to be mounted on to the docker instance on run time, preferably at `/etc/newman`, which is the default working directory. If you mount to a different location, then
- You can either pass the full path to your collection and environment files to newman. For instance, if you mount to `/var/newman`,

```terminal
docker --volume="/home/postman/collection:/var/newman" -t postman/newman_ubuntu1404 --collection="/var/newman/JSONBlobCoreAPI.json.postman_collection" --html="/var/newman/newman-report.html"
```
- You can change the working directory while running the image to the location you mounted to, using the `-w` or `--workdir` flag.

```terminal
docker run --volume="/home/postman/collections:/var/newman" --workdir="/var/newman" -t postman/newman_ubuntu1404 --collection="JSONBlobCoreAPI.json.postman_collection" --html="newman-report.html"
```

In case you don't need to save newmans report to the host, and your collection is available online and it does not require any environment, then you can forgo mounting your collections directory, and directly pass the collection url to newman

```terminal
docker run -t postman/newman_ubuntu1404 --url="https://www.getpostman.com/collections/8a0c9bc08f062d12dcda"
```
40 changes: 40 additions & 0 deletions npm/postpublish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Bail out on the first error
set -e;

BLUE='\033[0;34m';
NO_COLOUR='\033[0m';
DOCKER_USER="postman";
TAG=$npm_package_version;
IMAGES_BASE_PATH="./docker/images";

# It's good to be paranoid
[[ -z "$TAG" ]] && TAG=$(jq -r ".version" < package.json);

function build_docker_image {
local TAG="$2";
local BASENAME=$(basename $1);
local IMAGE_NAME="newman_$BASENAME";

echo "";
echo -e "$BLUE Building docker image for $DOCKER_USER/$IMAGE_NAME:$TAG, latest $NO_COLOUR";
docker build \
-t "$DOCKER_USER/$IMAGE_NAME:$TAG" -t "$DOCKER_USER/$IMAGE_NAME:latest" \
--no-cache --force-rm --file="docker/images/$BASENAME/Dockerfile" --build-arg newman_version="$TAG" .;

echo -e "$BLUE Running docker image test for $DOCKER_USER/$IMAGE_NAME:$TAG, latest $NO_COLOUR";
docker run -v "$PWD/examples:/etc/newman" -t "$DOCKER_USER/$IMAGE_NAME:$TAG" run "sample-collection.json";

# prepare current images for pushing
docker tag $DOCKER_USER/$IMAGE_NAME:$TAG $DOCKER_USER/$IMAGE_NAME:$TAG;
docker tag $DOCKER_USER/$IMAGE_NAME:latest $DOCKER_USER/$IMAGE_NAME:latest;

echo -e "$BLUE Pushing docker image for $DOCKER_USER/$IMAGE_NAME:$TAG, latest $NO_COLOUR";
docker push $DOCKER_USER/$IMAGE_NAME:$TAG;
docker push $DOCKER_USER/$IMAGE_NAME:latest;
}

for image in $IMAGES_BASE_PATH/*; do
build_docker_image ${image} ${TAG};
done
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"build-docs": "node npm/build-docs.js",
"build-wiki": "node npm/build-wiki.js",
"publish-docs": "node npm/publish-docs.js",
"postpublish": "./npm/postpublish.sh",
"publish-wiki": "node npm/publish-wiki.js"
},
"author": "Postman Labs <help@getpostman.com> (=)",
Expand Down
33 changes: 26 additions & 7 deletions test/system/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* @fileOverview This test specs runs tests on the package.json file of repository. It has a set of strict tests on the
* content of the file as well. Any change to package.json must be accompanied by valid test case in this spec-sheet.
*/
var _ = require('lodash'),
var path = require('path'),

_ = require('lodash'),
expect = require('expect.js'),
parseIgnore = require('parse-gitignore');

Expand Down Expand Up @@ -73,19 +75,36 @@ describe('project repository', function () {

describe('script definitions', function () {
it('files must exist', function () {
var scriptRegex = /^node\snpm\/.+\.js$/;

expect(json.scripts).to.be.ok();
json.scripts && Object.keys(json.scripts).forEach(function (scriptName) {
expect(scriptRegex.test(json.scripts[scriptName])).to.be.ok();
expect(fs.statSync('npm/' + scriptName + '.js')).to.be.ok();
var name = json.scripts[scriptName];
name = name.replace(/^(node\s|\.\/)/, '');
fs.stat(name, function (err) {
var fileDetails = path.parse(name);
expect(err).to.equal(null);
expect(fileDetails.ext).to.match(/^\.(sh|js)$/);
});
});
});

it('must have the hashbang defined', function () {
expect(json.scripts).to.be.ok();
json.scripts && Object.keys(json.scripts).forEach(function (scriptName) {
var fileContent = fs.readFileSync('npm/' + scriptName + '.js').toString();
expect(/^#!\/(bin\/bash|usr\/bin\/env\snode)[\r\n][\W\w]*$/g.test(fileContent)).to.be.ok();
var fileDetails,
name = json.scripts[scriptName].replace(/^(node\s|\.\/)/, '');

fileDetails = path.parse(name);
expect(fileDetails.ext).to.match(/^\.(sh|js)$/);

fs.readFile(name, function (error, content) {
expect(error).to.equal(null);
if (fileDetails.ext === '.sh') {
expect(/^#!\/bin\/bash[\r\n][\W\w]*$/g.test(content)).to.be.ok();
}
else {
expect(/^#!\/usr\/bin\/env\snode[\r\n][\W\w]*$/g.test(content)).to.be.ok();
}
});
});
});
});
Expand Down