Skip to content
Snippets Groups Projects
Commit a5eec436 authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

Merge branch 'feature/autodetect-ci-in-url' into 'master'

Autodetect "/ci" in URL

Fixes #1483 

/cc @ayufan

See merge request !289
parents 38dcdc08 ab608d68
Branches
Tags
No related merge requests found
......@@ -129,7 +129,7 @@ func (s *RegisterCommand) addRunner(runner *common.RunnerConfig) {
}
func (s *RegisterCommand) askRunner() {
s.URL = s.ask("url", "Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):")
s.URL = s.ask("url", "Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):")
if s.Token != "" {
log.Infoln("Token specified trying to verify runner...")
......
......@@ -293,7 +293,7 @@ a full URL and the runner's token, or the runner's name. First get the runner's
executing `gitlab-runner list`:
```bash
test-runner Executor=shell Token=t0k3n URL=http://gitlab.example.com/ci/
test-runner Executor=shell Token=t0k3n URL=http://gitlab.example.com
```
Then use this information to unregister it, using one of the following commands.
......@@ -305,7 +305,7 @@ make sure to have a backup of `config.toml` before executing it.
#### By URL and token:
```bash
gitlab-runner unregister --url http://gitlab.example.com/ci/ --token t0k3n
gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
```
#### By name:
......
......@@ -327,7 +327,7 @@ The `config.toml` below uses the `digitalocean` Docker Machine driver:
concurrent = 50 # All registered Runners can run up to 50 concurrent builds
[[runners]]
url = "https://gitlab.com/ci"
url = "https://gitlab.com"
token = "RUNNER_TOKEN" # Note this is different from the registration token used by `gitlab-runner register`
name = "autoscale-runner"
executor = "docker+machine" # This Runner is using the 'docker+machine' executor
......
......@@ -8,7 +8,7 @@ You can export it as a variable and run the command below as is:
```bash
gitlab-ci-multi-runner register \
--non-interactive \
--url "https://gitlab.com/ci" \
--url "https://gitlab.com" \
--registration-token "$REGISTRATION_TOKEN" \
--description "gitlab-ce-ruby-2.1" \
--executor "docker" \
......
......@@ -114,8 +114,8 @@ more in [Distributed runners caching][caching].
Example output:
```bash
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
https://gitlab.com/ci
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
Please enter the gitlab-ci description for this runner
......
......@@ -45,8 +45,8 @@ Register the runner:
```bash
docker exec -it gitlab-runner gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
https://gitlab.com/ci
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
Please enter the gitlab-ci description for this runner
......
......@@ -96,7 +96,7 @@ Register the runner:
```bash
sudo -u gitlab-runner -H /usr/local/bin/gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com):
Please enter the gitlab-ci token for this runner:
......
......@@ -33,8 +33,8 @@ Register the runner:
```bash
sudo gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
https://gitlab.com/ci
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
Please enter the gitlab-ci description for this runner
......
......@@ -20,8 +20,8 @@ Register the runner:
```bash
gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
https://gitlab.com/ci
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
Please enter the gitlab-ci description for this runner
......
......@@ -16,8 +16,8 @@ Register the runner:
cd C:\Multi-Runner
gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. http://gitlab-ci.org:3000/ )
https://ci.gitlab.com
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
Please enter the gitlab-ci description for this runner
......
......@@ -197,8 +197,16 @@ func (n *client) doJSON(uri, method string, statusCode int, request interface{},
return res.StatusCode, res.Status, n.getCAChain(res.TLS)
}
func fixCIURL(url string) string {
url = strings.TrimRight(url, "/")
if !strings.HasSuffix(url, "/ci") {
url += "/ci"
}
return url
}
func newClient(config common.RunnerCredentials) (c *client, err error) {
url, err := url.Parse(strings.TrimRight(config.URL, "/") + "/api/v1/")
url, err := url.Parse(fixCIURL(config.URL) + "/api/v1/")
if err != nil {
return
}
......
......@@ -23,10 +23,10 @@ func clientHandler(w http.ResponseWriter, r *http.Request) {
"Body:", string(body))
switch r.URL.Path {
case "/api/v1/test/ok":
case "/api/v1/test/auth":
case "/ci/api/v1/test/ok":
case "/ci/api/v1/test/auth":
w.WriteHeader(403)
case "/api/v1/test/json":
case "/ci/api/v1/test/json":
if r.Header.Get("Content-Type") != "application/json" {
w.WriteHeader(400)
} else if r.Header.Get("Accept") != "application/json" {
......@@ -159,3 +159,18 @@ func TestClientCertificateInPredefinedDirectory(t *testing.T) {
assert.Equal(t, 200, statusCode, statusText)
assert.NotEmpty(t, certificates)
}
func TestUrlFixing(t *testing.T) {
assert.Equal(t, "https://gitlab.example.com/ci", fixCIURL("https://gitlab.example.com/ci///"))
assert.Equal(t, "https://gitlab.example.com/ci", fixCIURL("https://gitlab.example.com/ci/"))
assert.Equal(t, "https://gitlab.example.com/ci", fixCIURL("https://gitlab.example.com/ci"))
assert.Equal(t, "https://gitlab.example.com/ci", fixCIURL("https://gitlab.example.com/"))
assert.Equal(t, "https://gitlab.example.com/ci", fixCIURL("https://gitlab.example.com///"))
assert.Equal(t, "https://gitlab.example.com/ci", fixCIURL("https://gitlab.example.com"))
assert.Equal(t, "https://example.com/gitlab/ci", fixCIURL("https://example.com/gitlab/ci/"))
assert.Equal(t, "https://example.com/gitlab/ci", fixCIURL("https://example.com/gitlab/ci///"))
assert.Equal(t, "https://example.com/gitlab/ci", fixCIURL("https://example.com/gitlab/ci"))
assert.Equal(t, "https://example.com/gitlab/ci", fixCIURL("https://example.com/gitlab/"))
assert.Equal(t, "https://example.com/gitlab/ci", fixCIURL("https://example.com/gitlab///"))
assert.Equal(t, "https://example.com/gitlab/ci", fixCIURL("https://example.com/gitlab"))
}
......@@ -45,7 +45,7 @@ func TestClients(t *testing.T) {
}
func testGetBuildHandler(w http.ResponseWriter, r *http.Request, t *testing.T) {
if r.URL.Path != "/api/v1/builds/register.json" {
if r.URL.Path != "/ci/api/v1/builds/register.json" {
w.WriteHeader(404)
return
}
......@@ -143,7 +143,7 @@ func TestGetBuild(t *testing.T) {
}
func testRegisterRunnerHandler(w http.ResponseWriter, r *http.Request, t *testing.T) {
if r.URL.Path != "/api/v1/runners/register.json" {
if r.URL.Path != "/ci/api/v1/runners/register.json" {
w.WriteHeader(404)
return
}
......@@ -237,7 +237,7 @@ func TestRegisterRunner(t *testing.T) {
func TestDeleteRunner(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/runners/delete" {
if r.URL.Path != "/ci/api/v1/runners/delete" {
w.WriteHeader(404)
return
}
......@@ -299,7 +299,7 @@ func TestDeleteRunner(t *testing.T) {
func TestVerifyRunner(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/builds/-1" {
if r.URL.Path != "/ci/api/v1/builds/-1" {
w.WriteHeader(404)
return
}
......@@ -361,7 +361,7 @@ func TestVerifyRunner(t *testing.T) {
func TestUpdateBuild(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/builds/10.json" {
if r.URL.Path != "/ci/api/v1/builds/10.json" {
w.WriteHeader(404)
return
}
......@@ -422,7 +422,7 @@ func TestUpdateBuild(t *testing.T) {
func TestArtifactsUpload(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/builds/10/artifacts" {
if r.URL.Path != "/ci/api/v1/builds/10/artifacts" {
w.WriteHeader(404)
return
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment