Introduce NoInternalGitServer scheme

Also clean-up how to
This commit is contained in:
Filip Gralinski 2021-08-21 15:02:08 +02:00
parent 636f8ab627
commit 9677c32cd5
9 changed files with 72 additions and 17 deletions

View File

@ -78,14 +78,17 @@ getPublicSubmissionBranch = T.pack . (printf "submission-%05d") . fromSqlKey
getPublicSubmissionUrl :: RepoScheme -> Text -> Maybe Repo -> Text -> Text
getPublicSubmissionUrl SelfHosted repoHost _ bareRepoName = repoHost ++ bareRepoName
getPublicSubmissionUrl Branches _ (Just repo) _ = repoUrl repo
getPublicSubmissionUrl NoInternalGitServer _ (Just repo) _ = repoUrl repo
getReadOnlySubmissionUrl :: RepoScheme -> Repo -> Text -> Text
getReadOnlySubmissionUrl SelfHosted _ bareRepoName = gitReadOnlyServer ++ bareRepoName
getReadOnlySubmissionUrl Branches repo _ = repoUrl repo
getReadOnlySubmissionUrl NoInternalGitServer repo _ = repoUrl repo
browsableGitRepoBranch :: RepoScheme -> Repo -> Text -> Text -> Text
browsableGitRepoBranch SelfHosted _ bareRepoName branch = (browsableGitRepo bareRepoName) ++ "/" ++ branch ++ "/"
browsableGitRepoBranch Branches repo _ branch = sshToHttps (repoUrl repo) branch
browsableGitRepoBranch NoInternalGitServer repo _ branch = sshToHttps (repoUrl repo) branch
sshToHttps :: Text -> Text -> Text
sshToHttps url branch = "https://" ++ (T.replace ".git" "" $ T.replace ":" "/" $ T.replace "ssh://" "" $ T.replace "git@" "" url) ++ "/tree/" ++ branch

View File

@ -526,20 +526,25 @@ idToBeShown _ maybeUser =
Nothing -> defaultIdToBe
where defaultIdToBe = "YOURID" :: Text
externalRepoPlaceholder :: Text
externalRepoPlaceholder = "URL_TO_YOUR_REPO"
defaultRepo :: RepoScheme -> Text -> Challenge -> Repo -> Maybe (Entity User) -> Text
defaultRepo SelfHosted repoHost challenge _ maybeUser = repoHost ++ (idToBeShown challenge maybeUser) ++ "/" ++ (challengeName challenge)
defaultRepo Branches _ _ repo _ = repoUrl repo
defaultRepo NoInternalGitServer _ _ _ _ = externalRepoPlaceholder
defaultBranch :: IsString a => RepoScheme -> Maybe a
defaultBranch SelfHosted = Just "master"
defaultBranch Branches = Nothing
defaultBranch NoInternalGitServer = Nothing
challengeHowTo :: Challenge -> AppSettings -> Repo -> Text -> Bool -> Bool -> Maybe Text -> Maybe Text -> WidgetFor App ()
challengeHowTo challenge settings repo shownId isIDSet isSSHUploaded mAltRepoScheme mToken = $(widgetFile "challenge-how-to")
where myBranch = "my-brilliant-branch" :: Text
urlToYourRepo = case mAltRepoScheme of
Just altRepoScheme -> encodeSlash (altRepoScheme <> (challengeName challenge))
Nothing -> "URL_TO_YOUR_REPO"
Nothing -> externalRepoPlaceholder
postHealR :: ChallengeId -> Handler TypedContent
postHealR challengeId = runViewProgress $ doHeal challengeId
@ -1086,6 +1091,8 @@ checkRepoAvailibility challengeId repoId chan = do
challengeSubmissionWidget :: (ToMarkup a1, ToWidget App a2) => a2 -> a1 -> Challenge -> WidgetFor App ()
challengeSubmissionWidget formWidget formEnctype challenge = $(widgetFile "challenge-submission")
externalRepoInfo settings = $(widgetFile "external-repo")
data ChallengeSubmissionData = ChallengeSubmissionData {
challengeSubmissionDataDescription :: Maybe Text,
challengeSubmissionDataTags :: Maybe Text,

View File

@ -21,11 +21,12 @@ import Web.Announcements (AnnouncementHook, toAnnouncementHook)
import qualified Jose.Jwk as JWK
data RepoScheme = SelfHosted | Branches
data RepoScheme = SelfHosted | Branches | NoInternalGitServer
deriving (Eq, Show)
toRepoScheme :: Text -> RepoScheme
toRepoScheme "branches" = Branches
toRepoScheme "no-internal-git-server" = NoInternalGitServer
toRepoScheme _ = SelfHosted
data TagPermissions = OnlyAdminCanAddNewTags | EverybodyCanAddNewTags

View File

@ -9,6 +9,14 @@ ip-from-header: "_env:IP_FROM_HEADER:false"
var-dir: "_env:VAR_DIR:."
contact-email: "_env:CONTACT_EMAIL:filipg@amu.edu.pl"
repo-host: "_env:REPO_HOST:ssh://gitolite@gonito.net/"
# How the git repos are handled
# - selfhosted - there is a git server (e.g. Gitolite) on the same
# host as the Gonito instance
# - branches - solutions are submitted to the same repo as the task
# (this is good for an internal repo within a company)
# - no-internal-git-server - there is no git server assumed, though
# REPO_HOST can be still specified
# for publishing opened solutions
repo-scheme: "_env:REPO_SCHEME:selfhosted"
tag-permissions: "_env:TAG_PERMISSIONS:only-admin-can-add-new-tags"
auto-opening: "_env:AUTO_OPENING:false"

View File

@ -12,6 +12,8 @@ services:
- ADMINPASS=$GONITO_ADMINPASS
- LOCATION=$GONITO_LOCATION
- APPROOT=$GONITO_APPROOT
- REPO_HOST=$GONITO_REPO_HOST
- REPO_SCHEME=$GONITO_REPO_SCHEME
- LEADERBOARD_STYLE=${GONITO_LEADERBOARD_STYLE:-by-tag}
- AUTO_OPENING=${GONITO_AUTO_OPENING:-false}
- IS_PUBLIC=${GONITO_IS_PUBLIC:-true}

View File

@ -22,6 +22,8 @@ services:
- ADMINPASS=$GONITO_ADMINPASS
- LOCATION=$GONITO_LOCATION
- APPROOT=$GONITO_APPROOT
- REPO_HOST=$GONITO_REPO_HOST
- REPO_SCHEME=$GONITO_REPO_SCHEME
- LEADERBOARD_STYLE=${GONITO_LEADERBOARD_STYLE:-by-tag}
- AUTO_OPENING=${GONITO_AUTO_OPENING:-false}
- IS_PUBLIC=${GONITO_IS_PUBLIC:-true}

View File

@ -5,6 +5,11 @@ GONITO_ADMINPASS=Ahxuz5du
GONITO_LOCATION=test
GONITO_ARENA_VOLUME=/home/user/arena
GONITO_APPROOT=https://localhost:443
# URL scheme for a git server associated with the instance
GONITO_REPO_HOST=ssh://gitolite@gonito.net/
# How git repos are handled, 'selfhosted', 'branches' or
# 'no-internal-git-server'
GONITO_REPO_SCHEME=branches
GONITO_LEADERBOARD_STYLE=by-tag
GONITO_AUTO_OPENING=false
NGINX_CERTIFICATE_DIR=/home/user/certs

View File

@ -43,7 +43,7 @@ $case (appRepoScheme settings)
\ and
$if not isSSHUploaded
\ upload your SSH public key
\ (see <a href="@{YourAccountR}">your account</a>) if you want to have a repo hosted on Gonito.net, then:
\ (see <a href="@{YourAccountR}">your account</a>) if you want to have a repo hosted on this instance, then:
$maybe altRepoScheme <- mAltRepoScheme
<p>(Depending on your setup, you might need to create the repo at your git server first; remember to initiate it without any commits!)
@ -53,23 +53,42 @@ $case (appRepoScheme settings)
<pre>
git clone --single-branch #{appRepoHost settings}#{shownId}/#{challengeName challenge}
<p>(Warning about empty repository is expected, don't worry about it.)
<p>(Warning about empty repository is expected, don't worry about it.)
$maybe altRepoScheme <- mAltRepoScheme
^{externalRepoInfo settings}
<pre>
cd #{challengeName challenge}
git pull #{repoUrl repo}
<h4>Using an external repository
$if isNothing mAltRepoScheme
<h4>Using an external repository
$maybe serverPubKey <- (appServerSSHPublicKey settings)
$if isNothing mAltRepoScheme
<p>Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo, make sure Gonito.net has access to your repo, either by making it public or giving read access to the SSH public key:
$else
<pre>
#{serverPubKey}
$nothing
$if isNothing mAltRepoScheme
<p>Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo, make sure Gonito.net has access to your repo.
<p>Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo.
^{externalRepoInfo settings}
$of NoInternalGitServer
$maybe altRepoScheme <- mAltRepoScheme
<p>Make sure the repo #{altRepoScheme}#{challengeName challenge} exists. Note that it should be created as empty (do <em>not</em> create any default `README.md` file).
$nothing
<p>You need to have a repo at some external Git server (e.g. GitHub, GitLab or your own git server) for storing your solution.
<p>Create a repo at your server. It should be created as empty (do **not** create any default `README.md` file).
<p>The repo should contain <tt>#{challengeName challenge}</tt> as part of its URL (preferably it should be the last part of the URL)
^{externalRepoInfo settings}
<pre>
$maybe altRepoScheme <- mAltRepoScheme
git clone #{altRepoScheme}#{challengeName challenge}
$nothing
git clone URL_TO_YOUR_REPO
<pre>
cd #{challengeName challenge}
git pull #{repoUrl repo}
$of Branches
<p>Clone the repo:
@ -121,13 +140,15 @@ $case (appRepoScheme settings)
$of SelfHosted
<pre>
git push origin #{myBranch}
<h3>Repos hosted on Gonito.net
<h2>Submit your solution to Gonito
<h3>Repos hosted on this instance
<p>If you use a repo hosted here, a submission and evaluation is triggered automatically. You'll see the evaluation results in your console while pushing.
$of Branches
$of _
<pre>
git push origin #{myBranch}
<h2>Submit your solution to Gonito
<h3>External repos
<h3>Integration with external repos
<p>If you use an external repo (e.g. at your own of Gitolite or at GitLab/GitHub), you can configure a webhook.
$maybe token <- mToken

View File

@ -0,0 +1,6 @@
$maybe serverPubKey <- (appServerSSHPublicKey settings)
<p>Make sure Gonito.net has access to your repo, either by making it public or giving read access to the SSH public key:
<pre>
#{serverPubKey}
$nothing
<p>Make sure Gonito.net has access to your repo (e.g. by making it public).