diff --git a/.github/workflows/ci_functests-install.yml b/.github/workflows/ci_functests-install.yml index 841720c0b..380353c4b 100644 --- a/.github/workflows/ci_functests-install.yml +++ b/.github/workflows/ci_functests-install.yml @@ -22,11 +22,17 @@ jobs: id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 + - id: keydb + uses: pozetroninc/github-action-get-latest-release@master + with: + owner: crowdsecurity + repo: crowdsec + excludes: draft - name: Build release - run: BUILD_VERSION=xxx make release + run: BUILD_VERSION=${{ steps.keydb.outputs.release }} make release - name: Install release run: | - cd crowdsec-xxx + cd crowdsec-${{ steps.keydb.outputs.release }} sudo bash -x ./wizard.sh --bininstall sudo cscli machines add -a - name: Post-installation check diff --git a/.github/workflows/ci_functests-upgrade.yml b/.github/workflows/ci_functests-upgrade.yml index 1bbefaac9..517ca58ac 100644 --- a/.github/workflows/ci_functests-upgrade.yml +++ b/.github/workflows/ci_functests-upgrade.yml @@ -25,9 +25,15 @@ jobs: - name: install ipset for bouncer run: | sudo apt update - sudo apt install ipset + sudo apt install ipset git + - id: keydb + uses: pozetroninc/github-action-get-latest-release@master + with: + owner: crowdsecurity + repo: crowdsec + excludes: draft - name: run tests run: | cd scripts - sudo ./test_wizard_upgrade.sh + sudo ./test_wizard_upgrade.sh --version ${{ steps.keydb.outputs.release }} diff --git a/cmd/crowdsec-cli/utils.go b/cmd/crowdsec-cli/utils.go index 003181bc8..8bd37215d 100644 --- a/cmd/crowdsec-cli/utils.go +++ b/cmd/crowdsec-cli/utils.go @@ -71,23 +71,22 @@ func setHubBranch() error { /* if no branch has been specified in flags for the hub, then use the one corresponding to crowdsec version */ - if cwhub.HubBranch == "" { latest, err := cwversion.Latest() if err != nil { cwhub.HubBranch = "master" return err } - - if cwversion.Version == latest { + csVersion := cwversion.VersionStrip() + if csVersion == latest { cwhub.HubBranch = "master" - } else if semver.Compare(cwversion.Version, latest) == 1 { // if current version is greater than the latest we are in pre-release - log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", cwversion.Version) + } else if semver.Compare(csVersion, latest) == 1 { // if current version is greater than the latest we are in pre-release + log.Debugf("Your current crowdsec version seems to be a pre-release (%s)", csVersion) cwhub.HubBranch = "master" } else { - log.Warnf("Crowdsec is not the latest version. Current version is '%s' and latest version is '%s'. Please update it!", cwversion.Version, latest) + log.Warnf("Crowdsec is not the latest version. Current version is '%s' and the latest stable version is '%s'. Please update it!", csVersion, latest) log.Warnf("As a result, you will not be able to use parsers/scenarios/collections added to Crowdsec Hub after CrowdSec %s", latest) - cwhub.HubBranch = cwversion.Version + cwhub.HubBranch = csVersion } log.Debugf("Using branch '%s' for the hub", cwhub.HubBranch) } diff --git a/config/config.yaml b/config/config.yaml index 73d89eab2..3f9777a80 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -16,7 +16,6 @@ crowdsec_service: parser_routines: 1 cscli: output: human - hub_branch: master db_config: log_level: info type: sqlite diff --git a/pkg/cwversion/version.go b/pkg/cwversion/version.go index 6572ccf62..28ca180f4 100644 --- a/pkg/cwversion/version.go +++ b/pkg/cwversion/version.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "strings" version "github.com/hashicorp/go-version" ) @@ -57,6 +58,11 @@ func VersionStr() string { return fmt.Sprintf("%s-%s", Version, Tag) } +func VersionStrip() string { + version := strings.Split(Version, "-") + return version[0] +} + func Statisfies(strvers string, constraint string) (bool, error) { vers, err := version.NewVersion(strvers) if err != nil { diff --git a/pkg/database/machines.go b/pkg/database/machines.go index 4b2da779a..0b5bfb8a7 100644 --- a/pkg/database/machines.go +++ b/pkg/database/machines.go @@ -70,8 +70,7 @@ func (c *Client) QueryMachineByID(machineID string) (*ent.Machine, error) { func (c *Client) ListMachines() ([]*ent.Machine, error) { machines, err := c.Ent.Machine.Query().All(c.CTX) if err != nil { - log.Warningf("ListMachines : %s", err) - return []*ent.Machine{}, errors.Wrap(UpdateFail, "setting machine status") + return []*ent.Machine{}, errors.Wrapf(QueryFail, "listing machines: %s", err) } return machines, nil } @@ -79,8 +78,7 @@ func (c *Client) ListMachines() ([]*ent.Machine, error) { func (c *Client) ValidateMachine(machineID string) error { _, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(c.CTX) if err != nil { - log.Warningf("ValidateMachine : %s", err) - return errors.Wrap(UpdateFail, "setting machine status") + return errors.Wrapf(UpdateFail, "validating machine: %s", err) } return nil } @@ -92,7 +90,7 @@ func (c *Client) QueryPendingMachine() ([]*ent.Machine, error) { machines, err = c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(c.CTX) if err != nil { log.Warningf("QueryPendingMachine : %s", err) - return []*ent.Machine{}, errors.Wrap(UpdateFail, "setting machine status") + return []*ent.Machine{}, errors.Wrapf(QueryFail, "querying pending machines: %s", err) } return machines, nil } diff --git a/scripts/test_wizard_upgrade.sh b/scripts/test_wizard_upgrade.sh index 4736cd55d..73d386420 100755 --- a/scripts/test_wizard_upgrade.sh +++ b/scripts/test_wizard_upgrade.sh @@ -11,7 +11,6 @@ FAIL_STR="${RED}FAIL${NC}" CURRENT_FOLDER=$(pwd) BOUNCER_VERSION="v0.0.6" -CROWDSEC_VERSION="xxx" RELEASE_FOLDER="" HUB_AVAILABLE_PARSERS="/etc/crowdsec/hub/parsers" @@ -40,6 +39,10 @@ MUST_FAIL=0 function init { + which git > /dev/null + if [ $? -ne 0 ]; then + echo "git is needed this test, exiting ..." + fi if [[ -z ${RELEASE_FOLDER} ]]; then cd .. @@ -324,7 +327,12 @@ while [[ $# -gt 0 ]] do key="${1}" case ${key} in - --release) + --version|-v) + CROWDSEC_VERSION="${2}" + shift #past argument + shift + ;; + --release|-r) RELEASE_FOLDER="${2}" shift #past argument shift diff --git a/wizard.sh b/wizard.sh index 210190fb0..e4cd61606 100755 --- a/wizard.sh +++ b/wizard.sh @@ -22,6 +22,8 @@ CROWDSEC_DB_PATH="${CROWDSEC_DATA_DIR}/crowdsec.db" CROWDSEC_PATH="/etc/crowdsec" CROWDSEC_CONFIG_PATH="${CROWDSEC_PATH}" CROWDSEC_LOG_FILE="/var/log/crowdsec.log" +LAPI_LOG_FILE="/var/log/crowdsec_api.log" + CROWDSEC_BIN="./cmd/crowdsec/crowdsec" CSCLI_BIN="./cmd/crowdsec-cli/cscli" @@ -477,6 +479,7 @@ uninstall_crowdsec() { find /etc/crowdsec -maxdepth 1 -mindepth 1 | grep -v "bouncer" | xargs rm -rf || echo "" rm -f ${CROWDSEC_LOG_FILE} || echo "" + rm -f ${LAPI_LOG_FILE} || echo "" rm -f ${CROWDSEC_DB_PATH} || echo "" rm -rf ${CROWDSEC_LIB_DIR} || echo "" rm -rf ${CROWDSEC_USR_DIR} || echo ""