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 :: RepoScheme -> Text -> Maybe Repo -> Text -> Text
getPublicSubmissionUrl SelfHosted repoHost _ bareRepoName = repoHost ++ bareRepoName getPublicSubmissionUrl SelfHosted repoHost _ bareRepoName = repoHost ++ bareRepoName
getPublicSubmissionUrl Branches _ (Just repo) _ = repoUrl repo getPublicSubmissionUrl Branches _ (Just repo) _ = repoUrl repo
getPublicSubmissionUrl NoInternalGitServer _ (Just repo) _ = repoUrl repo
getReadOnlySubmissionUrl :: RepoScheme -> Repo -> Text -> Text getReadOnlySubmissionUrl :: RepoScheme -> Repo -> Text -> Text
getReadOnlySubmissionUrl SelfHosted _ bareRepoName = gitReadOnlyServer ++ bareRepoName getReadOnlySubmissionUrl SelfHosted _ bareRepoName = gitReadOnlyServer ++ bareRepoName
getReadOnlySubmissionUrl Branches repo _ = repoUrl repo getReadOnlySubmissionUrl Branches repo _ = repoUrl repo
getReadOnlySubmissionUrl NoInternalGitServer repo _ = repoUrl repo
browsableGitRepoBranch :: RepoScheme -> Repo -> Text -> Text -> Text browsableGitRepoBranch :: RepoScheme -> Repo -> Text -> Text -> Text
browsableGitRepoBranch SelfHosted _ bareRepoName branch = (browsableGitRepo bareRepoName) ++ "/" ++ branch ++ "/" browsableGitRepoBranch SelfHosted _ bareRepoName branch = (browsableGitRepo bareRepoName) ++ "/" ++ branch ++ "/"
browsableGitRepoBranch Branches repo _ branch = sshToHttps (repoUrl repo) branch browsableGitRepoBranch Branches repo _ branch = sshToHttps (repoUrl repo) branch
browsableGitRepoBranch NoInternalGitServer repo _ branch = sshToHttps (repoUrl repo) branch
sshToHttps :: Text -> Text -> Text sshToHttps :: Text -> Text -> Text
sshToHttps url branch = "https://" ++ (T.replace ".git" "" $ T.replace ":" "/" $ T.replace "ssh://" "" $ T.replace "git@" "" url) ++ "/tree/" ++ branch 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 Nothing -> defaultIdToBe
where defaultIdToBe = "YOURID" :: Text where defaultIdToBe = "YOURID" :: Text
externalRepoPlaceholder :: Text
externalRepoPlaceholder = "URL_TO_YOUR_REPO"
defaultRepo :: RepoScheme -> Text -> Challenge -> Repo -> Maybe (Entity User) -> Text defaultRepo :: RepoScheme -> Text -> Challenge -> Repo -> Maybe (Entity User) -> Text
defaultRepo SelfHosted repoHost challenge _ maybeUser = repoHost ++ (idToBeShown challenge maybeUser) ++ "/" ++ (challengeName challenge) defaultRepo SelfHosted repoHost challenge _ maybeUser = repoHost ++ (idToBeShown challenge maybeUser) ++ "/" ++ (challengeName challenge)
defaultRepo Branches _ _ repo _ = repoUrl repo defaultRepo Branches _ _ repo _ = repoUrl repo
defaultRepo NoInternalGitServer _ _ _ _ = externalRepoPlaceholder
defaultBranch :: IsString a => RepoScheme -> Maybe a defaultBranch :: IsString a => RepoScheme -> Maybe a
defaultBranch SelfHosted = Just "master" defaultBranch SelfHosted = Just "master"
defaultBranch Branches = Nothing defaultBranch Branches = Nothing
defaultBranch NoInternalGitServer = Nothing
challengeHowTo :: Challenge -> AppSettings -> Repo -> Text -> Bool -> Bool -> Maybe Text -> Maybe Text -> WidgetFor App () 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") challengeHowTo challenge settings repo shownId isIDSet isSSHUploaded mAltRepoScheme mToken = $(widgetFile "challenge-how-to")
where myBranch = "my-brilliant-branch" :: Text where myBranch = "my-brilliant-branch" :: Text
urlToYourRepo = case mAltRepoScheme of urlToYourRepo = case mAltRepoScheme of
Just altRepoScheme -> encodeSlash (altRepoScheme <> (challengeName challenge)) Just altRepoScheme -> encodeSlash (altRepoScheme <> (challengeName challenge))
Nothing -> "URL_TO_YOUR_REPO" Nothing -> externalRepoPlaceholder
postHealR :: ChallengeId -> Handler TypedContent postHealR :: ChallengeId -> Handler TypedContent
postHealR challengeId = runViewProgress $ doHeal challengeId 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 :: (ToMarkup a1, ToWidget App a2) => a2 -> a1 -> Challenge -> WidgetFor App ()
challengeSubmissionWidget formWidget formEnctype challenge = $(widgetFile "challenge-submission") challengeSubmissionWidget formWidget formEnctype challenge = $(widgetFile "challenge-submission")
externalRepoInfo settings = $(widgetFile "external-repo")
data ChallengeSubmissionData = ChallengeSubmissionData { data ChallengeSubmissionData = ChallengeSubmissionData {
challengeSubmissionDataDescription :: Maybe Text, challengeSubmissionDataDescription :: Maybe Text,
challengeSubmissionDataTags :: Maybe Text, challengeSubmissionDataTags :: Maybe Text,

View File

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

View File

@ -9,6 +9,14 @@ ip-from-header: "_env:IP_FROM_HEADER:false"
var-dir: "_env:VAR_DIR:." var-dir: "_env:VAR_DIR:."
contact-email: "_env:CONTACT_EMAIL:filipg@amu.edu.pl" contact-email: "_env:CONTACT_EMAIL:filipg@amu.edu.pl"
repo-host: "_env:REPO_HOST:ssh://gitolite@gonito.net/" 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" repo-scheme: "_env:REPO_SCHEME:selfhosted"
tag-permissions: "_env:TAG_PERMISSIONS:only-admin-can-add-new-tags" tag-permissions: "_env:TAG_PERMISSIONS:only-admin-can-add-new-tags"
auto-opening: "_env:AUTO_OPENING:false" auto-opening: "_env:AUTO_OPENING:false"

View File

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

View File

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

View File

@ -5,6 +5,11 @@ GONITO_ADMINPASS=Ahxuz5du
GONITO_LOCATION=test GONITO_LOCATION=test
GONITO_ARENA_VOLUME=/home/user/arena GONITO_ARENA_VOLUME=/home/user/arena
GONITO_APPROOT=https://localhost:443 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_LEADERBOARD_STYLE=by-tag
GONITO_AUTO_OPENING=false GONITO_AUTO_OPENING=false
NGINX_CERTIFICATE_DIR=/home/user/certs NGINX_CERTIFICATE_DIR=/home/user/certs

View File

@ -43,7 +43,7 @@ $case (appRepoScheme settings)
\ and \ and
$if not isSSHUploaded $if not isSSHUploaded
\ upload your SSH public key \ 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 $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!) <p>(Depending on your setup, you might need to create the repo at your git server first; remember to initiate it without any commits!)
@ -55,21 +55,40 @@ $case (appRepoScheme settings)
<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> <pre>
cd #{challengeName challenge} cd #{challengeName challenge}
git pull #{repoUrl repo} git pull #{repoUrl repo}
$if isNothing mAltRepoScheme
<h4>Using an external repository <h4>Using an external repository
$maybe serverPubKey <- (appServerSSHPublicKey settings) <p>Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo.
$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: ^{externalRepoInfo settings}
$else
<pre> $of NoInternalGitServer
#{serverPubKey} $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 $nothing
$if isNothing mAltRepoScheme <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>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>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 $of Branches
<p>Clone the repo: <p>Clone the repo:
@ -121,13 +140,15 @@ $case (appRepoScheme settings)
$of SelfHosted $of SelfHosted
<pre> <pre>
git push origin #{myBranch} 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. <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> <pre>
git push origin #{myBranch} 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. <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 $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).