#!/bin/bash

QUICKSTART_VERSION="0.1.2"
PWD=`pwd`

# Defaults
maintainer_string="# MAINTAINER Darth Vader <darth@thedeathstar.io>"

echo "\n>> meteor-tupperware quickstart script $QUICKSTART_VERSION\n"

if [[ -f $PWD/Dockerfile || -f $PWD/.dockerignore ]]; then
  echo "! A Dockerfile or .dockerignore file already exists in this directory, $PWD. Please check, remove them and rerun this tool."
  exit 1
fi

echo "] Docker Image Maintainer Information"
echo "? Please enter your name: "
read user_name
if [[ ! -z "$user_name" ]]; then
  maintainer="$user_name"

  echo "? Thanks, $user_name. Now your e-mail address:"
  read user_email
    if [[ ! -z "$user_email" ]]; then
      maintainer="$maintainer <$user_email>"
    fi
  maintainer_string="MAINTAINER $maintainer"
  echo "> Got it. The image maintainer will be set to: $maintainer"
fi

cat <<EOF > ./Dockerfile
# Generated by meteor-tupperware quickstart script $QUICKSTART_VERSION
# https://github.com/chriswessels/meteor-tupperware

# Inherit from chriswessels/meteor-tupperware image
FROM quay.io/chriswessels/meteor-tupperware

# The maintainer of your app image
$maintainer_string

# (optional) Bake runtime options into your image
# ENV MONGO_URL="mongodb://url" MONGO_OPLOG_URL="mongodb://oplog_url" ROOT_URL="http://yourapp.com"
EOF

cat <<EOF > ./.dockerignore
.meteor/local
packages/*/.build*
packages/*/.npm*
EOF

echo "\n] Success"
echo "> Wrote Dockerfile and .dockerignore to $PWD. Assuming you have Docker running, you can now build your app image with:"
echo "$ docker build -t yourname/app ."
