Skip to content

Commit 356c9d7

Browse files
Vendor lfs-test-server (#1184)
Change: vendor-lfs-test-server
1 parent 0986160 commit 356c9d7

33 files changed

+3586
-16
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
!josh-ui/*.toml
1414
!josh-ui/public
1515
!josh-ui/src
16+
!lfs-test-server
1617
!run-josh.sh

Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ RUN pip3 install \
9292

9393
RUN apk add --no-cache go nodejs npm openssh-client patch
9494

95-
ARG GIT_LFS_VERSION=d4ced458b5cc9eaa712c1a2d299d77a4e3a0a7c5
96-
RUN GOPATH=/opt/lfs-test-server go install \
97-
github.com/git-lfs/lfs-test-server@${GIT_LFS_VERSION}
98-
ENV PATH=${PATH}:/opt/lfs-test-server/bin
95+
ARG GIT_LFS_TEST_SERVER_VERSION=d4ced458b5cc9eaa712c1a2d299d77a4e3a0a7c5
96+
97+
COPY lfs-test-server lfs-test-server
98+
RUN cd lfs-test-server && GOPATH=/opt/git-lfs go install
99+
100+
ENV PATH=${PATH}:/opt/git-lfs/bin
101+
102+
RUN git clone https://github.com/git-lfs/git-lfs.git /usr/src/git-lfs
103+
WORKDIR /usr/src/git-lfs
104+
RUN make
105+
RUN cp bin/git-lfs /opt/git-lfs/bin
99106

100107
WORKDIR /usr/src/josh
101108

@@ -113,6 +120,7 @@ ENV CARGO_TARGET_DIR=/opt/cache/cargo-target
113120
ENV CARGO_HOME=/opt/cache/cargo-cache
114121
ENV GOCACHE=/opt/cache/go-cache
115122
ENV GOPATH=/opt/cache/go-path
123+
ENV GOFLAGS=-buildvcs=false
116124
RUN npm config set cache /opt/cache/npm-cache --global
117125

118126
ARG USER_GID

hyper_cgi/src/bin/hyper-cgi-test-server.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ async fn call(
107107
req: hyper::Request<hyper::Body>,
108108
) -> hyper::Response<hyper::Body> {
109109
println!("call {:?}", req.uri().path());
110+
let mut req = req;
110111

111112
let path = req.uri().path();
112113

@@ -143,16 +144,20 @@ async fn call(
143144
}
144145

145146
if let Some(proxy) = &ARGS.get_one::<String>("proxy") {
146-
if let [proxy_path, proxy_target] = proxy.split(":").collect::<Vec<_>>().as_slice() {
147-
if path == *proxy_path {
148-
let client_ip = std::net::IpAddr::from_str("127.0.0.1").unwrap();
149-
return match hyper_reverse_proxy::call(client_ip, proxy_target, req).await {
150-
Ok(response) => response,
151-
Err(error) => hyper::Response::builder()
152-
.status(hyper::StatusCode::INTERNAL_SERVER_ERROR)
153-
.body(hyper::Body::from(format!("Proxy error: {:?}", error)))
154-
.unwrap(),
155-
};
147+
for proxy in proxy.split(",") {
148+
if let [proxy_path, proxy_target] = proxy.split("=").collect::<Vec<_>>().as_slice() {
149+
if let Some(ppath) = path.strip_prefix(proxy_path) {
150+
let client_ip = std::net::IpAddr::from_str("127.0.0.1").unwrap();
151+
*req.uri_mut() = ppath.parse().unwrap();
152+
println!("proxy {:?}", req.uri().path());
153+
return match hyper_reverse_proxy::call(client_ip, proxy_target, req).await {
154+
Ok(response) => response,
155+
Err(error) => hyper::Response::builder()
156+
.status(hyper::StatusCode::INTERNAL_SERVER_ERROR)
157+
.body(hyper::Body::from(format!("Proxy error: {:?}", error)))
158+
.unwrap(),
159+
};
160+
}
156161
}
157162
}
158163
}

lfs-test-server/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git
2+
lfs-content
3+
lfs.db
4+
Procfile
5+
Readme.md
6+
TODO

lfs-test-server/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
lfs.db
3+
lfs-test-server
4+
lfs-test-server-out.*
5+
lfs-test-server-release.*

lfs-test-server/CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Contributing to LFS Test Server
2+
3+
Hi there! We're thrilled that you'd like to contribute to this project. Your
4+
help is essential for keeping it great.
5+
6+
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
7+
8+
## Submitting a pull request
9+
10+
0. [Fork][] and clone the repository
11+
0. Configure and install the dependencies: `go build`
12+
0. Make sure the tests pass on your machine: `go test`
13+
0. Create a new branch: `git checkout -b my-branch-name`
14+
0. Make your change, add tests, and make sure the tests still pass
15+
0. Push to your fork and [submit a pull request][pr]
16+
0. Pat your self on the back and wait for your pull request to be reviewed.
17+
18+
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
19+
20+
- Follow the [style guide][style] where possible.
21+
- Write tests.
22+
- Update documentation as necessary.
23+
- Keep your change as focused as possible. If there are multiple changes you
24+
would like to make that are not dependent upon each other, consider submitting
25+
them as separate pull requests.
26+
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
27+
28+
## Resources
29+
30+
- [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/)
31+
- [Using Pull Requests](https://help.github.com/articles/using-pull-requests/)
32+
- [GitHub Help](https://help.github.com)
33+
34+
[![GoDoc](https://godoc.org/github.com/github/lfs-test-server?status.svg)](https://godoc.org/github.com/github/lfs-test-server)
35+
36+
[fork]: https://github.com/github/lfs-test-server/fork
37+
[pr]: https://github.com/github/lfs-test-server/compare
38+
[style]: https://github.com/golang/go/wiki/CodeReviewComments

lfs-test-server/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.14.7
2+
MAINTAINER GitHub, Inc.
3+
4+
WORKDIR /go/src/github.com/git-lfs/lfs-test-server
5+
6+
COPY . .
7+
8+
RUN go build
9+
10+
EXPOSE 8080
11+
12+
CMD /go/src/github.com/git-lfs/lfs-test-server/lfs-test-server

lfs-test-server/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) GitHub, Inc. and LFS Test Server contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

lfs-test-server/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
LFS Test Server
2+
======
3+
4+
[rel]: https://github.com/github/lfs-test-server/releases
5+
[lfs]: https://github.com/github/git-lfs
6+
[api]: https://github.com/github/git-lfs/tree/master/docs/api#readme
7+
8+
LFS Test Server is an example server that implements the [Git LFS API][api]. It
9+
is intended to be used for testing the [Git LFS][lfs] client and is not in a
10+
production ready state.
11+
12+
LFS Test Server is written in Go, with pre-compiled binaries available for Mac,
13+
Windows, Linux, and FreeBSD.
14+
15+
See [CONTRIBUTING.md](CONTRIBUTING.md) for info on working on LFS Test Server and
16+
sending patches.
17+
18+
## Installing
19+
20+
Use the Go installer:
21+
22+
```
23+
$ go install github.com/git-lfs/lfs-test-server
24+
```
25+
26+
27+
## Building
28+
29+
To build from source, use the Go tools:
30+
31+
```
32+
$ go get github.com/git-lfs/lfs-test-server
33+
```
34+
35+
36+
## Running
37+
38+
Running the binary will start an LFS server on `localhost:8080` by default.
39+
There are few things that can be configured via environment variables:
40+
41+
LFS_LISTEN # The address:port the server listens on, default: "tcp://:8080"
42+
LFS_HOST # The host used when the server generates URLs, default: "localhost:8080"
43+
LFS_METADB # The database file the server uses to store meta information, default: "lfs.db"
44+
LFS_CONTENTPATH # The path where LFS files are store, default: "lfs-content"
45+
LFS_ADMINUSER # An administrator username, default: not set
46+
LFS_ADMINPASS # An administrator password, default: not set
47+
LFS_CERT # Certificate file for tls
48+
LFS_KEY # tls key
49+
LFS_SCHEME # set to 'https' to override default http
50+
LFS_USETUS # set to 'true' to enable tusd (tus.io) resumable upload server; tusd must be on PATH, installed separately
51+
LFS_TUSHOST # The host used to start the tusd upload server, default "localhost:1080"
52+
53+
If the `LFS_ADMINUSER` and `LFS_ADMINPASS` variables are set, a
54+
rudimentary admin interface can be accessed via
55+
`http://$LFS_HOST/mgmt`. Here you can add and remove users, which must
56+
be done before you can use the server with the client. If either of
57+
these variables are not set (which is the default), the administrative
58+
interface is disabled.
59+
60+
To use the LFS test server with the Git LFS client, configure it in the repository's `.lfsconfig`:
61+
62+
63+
```
64+
[lfs]
65+
url = "http://localhost:8080/"
66+
67+
```
68+
69+
HTTPS:
70+
71+
NOTE: If using https with a self signed cert also disable cert checking in the client repo.
72+
73+
```
74+
[lfs]
75+
url = "https://localhost:8080/"
76+
77+
[http]
78+
sslverify = false
79+
80+
```
81+
82+
83+
An example usage:
84+
85+
86+
Generate a key pair
87+
```
88+
openssl req -x509 -sha256 -nodes -days 2100 -newkey rsa:2048 -keyout mine.key -out mine.crt
89+
```
90+
91+
Make yourself a run script
92+
93+
```
94+
#!/bin/bash
95+
96+
set -eu
97+
set -o pipefail
98+
99+
100+
LFS_LISTEN="tcp://:9999"
101+
LFS_HOST="127.0.0.1:9999"
102+
LFS_CONTENTPATH="content"
103+
LFS_ADMINUSER="<cool admin user name>"
104+
LFS_ADMINPASS="<better admin password>"
105+
LFS_CERT="mine.crt"
106+
LFS_KEY="mine.key"
107+
LFS_SCHEME="https"
108+
109+
export LFS_LISTEN LFS_HOST LFS_CONTENTPATH LFS_ADMINUSER LFS_ADMINPASS LFS_CERT LFS_KEY LFS_SCHEME
110+
111+
./lfs-test-server
112+
113+
```
114+
115+
Build the server
116+
117+
```
118+
go build
119+
120+
```
121+
122+
Run
123+
124+
```
125+
bash run.sh
126+
127+
```
128+
129+
Check the managment page
130+
131+
browser: https://localhost:9999/mgmt
132+
133+

lfs-test-server/config.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"reflect"
7+
"strings"
8+
)
9+
10+
// Configuration holds application configuration. Values will be pulled from
11+
// environment variables, prefixed by keyPrefix. Default values can be added
12+
// via tags.
13+
type Configuration struct {
14+
Listen string `config:"tcp://:8080"`
15+
Host string `config:"localhost:8080"`
16+
ExtOrigin string `config:""` // consider lfs-test-server may behind a reverse proxy
17+
MetaDB string `config:"lfs.db"`
18+
ContentPath string `config:"lfs-content"`
19+
AdminUser string `config:""`
20+
AdminPass string `config:""`
21+
Cert string `config:""`
22+
Key string `config:""`
23+
Scheme string `config:"http"`
24+
Public string `config:"public"`
25+
UseTus string `config:"false"`
26+
TusHost string `config:"localhost:1080"`
27+
}
28+
29+
func (c *Configuration) IsHTTPS() bool {
30+
return strings.Contains(Config.Scheme, "https")
31+
}
32+
33+
func (c *Configuration) IsPublic() bool {
34+
switch Config.Public {
35+
case "1", "true", "TRUE":
36+
return true
37+
}
38+
return false
39+
}
40+
41+
func (c *Configuration) IsUsingTus() bool {
42+
switch Config.UseTus {
43+
case "1", "true", "TRUE":
44+
return true
45+
}
46+
return false
47+
}
48+
49+
// Config is the global app configuration
50+
var Config = &Configuration{}
51+
52+
const keyPrefix = "LFS"
53+
54+
func init() {
55+
te := reflect.TypeOf(Config).Elem()
56+
ve := reflect.ValueOf(Config).Elem()
57+
58+
for i := 0; i < te.NumField(); i++ {
59+
sf := te.Field(i)
60+
name := sf.Name
61+
field := ve.FieldByName(name)
62+
63+
envVar := strings.ToUpper(fmt.Sprintf("%s_%s", keyPrefix, name))
64+
env := os.Getenv(envVar)
65+
tag := sf.Tag.Get("config")
66+
67+
if env == "" && tag != "" {
68+
env = tag
69+
}
70+
71+
field.SetString(env)
72+
}
73+
74+
if port := os.Getenv("PORT"); port != "" {
75+
// If $PORT is set, override LFS_LISTEN. This is useful for deploying to Heroku.
76+
Config.Listen = "tcp://:" + port
77+
}
78+
79+
if Config.ExtOrigin == "" {
80+
Config.ExtOrigin = fmt.Sprintf("%s://%s", Config.Scheme, Config.Host)
81+
}
82+
}

0 commit comments

Comments
 (0)