Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
7f1098a1
Commit
7f1098a1
authored
Sep 28, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specify a richer scheme to run the migration with
parent
c37020bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
28 deletions
+60
-28
config.yml.example
config.yml.example
+6
-2
go/cmd/gitlab-shell/main.go
go/cmd/gitlab-shell/main.go
+28
-15
go/internal/config/config.go
go/internal/config/config.go
+9
-4
go/internal/config/config_test.go
go/internal/config/config_test.go
+17
-7
No files found.
config.yml.example
View file @
7f1098a1
...
...
@@ -50,5 +50,9 @@ log_level: INFO
# incurs an extra API call on every gitlab-shell command.
audit_usernames: false
# Feature flag: go or ruby
experimental: false
# Migration to Go: anything listed here has two implementations. Use these flags
# to try the new implementations out, or to revert to the old behaviour if there
# problems arise.
migration:
enabled: false
features: []
go/cmd/gitlab-shell/main.go
View file @
7f1098a1
...
...
@@ -9,28 +9,41 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
func
experiment
(
)
{
fmt
.
Println
(
"Experiment! nothing works!"
)
os
.
Exit
(
1
)
func
migrate
(
_cfg
*
config
.
Config
,
_args
[]
string
)
(
int
,
bool
)
{
// TODO: decide whether to handle the request in Go or not
return
0
,
false
}
func
main
()
{
// rubyExec will never return. It either replaces the current process with a
// Ruby interpreter, or outputs an error and kills the process.
func
execRuby
()
{
root
:=
filepath
.
Dir
(
os
.
Args
[
0
])
ruby
:=
filepath
.
Join
(
root
,
"gitlab-shell-ruby"
)
rubyCmd
:=
filepath
.
Join
(
root
,
"gitlab-shell-ruby"
)
rubyArgs
:=
os
.
Args
[
1
:
]
rubyEnv
:=
os
.
Environ
()
execErr
:=
syscall
.
Exec
(
rubyCmd
,
rubyArgs
,
rubyEnv
)
if
execErr
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Failed to exec(%q): %v
\n
"
,
rubyCmd
,
execErr
)
os
.
Exit
(
1
)
}
}
func
main
()
{
// Fall back to Ruby in case of problems reading the config, but issue a
// warning as this isn't something we can sustain indefinitely
config
,
err
:=
config
.
New
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
fmt
.
Fprintln
(
os
.
Stderr
,
"Failed to read config, falling back to gitlab-shell-ruby"
)
execRuby
(
)
}
if
config
.
Experimental
{
experiment
()
}
else
{
execErr
:=
syscall
.
Exec
(
ruby
,
os
.
Args
,
os
.
Environ
())
if
execErr
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Failed to exec(%q): %v
\n
"
,
ruby
,
execErr
)
os
.
Exit
(
1
)
}
// Try to handle the command with the Go implementation
if
exitCode
,
done
:=
migrate
(
config
,
os
.
Args
[
1
:
]);
done
{
os
.
Exit
(
exitCode
)
}
// Since a migration has not handled the command, fall back to Ruby to do so
execRuby
()
}
go/internal/config/config.go
View file @
7f1098a1
...
...
@@ -13,11 +13,16 @@ const (
logFile
=
"gitlab-shell.log"
)
type
MigrationConfig
struct
{
Enabled
bool
`yaml:"enabled"`
Features
[]
string
`yaml:"features"`
}
type
Config
struct
{
RootDir
string
LogFile
string
`yaml:"log_file"`
LogFormat
string
`yaml:"log_format"`
Experimental
bool
`yaml:"experimental
"`
RootDir
string
LogFile
string
`yaml:"log_file"`
LogFormat
string
`yaml:"log_format"`
Migration
MigrationConfig
`yaml:"migration
"`
}
func
New
()
(
*
Config
,
error
)
{
...
...
go/internal/config/config_test.go
View file @
7f1098a1
...
...
@@ -2,22 +2,28 @@ package config
import
(
"fmt"
"strings"
"testing"
)
func
TestConfigLogFile
(
t
*
testing
.
T
)
{
testRoot
:=
"/foo/bar"
testCases
:=
[]
struct
{
yaml
string
path
string
format
string
experimental
bool
yaml
string
path
string
format
string
migration
MigrationConfig
}{
{
path
:
"/foo/bar/gitlab-shell.log"
,
format
:
"text"
},
{
yaml
:
"log_file: my-log.log"
,
path
:
"/foo/bar/my-log.log"
,
format
:
"text"
},
{
yaml
:
"log_file: /qux/my-log.log"
,
path
:
"/qux/my-log.log"
,
format
:
"text"
},
{
yaml
:
"log_format: json"
,
path
:
"/foo/bar/gitlab-shell.log"
,
format
:
"json"
},
{
yaml
:
"experimental: true"
,
path
:
"/foo/bar/gitlab-shell.log"
,
format
:
"text"
,
experimental
:
true
},
{
yaml
:
"migration:
\n
enabled: true
\n
features:
\n
- foo
\n
- bar"
,
path
:
"/foo/bar/gitlab-shell.log"
,
format
:
"text"
,
migration
:
MigrationConfig
{
Enabled
:
true
,
Features
:
[]
string
{
"foo"
,
"bar"
}},
},
}
for
_
,
tc
:=
range
testCases
{
...
...
@@ -27,8 +33,12 @@ func TestConfigLogFile(t *testing.T) {
t
.
Fatal
(
err
)
}
if
cfg
.
Experimental
!=
tc
.
experimental
{
t
.
Fatalf
(
"expected %v, got %v"
,
tc
.
experimental
,
cfg
.
Experimental
)
if
cfg
.
Migration
.
Enabled
!=
tc
.
migration
.
Enabled
{
t
.
Fatalf
(
"migration.enabled: expected %v, got %v"
,
tc
.
migration
.
Enabled
,
cfg
.
Migration
.
Enabled
)
}
if
strings
.
Join
(
cfg
.
Migration
.
Features
,
":"
)
!=
strings
.
Join
(
tc
.
migration
.
Features
,
":"
)
{
t
.
Fatalf
(
"migration.features: expected %#v, got %#v"
,
tc
.
migration
.
Features
,
cfg
.
Migration
.
Features
)
}
if
cfg
.
LogFile
!=
tc
.
path
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment