<commit_before>#!/usr/bin/env bash

set -eux

RUBY=$(mktemp)

cat << EOS > $RUBY
require 'yaml';
require 'json';

conf = YAML.load_file( "provision/default.yml" );

if File.exists?( 'site.yml' )
  site = YAML.load(
    File.open(
      'site.yml',
      File::RDONLY
    ).read
  )
  conf.merge!( site ) if site.is_a?( Hash )
end

if ENV['VCCW_ENV'].instance_of?( String )
  site = JSON.parse( ENV['VCCW_ENV'] );
  conf.merge!( site ) if site.is_a?( Hash );
end

conf[:vagrant_dir] = "/vagrant";
puts JSON.generate( { :vccw => conf } );
EOS

VCCW_CONFIG=$(ruby $RUBY)
VCCW_HOSTNAME=$(echo $VCCW_CONFIG | jq -r .vccw.hostname)

docker pull vccw/vccw-xenial64

docker run -idt -p 80:80 -p 443:443 \
--name=${VCCW_HOSTNAME} \
--add-host=${VCCW_HOSTNAME}:127.0.0.1 \
--privileged \
--volume="$(pwd)":${VM_DIR}/:rw \
vccw/vccw-xenial64:latest \
"/sbin/init"

docker exec --user ubuntu --tty ${VCCW_HOSTNAME} \
env TERM=xterm ansible-playbook ${VM_DIR}/provision/playbook.yml -e "$(ruby $RUBY)"<commit_msg>to be writeable vm_dir for docker<commit_after>#!/usr/bin/env bash

set -eux

RUBY=$(mktemp)

cat << EOS > $RUBY
require 'yaml';
require 'json';

conf = YAML.load_file( "provision/default.yml" );

if File.exists?( 'site.yml' )
  site = YAML.load(
    File.open(
      'site.yml',
      File::RDONLY
    ).read
  )
  conf.merge!( site ) if site.is_a?( Hash )
end

if ENV['VCCW_ENV'].instance_of?( String )
  site = JSON.parse( ENV['VCCW_ENV'] );
  conf.merge!( site ) if site.is_a?( Hash );
end

conf[:vagrant_dir] = "/vagrant";
puts JSON.generate( { :vccw => conf } );
EOS

VCCW_CONFIG=$(ruby $RUBY)
VCCW_HOSTNAME=$(echo $VCCW_CONFIG | jq -r .vccw.hostname)

docker pull vccw/vccw-xenial64

docker run -idt -p 80:80 -p 443:443 \
--name=${VCCW_HOSTNAME} \
--add-host=${VCCW_HOSTNAME}:127.0.0.1 \
--privileged \
--volume="$(pwd)":${VM_DIR}/:rw \
vccw/vccw-xenial64:latest \
"/sbin/init"

docker exec --user ubuntu --tty ${VCCW_HOSTNAME} \
env TERM=xterm chmod -R 777 ${VM_DIR}

docker exec --user ubuntu --tty ${VCCW_HOSTNAME} \
env TERM=xterm ansible-playbook ${VM_DIR}/provision/playbook.yml -e "$(ruby $RUBY)"
{'fraction_non_alphanumeric': 0.1900473933649289, 'fraction_numerical': 0.02037914691943128, 'mean_word_length': 3.649779735682819, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5957562', 'n_tokens_mistral': 982, 'n_tokens_neox': 909, 'n_words': 186}