Commit d86407d
Eric Bower
·
2023-08-10 10:28:41 -0400 EDT
parent 6d8b897
dockerfile
4 files changed,
+66,
-12
+0,
-0
+21,
-0
| ... | ... | @@ -0,0 +1,21 @@ | |
| 1 | + | FROM golang:1.20 AS builder | |
| 2 | + | ||
| 3 | + | WORKDIR /app | |
| 4 | + | ||
| 5 | + | COPY go.mod go.sum ./ | |
| 6 | + | RUN go mod download && go mod verify | |
| 7 | + | ||
| 8 | + | COPY . /app | |
| 9 | + | ||
| 10 | + | RUN go build -v -o pgit main.go | |
| 11 | + | ||
| 12 | + | FROM debian:12 | |
| 13 | + | WORKDIR /app | |
| 14 | + | ||
| 15 | + | RUN apt-get update && apt-get install -y git | |
| 16 | + | # ignore git warning "detected dubious ownership in repository" | |
| 17 | + | RUN git config --global safe.directory '*' | |
| 18 | + | ||
| 19 | + | COPY --from=builder /app/pgit /usr/bin | |
| 20 | + | ||
| 21 | + | CMD ["pgit"] |
M
Makefile
+4,
-0
| ... | ... | @@ -6,6 +6,10 @@ build: | |
| 6 | 6 | go build -o pgit ./main.go | |
| 7 | 7 | .PHONY: build | |
| 8 | 8 | ||
| 9 | + | img: | |
| 10 | + | docker build -t neurosnap/pgit:latest . | |
| 11 | + | .PHONY: img | |
| 12 | + | ||
| 9 | 13 | static: build clean | |
| 10 | 14 | cp -R ./static ./public | |
| 11 | 15 | ./pgit |
M
main.go
+41,
-12
| ... | ... | @@ -7,6 +7,7 @@ import ( | |
| 7 | 7 | "flag" | |
| 8 | 8 | "fmt" | |
| 9 | 9 | "html/template" | |
| 10 | + | "io/ioutil" | |
| 10 | 11 | "math" | |
| 11 | 12 | "os" | |
| 12 | 13 | "path/filepath" |
| ... | ... | @@ -24,6 +25,12 @@ import ( | |
| 24 | 25 | "go.uber.org/zap" | |
| 25 | 26 | ) | |
| 26 | 27 | ||
| 28 | + | //go:embed static/main.css | |
| 29 | + | var mainCss []byte | |
| 30 | + | ||
| 31 | + | //go:embed static/syntax.css | |
| 32 | + | var syntaxCss []byte | |
| 33 | + | ||
| 27 | 34 | //go:embed html/*.tmpl | |
| 28 | 35 | var efs embed.FS | |
| 29 | 36 |
| ... | ... | @@ -317,13 +324,19 @@ func (c *Config) writeHtml(writeData *WriteData) { | |
| 317 | 324 | fp := filepath.Join(dir, writeData.Filename) | |
| 318 | 325 | c.Logger.Infof("writing (%s)", fp) | |
| 319 | 326 | ||
| 320 | - | w, err := os.OpenFile(fp, os.O_WRONLY|os.O_CREATE, 0755) | |
| 327 | + | w, err := os.OpenFile(fp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) | |
| 321 | 328 | bail(err) | |
| 322 | 329 | ||
| 323 | 330 | err = ts.Execute(w, writeData.Data) | |
| 324 | 331 | bail(err) | |
| 325 | 332 | } | |
| 326 | 333 | ||
| 334 | + | func (c *Config) copyStatic(dst string, data []byte) { | |
| 335 | + | c.Logger.Infof("writing (%s)", dst) | |
| 336 | + | err := ioutil.WriteFile(dst, data, 0755) | |
| 337 | + | bail(err) | |
| 338 | + | } | |
| 339 | + | ||
| 327 | 340 | func (c *Config) writeRootSummary(data *PageData, readme template.HTML) { | |
| 328 | 341 | c.writeHtml(&WriteData{ | |
| 329 | 342 | Filename: "index.html", |
| ... | ... | @@ -742,6 +755,8 @@ func main() { | |
| 742 | 755 | var rpath = flag.String("repo", ".", "path to git repo") | |
| 743 | 756 | var revsFlag = flag.String("revs", "HEAD", "list of revs to generate logs and tree (e.g. main,v1,c69f86f,HEAD") | |
| 744 | 757 | var themeFlag = flag.String("theme", "dracula", "theme to use for site") | |
| 758 | + | var labelFlag = flag.String("label", "", "pretty name for the subdir where we create the repo, default is last folder in --repo") | |
| 759 | + | var assetFlag = flag.Bool("assets", false, "copy static assets to --out") | |
| 745 | 760 | ||
| 746 | 761 | flag.Parse() | |
| 747 | 762 |
| ... | ... | @@ -750,15 +765,6 @@ func main() { | |
| 750 | 765 | repoPath, err := filepath.Abs(*rpath) | |
| 751 | 766 | bail(err) | |
| 752 | 767 | ||
| 753 | - | revs := strings.Split(*revsFlag, ",") | |
| 754 | - | if len(revs) == 1 && revs[0] == "" { | |
| 755 | - | revs = []string{} | |
| 756 | - | } | |
| 757 | - | ||
| 758 | - | if len(revs) == 0 { | |
| 759 | - | bail(fmt.Errorf("you must provide --revs")) | |
| 760 | - | } | |
| 761 | - | ||
| 762 | 768 | theme := styles.Get(*themeFlag) | |
| 763 | 769 | ||
| 764 | 770 | lg, err := zap.NewProduction() |
| ... | ... | @@ -768,10 +774,20 @@ func main() { | |
| 768 | 774 | ||
| 769 | 775 | logger := lg.Sugar() | |
| 770 | 776 | ||
| 777 | + | label := repoName(repoPath) | |
| 778 | + | if *labelFlag != "" { | |
| 779 | + | label = *labelFlag | |
| 780 | + | } | |
| 781 | + | ||
| 782 | + | revs := strings.Split(*revsFlag, ",") | |
| 783 | + | if len(revs) == 1 && revs[0] == "" { | |
| 784 | + | revs = []string{} | |
| 785 | + | } | |
| 786 | + | ||
| 771 | 787 | config := &Config{ | |
| 772 | 788 | Outdir: out, | |
| 773 | 789 | RepoPath: repoPath, | |
| 774 | - | RepoName: repoName(repoPath), | |
| 790 | + | RepoName: label, | |
| 775 | 791 | Cache: make(map[string]bool), | |
| 776 | 792 | Revs: revs, | |
| 777 | 793 | Theme: theme, |
| ... | ... | @@ -779,7 +795,20 @@ func main() { | |
| 779 | 795 | } | |
| 780 | 796 | config.Logger.Infof("%+v", config) | |
| 781 | 797 | ||
| 798 | + | writeAssets := *assetFlag | |
| 799 | + | if writeAssets { | |
| 800 | + | config.copyStatic(filepath.Join(config.Outdir, "main.css"), mainCss) | |
| 801 | + | config.copyStatic(filepath.Join(config.Outdir, "syntax.css"), syntaxCss) | |
| 802 | + | return | |
| 803 | + | } | |
| 804 | + | ||
| 805 | + | if len(revs) == 0 { | |
| 806 | + | bail(fmt.Errorf("you must provide --revs")) | |
| 807 | + | } | |
| 808 | + | ||
| 782 | 809 | config.writeRepo() | |
| 783 | - | url := filepath.Join("/", config.RepoName, "index.html") | |
| 810 | + | ||
| 811 | + | prefixPath := filepath.Join("/", config.RepoName) | |
| 812 | + | url := filepath.Join(prefixPath, "index.html") | |
| 784 | 813 | config.Logger.Info(url) | |
| 785 | 814 | } |