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

Conversation

rishivikram
Copy link
Contributor

@rishivikram rishivikram commented Jan 24, 2018

No description provided.

… alpine33. Also updated the docker files to install the root newman directory as a nodejs module which would be used by the docker image
@kunagpal kunagpal self-requested a review January 24, 2018 20:31
@kunagpal kunagpal self-assigned this Jan 24, 2018
@rishivikram rishivikram changed the title [NEWMAN-133] Automate newman docker image version bumps after successful tag build on master branch of newman Automate newman docker image version bumps after successful tag build on master branch of newman Jan 24, 2018
Copy link
Contributor

@kunagpal kunagpal left a comment

Choose a reason for hiding this comment

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

@rishivikram Ensure that all applicable statements are terminated with a semicolon.

@@ -0,0 +1,38 @@
# newman_ubuntu1404

This image runs newman 3.9.0 on node 4.3.0 on Ubuntu 14.04.2
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the Newman version from this statement, mention the Node version as 8.

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

```terminal
docker pull postman/newman_ubuntu1404:3.9.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

fi
}

NODE_V=$(node -v | grep -o "v.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Travis provides an inbuilt environment variable for this, use that instead.

NODE_V=$(node -v | grep -o "v.")

IMAGES_BASE_PATH="./docker/images"
if [ -n "$TRAVIS_TAG" ] && [ "$NODE_V" = "v8" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause unstable tags to be built as well.

docker build -t "$DOCKER_ID_USER/$IMAGE_NAME:$TRAVIS_TAG" .
if docker images | grep -q "$DOCKER_ID_USER/$IMAGE_NAME"; then
echo "Image built"
if docker run -t "$DOCKER_ID_USER/$IMAGE_NAME:$TRAVIS_TAG" run "https://www.getpostman.com/collections/8a0c9bc08f062d12dcda"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This will fail if the link ever dies, use a local collection file instead.

if docker run -t "$DOCKER_ID_USER/$IMAGE_NAME:$TRAVIS_TAG" run "https://www.getpostman.com/collections/8a0c9bc08f062d12dcda"; then
echo "Collection run successfully"
docker login -u "$DOCKER_ID_USER" -p "$DOCKER_ID_PASSWORD"
docker push "$DOCKER_ID_USER/$IMAGE_NAME:$TRAVIS_TAG"
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs the latest tag as well.

function build_docker_image {
BASENAME=$(basename $1)
IMAGE_NAME="newman_$BASENAME"
docker build -t "$DOCKER_ID_USER/$IMAGE_NAME:$TRAVIS_TAG" .
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is off.

echo "Collection not run successfully"
fi
else
echo "Image not built"
Copy link
Contributor

Choose a reason for hiding this comment

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

Also include the image basename in the message.

MAINTAINER Postman Labs <help@getpostman.com>

# Set node version
# Can't upgrade to nodev8 because it isn't supported in alpine 3.3
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,38 @@
# newman_alpine33

This image runs newman 3.9.0 on node 4.3.0 on Alpine 3.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the Newman version, update the Node version to v4.3.2

BASENAME=$(basename $1);
IMAGE_NAME="newman_$BASENAME";
TAG="$2";
docker build -t "$DOCKER_ID_USER/$IMAGE_NAME:$TAG" .
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll have to add the latest tag here (-t can accept multiple space separated name:value parameters). See https://github.com/postmanlabs/newman-docker/blob/develop/scripts/docker/docker-build.sh#L13 for a working example.

if [ -d "${image}" ] && [ -f "${image}/Dockerfile" ]; then
cp "${image}/Dockerfile" .
build_docker_image ${image} ${TRAVIS_TAG};
build_docker_image ${image} "latest";
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to build two separate images, supply multiple tags as explained above. 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, will correct it right away.

docker build -t "$DOCKER_ID_USER/$IMAGE_NAME:$TAG" .
if docker images | grep -q "$DOCKER_ID_USER/$IMAGE_NAME"; then
echo "Image built"
if docker run -t "$DOCKER_ID_USER/$IMAGE_NAME:$TAG" run "sample-collection.json"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you have to specify the complete path, as in examples/sample-collection.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, I already mounted the whole examples directory in etc/newman, so no need. The collection runs correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did the mounting work in the dockerfile.

EXTRACTED_TAG=$(echo $TRAVIS_TAG | grep -o "[0-9]\+.[0-9]\+.[0-9]\+")
if [ -n "$TRAVIS_TAG" ] && [ "$TRAVIS_TAG" = "$EXTRACTED_TAG" ] && [ "$TRAVIS_NODE_VERSION" = "8" ]; then
for image in $IMAGES_BASE_PATH/*; do
if [ -d "${image}" ] && [ -f "${image}/Dockerfile" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

The -d conditional check is redundant here.


ADD . /newman

RUN ln -s /newman/examples /etc/newman
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid creating symlinks here, use the complete path in collection run tests in the build script.


ADD . /newman

RUN ln -s /newman/examples /etc/newman
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

});
});

it('must have the hashbang defined', function () {
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();
fs.readFile('npm/' + scriptName + '.js', function (err, fileContent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No. Check if the file is a shell script or js file using fs.stat first, and then perform extension specific checks.

var scriptRegex = /^node\snpm\/.+\.js$/;

var scriptRegexJS = /^node\snpm\/.+\.js$/,
scriptRegexSH = /^\.\/npm\/.+\.sh$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have one cumulative regex testing both patterns.

RUN npm install -g n;
RUN n ${NODE_VERSION};

ARG newman_version=default_value
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It needs a default value which would be used if $newman_version is not sent as a variable in the docker build command.

# Install node
RUN apk add --update nodejs=${NODE_VERSION}-r1;

ARG newman_version=default_value
Copy link
Contributor

Choose a reason for hiding this comment

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

?

rishivikram and others added 4 commits January 31, 2018 20:22
…thub.com:rishivikram/newman into feature/automate-newman-dockerimage-version-bump

Pulled latest code from github.
…ted the DOCKER_ID_USER and DOCKER_ID_PASSWORD environment variables to DOCKER_USER and DOCKER_PASSWORD respectively
@sheluchin
Copy link

Looking for updated Docker images and this might be the shortest path there. Is this going to continue through the review process? Perhaps we can get updated images created manually if this isn't going to get merged anytime soon?

Copy link

@guessi guessi left a comment

Choose a reason for hiding this comment

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

@rishivikram FYI,
maybe you would like to see my PR at another repository:


RUN apt-get install -y curl;

RUN curl -sS https://deb.nodesource.com/setup_8.x | sudo -E bash -
Copy link

Choose a reason for hiding this comment

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

no need to install curl, it could be replaced by Docker build-in ADD feature
FYI, https://github.com/postmanlabs/newman-docker/pull/89/files#diff-df82f574da54a99527d80ff59fdf5388R10

@@ -0,0 +1,49 @@
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


RUN curl -sS https://deb.nodesource.com/setup_8.x | sudo -E bash -

RUN apt-get clean && apt-get upgrade -y && apt-get update -y --fix-missing && apt-get install -y nodejs
Copy link

Choose a reason for hiding this comment

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

should avoid upgrade inside docker, use FROM ubuntu:14.04 instead

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

kunagpal and others added 5 commits May 8, 2018 15:33
* Added alpine linux repository reference for correct dependency installation
* Compacted multiple ENV statements
* Added validation for build-args
* Switched to installing Node from the debian nodesource repository
* Compacted multiple ENV statements
* Added validation for build-args
* Added validation, coloured output
* Added steps to autopublish the built images
* Updated docker build command to work without caching, remove intermediate image layers
@kunagpal kunagpal changed the title Automate newman docker image version bumps after successful tag build on master branch of newman Added Docker push postpublish script May 8, 2018
@liyinchigithub
Copy link

deprecation !why?

@kunagpal
Copy link
Contributor

kunagpal commented Nov 13, 2018

@liyinchigithub This has now been replaced with https://hub.docker.com/r/postman/newman, which has all tags under one unified repository.

@liyinchigithub
Copy link

I see, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants