jpschewe / fll-sw

FIRST Lego League scoring software
http://jpschewe.github.io/fll-sw/
GNU General Public License v2.0
10 stars 7 forks source link

Setup continuous deployment #1098

Closed jpschewe closed 1 year ago

jpschewe commented 1 year ago

Have all builds on main automatically update demo.fll-sw.mtu.net or another similar site.

jpschewe commented 1 year ago

One can get the tar.gz with

url="https://jenkins.mtu.net/job/FLL-SW/job/main/lastSuccessfulBuild/artifact/$(curl --silent https://jenkins.mtu.net/job/FLL-SW/job/main/lastSuccessfulBuild/api/json | jq -r '.artifacts[].relativePath' | grep distributions | grep linux)"
curl --silent -O "${url}"
jpschewe commented 1 year ago

Get filename with

echo ${url} | awk -F/ '{print $NF}'
jpschewe commented 1 year ago
tar -xzf ${filename}
dirname=$(basename "${filename}" .tar.gz)
jpschewe commented 1 year ago

Can use this using polling

#!/bin/sh

debug() { ! "${log_debug-false}" || log "DEBUG: $*" >&2; }
log() { printf '%s\n' "$*"; }
warn() { log "WARNING: $*" >&2; }
error() { log "ERROR: $*" >&2; }
fatal() { error "$*"; exit 1; }
try() { "$@" || fatal "'$@' failed"; }

mydir=$(cd "$(dirname "$0")" && pwd -L) || fatal "Unable to determine script directory"

cleanup() {
    debug "In cleanup"
}
trap 'cleanup' INT TERM EXIT

fetch_extract() {
    try curl --silent -O "${url}"
    try tar -xzf ${filename}
    try ln -s "${dirname}" current
}

release_file=$(curl --silent https://jenkins.mtu.net/job/FLL-SW/job/main/lastSuccessfulBuild/api/json | jq -r '.artifacts[].relativePath' | grep distributions | grep linux)
url="https://jenkins.mtu.net/job/FLL-SW/job/main/lastSuccessfulBuild/artifact/${release_file}"
filename=$(echo ${url} | awk -F/ '{print $NF}')
dirname=$(basename "${filename}" .tar.gz)

if [ -e current ]; then
    if [ -L current ]; then
        target_link=$(readlink current)
        if [ "${target_link}" = "${dirname}" ]; then
            debug "New release is the same as the current, no change needed"
            exit 0
        fi

        try rm current
        fetch_extract
        cd current
        log ../launch.sh --migrate ../${target_link}
    else
        fatal "current exists and is NOT a symlink"
    fi
else
    fetch_extract
    try cd current
    log ../launch.sh
fi
jpschewe commented 1 year ago

Still need to kill off the existing process.

jpschewe commented 1 year ago

Have a shell script that kills the process and starts a new one. One issue is that I don't have the standard output anywhere, although I'm not sure if I care.

jpschewe commented 1 year ago

I have a script setup and running on the server. I should have a way for old versions to be removed so that the disk doesn't get filled up.

Also consider running as a service.

jpschewe commented 1 year ago

I created a service for fll2 today. See how this goes.

jpschewe commented 1 year ago

I've got services for all of the sites up and a service for the deploy script.