Skip to content

Instantly share code, notes, and snippets.

@tranphuquy19
Last active August 21, 2022 19:39
Show Gist options
  • Save tranphuquy19/0dca3190032fb70f763ee5cada8e904d to your computer and use it in GitHub Desktop.
Save tranphuquy19/0dca3190032fb70f763ee5cada8e904d to your computer and use it in GitHub Desktop.
Angular run.sh file
FROM node:12.22.12-buster-slim as builder
ARG DEBIAN_FRONTEND=noninteractive
ARG NPM_TOKEN=default_value
ARG PROJECT_NAME=web-billing
WORKDIR /${PROJECT_NAME}
RUN npm install -g vsts-npm-auth && \
apt update -y && \
apt install chromium chromium-driver -y
COPY package.json package-lock.json ./
COPY .npmrc.docker ./.npmrc
RUN npm install
FROM builder as tester
ENV NPM_TOKEN=${NPM_TOKEN}
ENV CHROME_BIN=/usr/bin/chromium
COPY . ./
CMD chmod +x ./run.sh
ENTRYPOINT ["/bin/bash", "-c", "./run.sh test"]
#!/bin/bash
# Example commands:
# bash run.sh test # Run the unit tests
# bash run.sh start # Start the dev server
# bash run.sh docker test [flags] # Run the unit tests inside a docker container, with flags are docker build flags (ex: --no-cache)
export NODE_OPTIONS=--max-old-space-size=12288
export DOCKER_BUILDKIT=1
# NOTICE: Replace this token with your own token.
NPM_TOKEN=$NPM_TOKEN
PROJECT_NAME=web-billing
TMP_PATH="./tmp"
CRT_UNIX_TIME=$(date +%s)
CRT_TIME=$(date +%Y-%m-%d_%H-%M-%S)
LOG_FILE_NAME="$((10000000000 - CRT_UNIX_TIME))-$CRT_TIME.log"
if [[ "$1" == "test" ]]; then
echo "mkdir -p $TMP_PATH/_logs"
mkdir -p $TMP_PATH/_logs
if [[ -n "$2" ]]; then
LOG_FILE_NAME="$2.log"
fi
LOG_FILE_PATH="$TMP_PATH/_logs/$LOG_FILE_NAME"
echo "npm test -- --code-coverage --source-map=false --browsers=ChromeHeadlessNoSandbox --watch=false --reporters=progress,trx,coverage-istanbul,coverage | sed -r \"s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g\" 2>&1 | tee $LOG_FILE_PATH"
npm test -- --code-coverage --source-map=false --browsers=ChromeHeadlessNoSandbox --watch=false --reporters=progress,trx,coverage-istanbul,coverage | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" 2>&1 | tee "$LOG_FILE_PATH"
echo "Log file: $LOG_FILE_PATH"
echo "Type Ctrl+C to exit"
tail -f /dev/null
exit 0
elif [[ "$1" == "start" ]]; then
echo "yarn start"
yarn start
elif [[ "$1" == "clean" ]]; then
echo "Removing node_modules folder"
echo "rm -rf ./node_modules"
rm -rf node_modules
# Default node package manager is yarn
if [[ "$2" == "npm" ]]; then
echo "npm install"
npm install
else
echo "yarn install"
yarn install
fi
elif [[ "$1" == "docker" ]]; then
if [[ "$2" == "test" ]]; then
echo "Building tester image"
docker build --build-arg NPM_TOKEN=$NPM_TOKEN -t $PROJECT_NAME-worker:tester --target tester . $3 || { echo "Failed to build tester image"; exit 1; }
echo "Testing.."
docker run -it --rm -v "$PWD"/tmp:/$PROJECT_NAME/tmp --name "${PROJECT_NAME}_${CRT_UNIX_TIME}" $PROJECT_NAME-worker:tester
echo "Cleaning..."
docker container prune -f
docker image prune -f
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment