Skip to content
Snippets Groups Projects
run.sh 3.27 KiB
Newer Older
Dean Lovett's avatar
Dean Lovett committed
#!/bin/bash

set -e

Dean Lovett's avatar
Dean Lovett committed
display_help() {
  echo "Nexus Mods Development Tools"
Dean Lovett's avatar
Dean Lovett committed
    echo " "
    echo "commands:"
    echo "down                        Stops a docker-compose service"
    echo "up                          Starts a docker-compose service in the background"
    echo "build                       Builds the local image(s) for a docker-compose service. Allows docker-compose build arguments"
    echo "restart                     Stops and then starts a docker-compose service"
    echo "rebuild                     Stops, builds and then starts a docker-compose service"
Rory Jennings's avatar
Rory Jennings committed
    echo "logs                        Shows the logs for a docker-compose service"
Dean Lovett's avatar
Dean Lovett committed
    echo "cq, code-quality            Runs the nexus code quality tool"
    echo "gu, gemfile-updater         Runs the gemfile updater tool, outputting common gemfiles in the console"
    echo "bu, bundle-update           Mounts the Gemfile and lockfile and runs bundle update."
    echo "-v, version                 Outputs the current version of this tool"
Dean Lovett's avatar
Dean Lovett committed
    echo "update                      Updates this script to the latest version."
Dean Lovett's avatar
Dean Lovett committed
    echo "-h, --help                  show brief help"
Rory Jennings's avatar
Rory Jennings committed
    echo " "
    echo "options:"
    echo "--logs                      Can be appended to up, restart or rebuild to tail the logs for the docker-compose service"
Dean Lovett's avatar
Dean Lovett committed
}

case "$1" in
  -h|--help)
    display_help
Dean Lovett's avatar
Dean Lovett committed
    exit 0
    ;;
  down)
James King's avatar
James King committed
    docker-compose down --remove-orphans
Dean Lovett's avatar
Dean Lovett committed
    ;;
  up)
    docker-compose up -d
    if [ "$2" == '--logs' ]
    then
    docker-compose logs -f
    fi
Dean Lovett's avatar
Dean Lovett committed
    ;;
  build)
    shift
    docker-compose build "$@"
    ;;
  restart)
    docker-compose down && docker-compose up  -d
    if [ "$2" == '--logs' ]
    then
    docker-compose logs -f
    fi
Dean Lovett's avatar
Dean Lovett committed
    ;;
  rebuild)
    docker-compose down && docker-compose build && docker-compose up  -d
    if [ "$2" == '--logs' ]
    then
    docker-compose logs -f
    fi
Dean Lovett's avatar
Dean Lovett committed
    ;;
Rory Jennings's avatar
Rory Jennings committed
  logs)
    docker-compose logs -f
    ;;
Dean Lovett's avatar
Dean Lovett committed
  cq|code-quality)
    shift
Dean Lovett's avatar
Dean Lovett committed
    CQ_IMAGE=registry.nexusmods.com/nexus-mods/devops/tools/nexus-code-quality:stable
    docker pull $CQ_IMAGE
    docker run --rm -v "$PWD":/app/mounted $CQ_IMAGE "$@"
Dean Lovett's avatar
Dean Lovett committed
    ;;
  gu|gemfile-updater)
    shift
Dean Lovett's avatar
Dean Lovett committed
    GU_IMAGE=registry.nexusmods.com/nexus-mods/devops/tools/base-image-gemfile-updater:stable
    docker pull $GU_IMAGE
    docker run --rm -it -v "$(pwd)":/app -v /usr/local/bundle:/usr/local/bundle $GU_IMAGE "$@"
Dean Lovett's avatar
Dean Lovett committed
    ;;
  bu|bundle-update)
    shift
    docker run --rm -it -v "$(pwd)":/app -v /usr/local/bundle:/usr/local/bundle gitlab.nexdev.uk:5555/pub/bundle-updater:v1.0.7 "$@"
Dean Lovett's avatar
Dean Lovett committed
    echo "Container now must be rebuilt!"
    ;;
  -v|version)
Dean Lovett's avatar
Dean Lovett committed
    shift
Dean Lovett's avatar
Dean Lovett committed
    version=`cat ~/nexus-tools/VERSION`
Dean Lovett's avatar
Dean Lovett committed
    echo "$version"
Dean Lovett's avatar
Dean Lovett committed
    echo "Downloading new version"
    wget https://gitlab.nexdev.uk/pub/nexus-tools/-/raw/master/run.sh -O ~/nexus-tools/nexus-tools.sh
    wget https://gitlab.nexdev.uk/pub/nexus-tools/-/raw/master/NEXUS_TOOLS_VERSION -O ~/nexus-tools/VERSION
Dean Lovett's avatar
Dean Lovett committed
  *)
    display_help
    ;;
Dean Lovett's avatar
Dean Lovett committed
esac
Dean Lovett's avatar
Dean Lovett committed
wget -q https://gitlab.nexdev.uk/pub/nexus-tools/-/raw/master/NEXUS_TOOLS_VERSION -O ~/nexus-tools/LATEST_VERSION

if ! cmp -s ~/nexus-tools/LATEST_VERSION ~/nexus-tools/VERSION; then

    echo
    echo -e "\e[31mWARNING: A newer version of nexus-tools is available, to update run:\e[0m"
    echo '    nexus update'
    echo
fi