<commit_before>#!/bin/bash
# confgure docker to not require sudo

# exit whenever a command returns with a non-zero exit code
set -e
set -o pipefail

DOCKER_USER="kahaco"
APP_NAME="kaha"
DOCKER_IMAGE="${DOCKER_USER}/${APP_NAME}:latest"
APP_PORT=3000
DB_CONTAINER="redis"
PROD_DB_PASS="<PASSWORD>"
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/change_this"
SLACK_CHANNEL="#deploy"

success=false
env=$1
container="${APP_NAME}_${env}"

# post to slack
function notify {
  echo "$1"
  curl -X POST "$SLACK_WEBHOOK_URL" --data-urlencode 'payload={
    "channel": "'"$SLACK_CHANNEL"'",
    "username": "deploybot",
    "text": "'"$1"'",
    "icon_emoji": ":ghost:"}'
}

# On exit, always do this
function finish {
  if [ "$success" = true ]; then
    notify "Deploy was successful! Check the site just to be sure :)"
    exit 0
  else
    notify "Deploy was unsuccessful :( Check the server logs. \nIf the site is down, you can restore the site by doing 'docker start kaha_prod_previous'"
    exit -1
  fi
}
trap finish EXIT

if [ "$env" != "dev" ] && [ "$env" != "stage" ] && [ "$env" != "prod" ]; then
  echo "usage : deploy_kaha.sh <environment>"
  echo "Available environments are dev, stage and prod"
  exit -1
fi

echo "Getting the image from docker hub..."
docker pull "$DOCKER_IMAGE"

# alternative to above
#echo "Building the docker image locally"
#docker build -t "$DOCKER_IMAGE" .

if docker ps | grep -q "$container"; then
  echo "Stopping running container..."
  docker stop "$container"
fi

if docker ps -a | grep -q "$container"; then
  container_backup="${container}_previous"

  echo "Removing previous container backup..."
  docker ps -a | grep -q "$container_backup" && docker rm "$container_backup"<commit_msg>Switch to local image build for faster deploy with CI<commit_after>#!/bin/bash
# confgure docker to not require sudo

# exit whenever a command returns with a non-zero exit code
set -e
set -o pipefail

DOCKER_USER="kahaco"
APP_NAME="kaha"
DOCKER_IMAGE="${DOCKER_USER}/${APP_NAME}:latest"
APP_PORT=3000
DB_CONTAINER="redis"
PROD_DB_PASS="<PASSWORD>"
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/change_this"
SLACK_CHANNEL="#deploy"

success=false
env=$1
container="${APP_NAME}_${env}"

# post to slack
function notify {
  echo "$1"
  curl -X POST "$SLACK_WEBHOOK_URL" --data-urlencode 'payload={
    "channel": "'"$SLACK_CHANNEL"'",
    "username": "deploybot",
    "text": "'"$1"'",
    "icon_emoji": ":ghost:"}'
}

# On exit, always do this
function finish {
  if [ "$success" = true ]; then
    notify "Deploy was successful! Check the site just to be sure :)"
    exit 0
  else
    notify "Deploy was unsuccessful :( Check the server logs. \nIf the site is down, you can restore the site by doing 'docker start kaha_prod_previous'"
    exit -1
  fi
}
trap finish EXIT

if [ "$env" != "dev" ] && [ "$env" != "stage" ] && [ "$env" != "prod" ]; then
  echo "usage : deploy_kaha.sh <environment>"
  echo "Available environments are dev, stage and prod"
  exit -1
fi

# This could have worked but docker hub builds are slow the hub webhook was not working.
# That's why we build the image locally. Maybe move this to our own private registry later
#echo "Getting the image from docker hub..."
#docker pull "$DOCKER_IMAGE"

echo "Pulling the latest changes to the repo..."
git pull origin master
echo "Building the docker image locally..."
docker build -t "$DOCKER_IMAGE" .
echo "Cleaning up..."
docker rmi $(docker images -q -f dangling=true)

running_containers=$(docker ps -q --filter="name=${APP_NAME}")

if [ -n "$running_containers" ]; then
  echo "Stopping running app containers..."
  docker stop "$running_containers"
fi

if docker ps -a | grep -q "$container"; then
  container_backup="${container}_previous"

  echo "Removing previous container backup if any..."
  docker ps -a | grep -q "$container_backup" && docker rm "$container_backup"
{'fraction_non_alphanumeric': 0.13635194237200926, 'fraction_numerical': 0.005145356315924878, 'mean_word_length': 4.254054054054054, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3895760', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1254, 'n_words': 447}