From 1570ae3df7f76a94f8749f72e2b6407e01744ea8 Mon Sep 17 00:00:00 2001 From: Jarl Friis Date: Fri, 11 Jul 2025 13:26:44 +0200 Subject: [PATCH 1/3] Initial Dockerfile for self-contained building --- Dockerfile | 19 ++++++++++++++++++- Dockerfile.dockerignore | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.dockerignore diff --git a/Dockerfile b/Dockerfile index 686fc60f5..0b0c1da99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,28 @@ # syntax=docker/dockerfile:1 +FROM node:18-alpine AS builder +ADD . . +# Validate versions +RUN node -v && npm -v +# Install Dependencies +RUN npm ci +# Version +RUN node tasks/version.js +# Docs and Static Analysis +RUN npm run lint || true +RUN scripts/codeclimate +# RUN cat ./coverage/lcov.info | node_modules/coveralls/bin/coveralls.js +# RUN scripts/sonar +RUN npm run jsdoc +# RUN node tasks/deploy/docs.js +# Dist +RUN node tasks/dist.js FROM node:18-alpine WORKDIR /app # Install tarball to allow the command to be 'mb' instead of 'bin/mb' -COPY mountebank-*.tgz ./ +COPY --from=builder dist/mountebank/mountebank-*.tgz ./ RUN npm install --production -g mountebank-*.tgz && npm cache clean -f # Run as a non-root user diff --git a/Dockerfile.dockerignore b/Dockerfile.dockerignore new file mode 100644 index 000000000..e453f0391 --- /dev/null +++ b/Dockerfile.dockerignore @@ -0,0 +1,29 @@ +# Ignore everything that is not white listed below +* + +!/.codeclimate.yml +!/.eslintignore +!/.eslintrc +!/.jsdoc +!/.mdlrc +!/.npmrc +!/.nvmrc +!/.scannerwork +!/CODE_OF_CONDUCT.md +!/CONTRIBUTING.md +!/Dockerfile +!/Dockerfile.dockerignore +!/LICENSE +!/README.md +!/bin +!/docs +!/images +!/mbTest +!/package-lock.json +!/package.json +!/releases.json +!/scripts +!/src +!/tasks +!/test + From 0f981b5677e5b5b0497029bb224b4d3ad42806b3 Mon Sep 17 00:00:00 2001 From: Jarl Friis Date: Mon, 4 Aug 2025 14:43:45 +0200 Subject: [PATCH 2/3] Reduce Dockerfile --- Dockerfile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0b0c1da99..bd8ff7ea4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,13 +7,7 @@ RUN node -v && npm -v RUN npm ci # Version RUN node tasks/version.js -# Docs and Static Analysis -RUN npm run lint || true -RUN scripts/codeclimate -# RUN cat ./coverage/lcov.info | node_modules/coveralls/bin/coveralls.js -# RUN scripts/sonar RUN npm run jsdoc -# RUN node tasks/deploy/docs.js # Dist RUN node tasks/dist.js From cf3deb6947771ecf25d37ad6294dc748aa50f3f2 Mon Sep 17 00:00:00 2001 From: Jarl Friis Date: Mon, 4 Aug 2025 14:43:57 +0200 Subject: [PATCH 3/3] Building docker image using docker container --- .circleci/config.yml | 56 ++++++++++++++++++++++++++++++++++--------- scripts/publishDocker | 18 -------------- 2 files changed, 45 insertions(+), 29 deletions(-) delete mode 100755 scripts/publishDocker diff --git a/.circleci/config.yml b/.circleci/config.yml index 071464771..293be7250 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -214,6 +214,35 @@ jobs: (cd dist/test && npm run web) - store_test_results: path: dist/test/testResults + dockerBuildPush: + parameters: + release: + type: boolean + default: false + docker: + - image: cimg/base:stable + steps: + - checkout + - setup_remote_docker: + docker_layer_caching: true + - run: | + echo export MB_VERSION=`grep version package.json | sed -e 's/^ "version": "\(.*\)", */\1/'` >> "$BASH_ENV" + - run: | + if [ "<>" = "true" ]; then + export DOCKER_MB_ALIAS=$([ "$CIRCLE_BRANCH" = "master" ] && echo beta || echo "$CIRCLE_BRANCH") + echo export DOCKER_MB_ALIAS="$DOCKER_MB_ALIAS" >> "$BASH_ENV" + # echo export DOCKER_MB_VERSION=$MB_VERSION-$DOCKER_MB_ALIAS-$CIRCLE_BUILD_NUM-$(echo $CIRCLE_SHA1 | cut -c1-7) >> "$BASH_ENV" + echo export DOCKER_MB_VERSION=$MB_VERSION-$DOCKER_MB_ALIAS-$CIRCLE_BUILD_NUM >> "$BASH_ENV" + else + echo export DOCKER_MB_ALIAS="latest" >> "$BASH_ENV" + echo export DOCKER_MB_VERSION=$MB_VERSION >> "$BASH_ENV" + fi + - run: echo bbyars/mountebank:$DOCKER_MB_VERSION + - run: echo bbyars/mountebank:$DOCKER_MB_ALIAS + - run: docker context create mountebank + - run: docker buildx create --driver docker-container mountebank --use + - run: echo "$DOCKER_PASSWORD" | docker login -u $DOCKER_USER --password-stdin + - run: docker buildx build --platform=linux/arm64,linux/amd64 --tag bbyars/mountebank:$DOCKER_MB_VERSION --tag bbyars/mountebank:$$DOCKER_MB_ALIAS --push . deploy: executor: node-active @@ -225,11 +254,6 @@ jobs: - run: name: Publish npm command: scripts/publishNpm - - run: - name: Publish Docker - command: | - export MB_VERSION=`scripts/printVersion` - scripts/publishDocker $MB_VERSION - run: name: Deploy to Heroku command: scripts/publishHeroku mountebank-dev @@ -253,11 +277,6 @@ jobs: - run: name: Publish npm command: scripts/publishNpm - - run: - name: Publish Docker - command: | - export MB_VERSION=`scripts/printVersion` - scripts/publishDocker $MB_VERSION - run: name: Deploy to Heroku command: scripts/publishHeroku mountebank @@ -308,6 +327,15 @@ workflows: filters: branches: only: master + - dockerBuildPush: + requires: # These are technically not necessary + - maintenanceOutOfProcessImposters + - currentWithFileDB + - performance + - web + filters: + branches: + only: master - deploy: requires: - maintenanceOutOfProcessImposters @@ -325,4 +353,10 @@ workflows: ignore: /.*/ tags: only: /^v.*/ - + - dockerBuildPush: + release: true + filters: + branches: + ignore: /.*/ + tags: + only: /^v.*/ diff --git a/scripts/publishDocker b/scripts/publishDocker deleted file mode 100755 index 8e745f951..000000000 --- a/scripts/publishDocker +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -set -e - -VERSION=$1 -TAG=beta -if [ "$MB_RELEASE" = "true" ]; then - TAG=latest -fi - -cd dist/mountebank -docker context create mountebank -docker buildx create mountebank --use -# https://stackoverflow.com/questions/72167570/docker-buildx-nodejs-fail -docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -docker login --username $DOCKER_USER --password "$DOCKER_PASSWORD" -docker buildx build --platform=linux/arm64,linux/amd64 --no-cache --tag bbyars/mountebank:$MB_VERSION --tag bbyars/mountebank:$TAG --push . -