Browse Source

Setup docker and stuffs

Brett Langdon 9 years ago
parent
commit
f580a2651c
No known key found for this signature in database GPG Key ID: A2ECAB73CE12147F
6 changed files with 47 additions and 12 deletions
  1. +2
    -0
      .gitignore
  2. +4
    -0
      Dockerfile
  3. +13
    -2
      Makefile
  4. +1
    -6
      cmd/pypihub/main.go
  5. +7
    -0
      docker-compose.yml
  6. +20
    -4
      server.go

+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
.env
build

+ 4
- 0
Dockerfile View File

@ -0,0 +1,4 @@
FROM alpine:3.4
RUN apk add --no-cache ca-certificates
COPY build/pypihub .
CMD ["./pypihub"]

+ 13
- 2
Makefile View File

@ -1,10 +1,21 @@
pypihub: ./*.go
pypihub: ./*.go ./cmd/pypihub/*.go
go build -o pypihub ./cmd/pypihub/
build/pypihub: ./*.go ./cmd/pypihub/*.go
mkdir -p build/
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' -o build/pypihub ./cmd/pypihub/
clean:
rm -f ./pypihub
rm -rf ./build
run:
go run ./cmd/pypihub/main.go
.PHONY: clean
docker_build: build/pypihub
docker build -t pypihub .
docker_up: docker_build
docker-compose up --build
.PHONY: clean docker_build run docker)up

+ 1
- 6
cmd/pypihub/main.go View File

@ -1,15 +1,10 @@
package main
import (
"fmt"
"github.com/brettlangdon/pypihub"
)
import "github.com/brettlangdon/pypihub"
func main() {
var config pypihub.Config
config = pypihub.ParseConfig()
fmt.Printf("%#v\r\n", config)
var server *pypihub.Server
server = pypihub.NewServer(config)


+ 7
- 0
docker-compose.yml View File

@ -0,0 +1,7 @@
version: '2'
services:
pypihub:
build: .
env_file: '.env'
ports:
- "8287:8287"

+ 20
- 4
server.go View File

@ -46,7 +46,7 @@ func (s *Server) startTimer() {
if s.timer != nil {
s.timer.Stop()
}
s.timer = time.AfterFunc(time.Duration(5*time.Minute), func() {
s.timer = time.AfterFunc(time.Duration(10*time.Minute), func() {
go s.refetchAssets()
})
}
@ -65,6 +65,22 @@ func (s *Server) listAssets(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "</body></html>")
}
func (s *Server) listRepoAssets(w http.ResponseWriter, r *http.Request) {
var parts = strings.SplitN(strings.Trim(r.URL.Path, "/"), "/", 2)
var owner = parts[0]
var repo = parts[1]
w.Header().Add("Content-Type", "text/html")
fmt.Fprintf(w, "<html><title>Links for %s</title><meta name=\"api-version\" content=\"2\" /><body>", repo)
fmt.Fprintf(w, "<h1>Links for %s</h1>", repo)
for _, a := range s.assets {
if a.Owner == owner && a.Repo == repo {
fmt.Fprintf(w, "<a href=\"%s\">%s</a> ", a.URL(), a.Name)
}
}
fmt.Fprintf(w, "</body></html>")
}
func (s *Server) listAllAssets(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
fmt.Fprintf(w, "<html><title>All asset links</title><meta name=\"api-version\" content=\"2\" /><body>")
@ -140,13 +156,13 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case 0:
s.listAllAssets(w, r)
case 1:
if parts[0] == "simple" {
s.listRepos(w, r)
} else if parts[0] == "favicon.ico" {
if parts[0] == "favicon.ico" {
s.serveFavicon(w, r)
} else {
s.listAssets(w, r)
}
case 2:
s.listRepoAssets(w, r)
default:
s.fetchAsset(w, r)
}


Loading…
Cancel
Save