<commit_before>#
# Run as root (or with docker permissions).
# Start the docker process, then update NGINX with the new port.
#
BASE_NAME=$(basename $0)
DIR_NAME=$(dirname $0)
VOLUMES="-v /mnt/hi_sinatra-docker/data:/data -v /mnt/hi_sinatra-docker/logs:/logs"
PORTS="-p 8080 -p 8000"
USER="-u root"
IMAGE=eb/any-java
CMD="/usr/bin/docker run -d $VOLUMES $PORTS $USER $IMAGE"
echo "Running command: $CMD"
CONT_ID=$($CMD)

TMP_FILE=/tmp/file$$
/usr/bin/docker inspect $CONT_ID > $TMP_FILE

# Fetch the exposed port from JSON file.
MY_PORT=$($DIR_NAME/JSON.sh -b < $TMP_FILE | grep "HostConfig.*8080.*HostPort" | cut -f2 | sed -e 's/"//g')

# Write the new service port to NGINX config file.

NGINX_CONFIG=/etc/nginx/conf.d/docker.conf
TMP_CONFIG=/tmp/nginx.conf$$

echo "# NGINX config file regenerated by $BASE_NAME script" > $TMP_CONFIG
echo "upstream docker_root {" >> $TMP_CONFIG
grep localhost $NGINX_CONFIG | grep -v $MY_PORT >> $TMP_CONFIG
echo "    server localhost:${MY_PORT};" >> $TMP_CONFIG
cat << EOF >> $TMP_CONFIG
}

server {
    listen 8000;
    location / {
        proxy_pass http://docker_root;
    }
}
EOF

# Kick the nginx process to reload config
/bin/cp -f $TMP_CONFIG $NGINX_CONFIG
/usr/sbin/nginx -s reload

rm -f $TMP_FILE $TMP_CONFIG
<commit_msg>Replace NGINX model with port forwarding at IPTABLES level<commit_after>#
# Run as root (or with docker permissions).
# Start the docker process, then update NGINX with the new port.
#
BASE_NAME=$(basename $0)
DIR_NAME=$(dirname $0)
VOLUMES="-v /mnt/hi_sinatra-docker/data:/data -v /mnt/hi_sinatra-docker/logs:/logs"
PORTS="-p 8080 -p 8000"
USER="-u root"
IMAGE=eb/any-java
TMP_FILE=/tmp/file$$

# Launch the container.
CMD="/usr/bin/docker run -d $VOLUMES $PORTS $USER $IMAGE"
echo "Running command: $CMD"
CONT_ID=$($CMD)

# Fetch the IP address of that container.
MY_IPADDR=$(/usr/bin/docker inspect $CONT_ID | $DIR_NAME/JSON.sh -b | grep "IPAddress" | cut -f2 | sed -e 's/"//g')

# Replace any old 8080 iptable entries with a new rule pointing to that container.
iptables -S -t nat | grep "dport 8080" | sed -e "s/.A DOCKER/iptables -t nat -D DOCKER/" > $TMP_FILE
iptables -t nat -A DOCKER ! -i docker0 -p tcp -m tcp --dport 8080 -j DNAT --to-destination ${MY_IPADDR}:8080
. $TMP_FILE

rm -f $TMP_FILE

{'fraction_non_alphanumeric': 0.14461538461538462, 'fraction_numerical': 0.02065934065934066, 'mean_word_length': 3.9586056644880174, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '3565383', 'n_tokens_mistral': 917, 'n_tokens_neox': 857, 'n_words': 259}