Skip to content

Commit

Permalink
Multi-platform Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Nov 20, 2023
1 parent df3c145 commit a612fbe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-> Promise execution in scripts
-> Stripping JSON comments in the raw mode body
-> ...and several improvements and bug fixes
- Multi-platform Docker images
fixed bugs:
- GH-3146 Fixed a bug where an invalid `folder` input used to exit silently
breaking changes:
Expand Down
62 changes: 29 additions & 33 deletions npm/docker-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
set -e;

LATEST="alpine";
RED="\033[0;31m";
BLUE="\033[0;34m";
NO_COLOUR="\033[0m";
DOCKER_REPO="postman/newman";
VERSION=${npm_package_version};
IMAGES_BASE_PATH="./docker/images";
IMAGES_PLATFORMS="linux/amd64,linux/arm64";
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD);

if [[ ${GIT_BRANCH} != "main" ]]; then
echo -e "$RED Not on main branch! $NO_COLOUR";
exit 1;
fi

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

MAJOR=$(echo ${VERSION} | grep -oE "^\d+");
MINOR=$(echo ${VERSION} | grep -oE "^\d+\.\d+");

function build_docker_image {
local TAG=$(basename $1);
Expand All @@ -24,43 +30,33 @@ function build_docker_image {

echo -e "$BLUE Building $DOCKER_REPO:$VERSION-$TAG $NO_COLOUR";

docker build \
--no-cache --force-rm --squash -t ${DOCKER_REPO}:${VERSION}-${TAG} \
--file="docker/images/$TAG/Dockerfile" --build-arg NEWMAN_VERSION=${VERSION} .;
if [[ ${TAG} == ${LATEST} ]]; then
docker buildx build \
--no-cache --file="docker/images/$TAG/Dockerfile" \
--build-arg NEWMAN_VERSION=${VERSION} --push \
--platform ${IMAGES_PLATFORMS} \
--tag ${DOCKER_REPO}:latest \
--tag ${DOCKER_REPO}:${TAG} \
--tag ${DOCKER_REPO}:${VERSION} \
--tag ${DOCKER_REPO}:${MAJOR} \
--tag ${DOCKER_REPO}:${VERSION}-${TAG} \
--tag ${DOCKER_REPO}:${MAJOR}-${TAG} \
.
else
docker buildx build \
--no-cache --file="docker/images/$TAG/Dockerfile" \
--build-arg NEWMAN_VERSION=${VERSION} --push \
--platform ${IMAGES_PLATFORMS} \
--tag ${DOCKER_REPO}:${TAG} \
--tag ${DOCKER_REPO}:${VERSION}-${TAG} \
--tag ${DOCKER_REPO}:${MAJOR}-${TAG} \
.
fi

echo -e "$BLUE Running docker image test for $DOCKER_REPO:$VERSION-$TAG, latest $NO_COLOUR";

# Test
docker run -v ${PWD}/examples:/etc/newman -t ${DOCKER_REPO}:${VERSION}-${TAG} run "sample-collection.json";

echo -e "$BLUE Pushing docker image for $DOCKER_REPO:$VERSION-$TAG $NO_COLOUR";

# Tag
if [[ ${GIT_BRANCH} == "main" ]]; then
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${TAG};
docker push ${DOCKER_REPO}:${TAG};

if [[ ${TAG} == ${LATEST} ]]; then
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:latest;
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${VERSION};
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${MINOR};
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${MAJOR};

docker push ${DOCKER_REPO}:latest;
docker push ${DOCKER_REPO}:${VERSION};
docker push ${DOCKER_REPO}:${MINOR};
docker push ${DOCKER_REPO}:${MAJOR};
fi
fi

# Push
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${VERSION}-${TAG};
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${MINOR}-${TAG};
docker tag ${DOCKER_REPO}:${VERSION}-${TAG} ${DOCKER_REPO}:${MAJOR}-${TAG};

docker push ${DOCKER_REPO}:${VERSION}-${TAG};
docker push ${DOCKER_REPO}:${MINOR}-${TAG};
docker push ${DOCKER_REPO}:${MAJOR}-${TAG};
}

for image in ${IMAGES_BASE_PATH}/*; do
Expand Down

0 comments on commit a612fbe

Please sign in to comment.