Skip to content

Commit

Permalink
Merge branch 'Duske-https-support'
Browse files Browse the repository at this point in the history
* Duske-https-support:
  Update TLS cert flag name
  [doc] update README for TLS flags
  [task] ignore ide/editor files
  [feat] add basic TLS support for HTTPS registry
  Create FUNDING.yml
  • Loading branch information
miguelmota committed Aug 9, 2019
2 parents 0a042d2 + 1d62603 commit 40ee23c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .circleci/run_build_locally.sh
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

curl --user "${CIRCLE_TOKEN}:" \
--request POST \
--form revision=0a042d26a7bdb34291c175d8603dbe8bfb21ad7b\
--form config=@config.yml \
--form notify=false \
https://circleci.com/api/v1.1/project/github/miguelmota/ipdr/tree/master
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
@@ -0,0 +1,2 @@
github: [miguelmota]
patreon: miguelmota
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -5,6 +5,10 @@
*.so
*.dylib

# IDEs/Editors
.idea
.vscode

# Test binary, built with `go test -c`
*.test

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -32,7 +32,7 @@ lint: $(GOMETALINTER)
## build: Builds project into an executable binary.
.PHONY: build
build:
go build -o bin/ipdr cmd/ipdr/ipdr.go
go build -o bin/ipdr cmd/ipdr/main.go

## release: Release a new version. Runs `goreleaser internally.
.PHONY: release
Expand Down
10 changes: 7 additions & 3 deletions README.md
Expand Up @@ -256,22 +256,26 @@ make test

## FAQ

- Q: How can I configure the local registry host or port that IPDR uses when pushing or pulling Docker images?
- Q: How do I configure the local registry host or port that IPDR uses when pushing or pulling Docker images?

- A: Use the `--docker-registry-host` flag, eg. `--docker-registry-host docker.for.mac.local:5000`

- Q: How can I configure the IPFS host that IPDR uses for pushing Docker images?
- Q: How do I configure the IPFS host that IPDR uses for pushing Docker images?

- A: Use the `--ipfs-host` flag, eg. `--ipfs-host 127.0.0.1:5001`

- Q: How can I configure the IPFS gateway that IPDR uses for pulling Docker images?
- Q: How do I configure the IPFS gateway that IPDR uses for pulling Docker images?

- A: Use the `--ipfs-gateway` flag, eg. `--ipfs-gateway https://ipfs.io`

- Q: How can I configure the port for the IPDR registry server?

- A: Use the `--port` flag, eg. `--port 5000`

- Q: How do I setup HTTPS/TLS on the IPDR registry server?

- A: Use the `--tlsKeyPath` and `--tlsCertPath` flag, eg. ` --tlsKeyPath path/server.key --tlsCertPath path/server.crt`

## Contributing

Pull requests are welcome!
Expand Down
10 changes: 8 additions & 2 deletions cmd/ipdr/main.go
Expand Up @@ -34,6 +34,8 @@ func main() {
var format string
var dockerRegistryHost string
var port uint
var tlsCertPath string
var tlsKeyPath string
var silent bool

rootCmd := &cobra.Command{
Expand Down Expand Up @@ -136,8 +138,10 @@ More info: https://github.com/miguelmota/ipdr`,
Long: "Start the IPFS-backed Docker registry server that proxies images stored on IPFS to Docker registry format",
RunE: func(cmd *cobra.Command, args []string) error {
srv := server.NewServer(&server.Config{
Port: port,
Debug: !silent,
Port: port,
Debug: !silent,
TLSKeyPath: tlsKeyPath,
TLSCrtPath: tlsCertPath,
})

return srv.Start()
Expand All @@ -146,6 +150,8 @@ More info: https://github.com/miguelmota/ipdr`,

serverCmd.Flags().BoolVarP(&silent, "silent", "s", false, "Silent flag suppresses logs")
serverCmd.Flags().UintVarP(&port, "port", "p", 5000, "The port for the Docker registry to listen on")
serverCmd.Flags().StringVarP(&tlsCertPath, "tlsCertPath", "", "", "The path to the .crt file for TLS")
serverCmd.Flags().StringVarP(&tlsKeyPath, "tlsKeyPath", "", "", "The path to the .key file for TLS")

convertCmd := &cobra.Command{
Use: "convert",
Expand Down
9 changes: 9 additions & 0 deletions server/server.go
Expand Up @@ -19,13 +19,17 @@ type Server struct {
listener net.Listener
host string
ipfsGateway string
tlsCertPath string
tlsKeyPath string
}

// Config is server config
type Config struct {
Debug bool
Port uint
IPFSGateway string
TLSCertPath string
TLSKeyPath string
}

// InfoResponse is response for manifest info response
Expand Down Expand Up @@ -59,6 +63,8 @@ func NewServer(config *Config) *Server {
host: fmt.Sprintf("0.0.0.0:%v", port),
debug: config.Debug,
ipfsGateway: ipfs.NormalizeGatewayURL(config.IPFSGateway),
tlsCertPath: config.TLSCertPath,
tlsKeyPath: config.TLSKeyPath,
}
}

Expand Down Expand Up @@ -171,6 +177,9 @@ func (s *Server) Start() error {
}

s.Debugf("[registry/server] listening on %s", s.listener.Addr())
if s.tlsKeyPath != "" && s.tlsCertPath != "" {
return http.ServeTLS(s.listener, nil, s.tlsCertPath, s.tlsKeyPath)
}

return http.Serve(s.listener, nil)
}
Expand Down

0 comments on commit 40ee23c

Please sign in to comment.