<commit_before>#!/usr/bin/env bash
set -Eeuo pipefail

#
# keter.sh: Like "yesod keter", but works with our split-package project.
#

#
# Options
#

opt_build=${BUILD:=true}
opt_deploy=${DEPLOY:=true}
# NB! Whatever name is used here must also be used in the 'crowdmatch' app
# (crowdmatch/app/crowdmatch.hs), where it is used to pull in postgres
# configuration. Must fix.
opt_appname=${APPNAME:=SnowdriftReboot}

#
#
#

install_path=./website/dist/bin

contents=(
    config
    static
    dist
)

export PGDATABASE=snowdrift_deploy
stack="stack --work-dir .stack-deploy"
dbmake="$stack exec -- make -f db.makefile"

hdr () {
    echo -e "\n-- $@"
}

main () {
    if $opt_build
    then
        hdr "Building"
        if [ -z "$install_path" ]; then
            >&2 echo "Hold up, \$install_path should be specified!"
            exit 1
        fi
        rm -rf ${install_path}
        mkdir -p ${install_path}
        $stack clean
        # Have to do dependencies without --pedantic, since stack still
        # rebuilds extra-deps specified as git repos after a clean. :(
        # Refer to https://github.com/commercialhaskell/stack/issues/1295
        $stack \
            build \
            --dependencies-only \
            --install-ghc
        (trap "$dbmake stop" EXIT
        $dbmake
        $stack \
            --local-bin-path $install_path \
            install \
            --flag Snowdrift:-dev \
            --pedantic
        ) # $dbmake stop
        hdr "Packing executables"
        find ${install_path} -type f -executable | xargs upx
        hdr "Tarballing"
        rm -rf website/static/tmp/*
        # This forces regeneration of the client session key, which will reset
        # everybody's sessions. This is a bug, but it's better than the current
        # behavior of using whatever key is on my system. :|
        # See https://tree.taiga.io/project/snowdrift/issue/401
        rm -f website/config/client_session_key.aes
        tar czf ${opt_appname}.keter -C website ${contents[@]}
    else
        hdr "Not building, as requested"
    fi
    if $opt_deploy
    then
        hdr "Deploying"
        (
            keyfile=$(mktemp)
            trap "rm -f $keyfile" EXIT
            echo $PROD_SSH_KEY > $keyfile
            scp -i $keyfile ${opt_appname}.keter gitlab@${SD_MAIN_INSTANCE_IP}:/opt/keter/incoming
        )
    else
        hdr "Not deploying, as requested"
    fi
}

time main<commit_msg>Supply a host key to scp<commit_after>#!/usr/bin/env bash
set -Eeuo pipefail

#
# keter.sh: Like "yesod keter", but works with our split-package project.
#

#
# Options
#

opt_build=${BUILD:=true}
opt_deploy=${DEPLOY:=true}
# NB! Whatever name is used here must also be used in the 'crowdmatch' app
# (crowdmatch/app/crowdmatch.hs), where it is used to pull in postgres
# configuration. Must fix.
opt_appname=${APPNAME:=SnowdriftReboot}

#
#
#

install_path=./website/dist/bin

contents=(
    config
    static
    dist
)

export PGDATABASE=snowdrift_deploy
stack="stack --work-dir .stack-deploy"
dbmake="$stack exec -- make -f db.makefile"

hdr () {
    echo -e "\n-- $@"
}

main () {
    if $opt_build
    then
        hdr "Building"
        if [ -z "$install_path" ]; then
            >&2 echo "Hold up, \$install_path should be specified!"
            exit 1
        fi
        rm -rf ${install_path}
        mkdir -p ${install_path}
        $stack clean
        # Have to do dependencies without --pedantic, since stack still
        # rebuilds extra-deps specified as git repos after a clean. :(
        # Refer to https://github.com/commercialhaskell/stack/issues/1295
        $stack \
            build \
            --dependencies-only \
            --install-ghc
        (trap "$dbmake stop" EXIT
        $dbmake
        $stack \
            --local-bin-path $install_path \
            install \
            --flag Snowdrift:-dev \
            --pedantic
        ) # $dbmake stop
        hdr "Packing executables"
        find ${install_path} -type f -executable | xargs upx
        hdr "Tarballing"
        rm -rf website/static/tmp/*
        # This forces regeneration of the client session key, which will reset
        # everybody's sessions. This is a bug, but it's better than the current
        # behavior of using whatever key is on my system. :|
        # See https://tree.taiga.io/project/snowdrift/issue/401
        rm -f website/config/client_session_key.aes
        tar czf ${opt_appname}.keter -C website ${contents[@]}
    else
        hdr "Not building, as requested"
    fi
    if $opt_deploy
    then
        hdr "Deploying"
        (
            keyfile=$(mktemp)
            host_keyfile=$(mktemp)
            trap "rm -f $keyfile $host_keyfile" EXIT
            echo $PROD_SSH_KEY > $keyfile
            echo $PROD_HOST_KEY > $host_keyfile
            scp -i $keyfile \
                -o "UserKnownHostsFile $host_keyfile" \
                ${opt_appname}.keter \
                gitlab@${SD_MAIN_INSTANCE_IP}:/opt/keter/incoming
        )
    else
        hdr "Not deploying, as requested"
    fi
}

time main
{'fraction_non_alphanumeric': 0.10672169811320754, 'fraction_numerical': 0.003537735849056604, 'mean_word_length': 1.9725467289719627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 4, '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': '5333546', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1577, 'n_words': 462}