<commit_before>#!/bin/bash
$(/usr/local/bin/boot2docker shellinit)

BUILD_DIR=./build

_clean() {

  if [ -d $BUILD_DIR ]; then
    rm -R $BUILD_DIR
  fi

  docker rmi build_master
  docker rmi build_masterprocessor
  docker rmi build_worker
}

# make build dirs
_make_build_dir() {
  echo build directory $BUILD_DIR
  mkdir -p $BUILD_DIR
}

_copy_app() {
  build_dir=$1
  # copy the dirs and files that should be in the image
  for dir in app bin config db lib public vendor; do
    cp -a $dir $build_dir
  done

  for dir in log tmp; do
    mkdir -p $build_dir/$dir
  done

  for file in config.ru Gemfile Gemfile.lock LICENSE Rakefile .dockerignore .gitignore; do
    cp -a $file $build_dir
  done
}

_prepare() {
  _make_build_dir
  cp -a container/docker-compose.yml $BUILD_DIR
}

_prepare_image() {
  image_name=$1

  # create a dir for master
  image_build_dir=$BUILD_DIR/$image_name
  echo $image_name build directory $image_build_dir

  mkdir -p $image_build_dir

  _copy_app $image_build_dir

  cp -a container/images/scripts $image_build_dir
  cp -a container/images/$image_name/ $image_build_dir
}

_build() {
  _prepare
  _prepare_image master
  _prepare_image master_processor
  _prepare_image worker

  docker-compose -f $BUILD_DIR/docker-compose.yml build
}

_up() {
  docker-compose -f $BUILD_DIR/docker-compose.yml up
}

if [ "$1" = "clean" ]; then
  _clean
elif [ "$1" = "up" ]; then
  _up
else
  _build
fi<commit_msg>add in tls/ssl - still need to add build script for ssl gen, but is in a comment<commit_after>#!/bin/bash
$(/usr/local/bin/boot2docker shellinit)

BUILD_DIR=./build

_clean() {

  if [ -d $BUILD_DIR ]; then
    rm -R $BUILD_DIR
  fi

  docker rmi build_master
  docker rmi build_masterprocessor
  docker rmi build_worker
}

# make build dirs
_make_build_dir() {
  echo build directory $BUILD_DIR
  mkdir -p $BUILD_DIR
}

_copy_app() {
  build_dir=$1
  # copy the dirs and files that should be in the image
  for dir in app bin config db lib public vendor; do
    cp -a $dir $build_dir
  done

  for dir in log tmp; do
    mkdir -p $build_dir/$dir
  done

  for file in config.ru Gemfile Gemfile.lock LICENSE Rakefile .dockerignore .gitignore; do
    cp -a $file $build_dir
  done
}

_prepare() {
  _make_build_dir
  cp -a container/docker-compose.yml $BUILD_DIR
}

_prepare_image() {
  image_name=$1

  # create a dir for master
  image_build_dir=$BUILD_DIR/$image_name
  echo $image_name build directory $image_build_dir

  mkdir -p $image_build_dir

  _copy_app $image_build_dir

  cp -a container/images/scripts $image_build_dir
  cp -a container/images/$image_name/ $image_build_dir
}

_prepare_container_files() {
  mkdir -p ~/fixer/tls
  cp -a container/tls/ ~/fixer/tls
}

_build() {
  _prepare
  _prepare_container_files
  _prepare_image master
  _prepare_image master_processor
  _prepare_image worker

  docker-compose -f $BUILD_DIR/docker-compose.yml build
}

_up() {
  docker-compose -f $BUILD_DIR/docker-compose.yml up
}

if [ "$1" = "clean" ]; then
  _clean
elif [ "$1" = "up" ]; then
  _up
else
  _build
fi


# Add in the ssl cert and key generation
# openssl req \
#   -new \
#   -newkey rsa:2048 \
#   -sha256 \
#   -days 3650 \
#   -nodes \
#   -x509 \
#   -keyout container/tls/ssl.key \
#   -out container/tls/ssl.crt \
#   -config container/tls/openssl.cnf


# docker rmi $(docker images | grep "^<none>" | awk '{ print $3 }')
{'fraction_non_alphanumeric': 0.09988179669030733, 'fraction_numerical': 0.007387706855791962, 'mean_word_length': 3.2902408111533585, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4501519', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1240, 'n_words': 357}