TruCol / Self-host-GitLab-CI-for-GitHub

Installs your own GitLab CI and runs it on all your GitHub repos, in a single command.
GNU Affero General Public License v3.0
4 stars 3 forks source link

visudo contains method not working properly. #74

Open a-t-0 opened 2 years ago

a-t-0 commented 2 years ago

Output:

Registering runner... succeeded                     runner=Q_1HebnF
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 
gitlab-runner ALL=(ALL) NOPASSWD: ALL
ERROR, did not find the visudo user thatwas added
Runtime platform                                    arch=amd64 os=linux pid=17862 revision=98daeee0 version=14.7.0
Runtime platform                                    arch=amd64 os=linux pid=17876 revision=98daeee0 version=14.7.0
The gitlab runner is already running
COMPLETED RUNNER INSTALLATION.

Related code: https://github.com/Simple-Setup/Self-host-GitLab-Server-and-Runner-CI/blob/8fd9eb27ee794e4e61cfe376a0238cd8c926c245/src/install_and_boot_gitlab_runner.sh

    visudo_line="$RUNNER_USERNAME ALL=(ALL) NOPASSWD: ALL"
    filepath="/etc/sudoers"
    added_runner_to_visudo=$(visudo_contains "$visudo_line" "$filepath")
    if [  "$added_runner_to_visudo" == "NOTFOUND" ]; then
        echo "$RUNNER_USERNAME ALL=(ALL) NOPASSWD: ALL" | sudo EDITOR='tee -a' visudo
        added_runner_to_visudo=$(visudo_contains "$visudo_line" "$filepath")
        if [  "$added_runner_to_visudo" == "NOTFOUND" ]; then
            # TODO: raise exception
            echo "ERROR, did not find the visudo user thatwas added"
            #exit 1
        fi
    fi

Also has test:


@test "Test file contains string with variable username that does exist." {
    # TODO: Move this test to a function where the installation is completed.
    username="$GITLAB_SERVER_ACCOUNT_GLOBAL"
    line="$username ALL=(ALL:ALL) ALL"
    actual_result=$(visudo_contains "$line" )
    EXPECTED_OUTPUT="FOUND"

    assert_equal "$actual_result" "$EXPECTED_OUTPUT"
}

in test/no_server_required/preserves_server/test_parsing.bats.