#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

cd $DIR/../
# always rebuild and include all GEMs
docker build --build-arg "BUNDLER_ARGS=--jobs=8" -t wpscan:rspec .
# update all gems (this updates Gemfile.lock on the host)
# this also needs some build dependencies
docker run --rm -u root -v $DIR/../Gemfile.lock:/wpscan/Gemfile.lock --entrypoint "" wpscan:rspec sh -c 'apk add --no-cache alpine-sdk ruby-dev libffi-dev zlib-dev && bundle update'
# rebuild image with latest GEMs
docker build --build-arg "BUNDLER_ARGS=--jobs=8" -t wpscan:rspec .
# run spec
docker run --rm -v $DIR/../:/wpscan --entrypoint "" wpscan:rspec rspec

