From 822c883b7116de3e3743b795b46d67d749e9587b Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Tue, 16 Nov 2021 14:22:55 +0800 Subject: [PATCH] Automatically update README --- .github/workflows/build.yml | 4 +-- .gitignore | 1 - README.md | 11 ++++----- go.mod | 6 ++--- go.sum | 16 ++++++++++++ update.go | 49 +++++++++++++++++++++++++++++++++++-- 6 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 go.sum diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee490e9..d692078 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,8 +32,8 @@ jobs: - name: Regenerate Dockerfiles run: | - go run update.go -dockerfiles - + go run update.go -dockerfiles -readme + - name: Commit and push changes id: commit-dockerfiles run: | diff --git a/.gitignore b/.gitignore index 34ef21a..3e3add7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ caddy.go -go.sum diff --git a/README.md b/README.md index 639f6aa..b2bd14d 100755 --- a/README.md +++ b/README.md @@ -1,20 +1,19 @@ -# [caddy](https://hub.docker.com/r/productionwentdown/caddy/) [![](https://images.microbadger.com/badges/version/productionwentdown/caddy.svg)](https://microbadger.com/images/productionwentdown/caddy "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/productionwentdown/caddy.svg)](https://microbadger.com/images/productionwentdown/caddy "Get your own image badge on microbadger.com") +# [caddy](https://hub.docker.com/r/productionwentdown/caddy/) ![Docker Pulls](https://img.shields.io/docker/pulls/productionwentdown/caddy) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/productionwentdown/caddy/alpine?style=flat-square) A tiny <10MB Caddy image compressed with [UPX](https://github.com/upx/upx). # Shared Tags -New versions are tracked within 4 hours. As of the time of writing, these are the tags available: +New versions are tracked within 4 hours. Currently available versions: -* `2.3.0-alpine`, `2-alpine`, `alpine` - -For the most up-to-date information, visit the Docker Hub tags page. +* `2.4.6-alpine`, `2-alpine`, `alpine` Legacy tags available that should not be used: * `2.0.0` -* `1.0.5`, `1` +* `1.0.0`, `1.0.1`, `1.0.2`, `1.0.3`, `1.0.4`, `1.0.5`, `1` +* `0.10.*`, `0.11.*` # Usage diff --git a/go.mod b/go.mod index 5e372f8..45a77fe 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/productionwentdown/caddy -go 1.14 +go 1.16 require ( - github.com/docker-library/go-dockerlibrary v0.0.0-20200501195759-c5db18cf68eb - pault.ag/go/debian v0.0.0-20190530135403-b831f604d664 // indirect + github.com/docker-library/go-dockerlibrary v0.0.0-20200821205225-669fbe5c1d52 + pault.ag/go/debian v0.12.0 // indirect ) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..28bfd34 --- /dev/null +++ b/go.sum @@ -0,0 +1,16 @@ +github.com/DataDog/zstd v1.4.8/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/docker-library/go-dockerlibrary v0.0.0-20200821205225-669fbe5c1d52 h1:Z3GnSICOyARBY/IBnOWtNN8N4AVRRDWxPEH28AM8wsg= +github.com/docker-library/go-dockerlibrary v0.0.0-20200821205225-669fbe5c1d52/go.mod h1:ijRhN3WM71dD8TfohKoUdX46BT2uz/Ek5O+5PINI880= +github.com/kjk/lzma v0.0.0-20161016003348-3fd93898850d/go.mod h1:phT/jsRPBAEqjAibu1BurrabCBNTYiVI+zbmyCZJY6Q= +github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +pault.ag/go/debian v0.12.0 h1:b8ctSdBSGJ98NE1VLn06aSx70EUpczlP2qqSHEiYYJA= +pault.ag/go/debian v0.12.0/go.mod h1:UbnMr3z/KZepjq7VzbYgBEfz8j4+Pyrm2L5X1fzhy/k= +pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a h1:WwS7vlB5H2AtwKj1jsGwp2ZLud1x6WXRXh2fXsRqrcA= +pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a/go.mod h1:INqx0ClF7kmPAMk2zVTX8DRnhZ/yaA/Mg52g8KFKE7k= diff --git a/update.go b/update.go index 02a0e3f..9324e0a 100644 --- a/update.go +++ b/update.go @@ -1,9 +1,9 @@ package main import ( - "os" "flag" "io/ioutil" + "os" "path" "strings" "text/template" @@ -16,6 +16,28 @@ var manifestURL = "https://github.com/docker-library/official-images/raw/master/ var maintainers = []string{"Ambrose Chua (@serverwentdown)"} var gitRepo = "https://github.com/productionwentdown/caddy.git" +var readmeTemplate = template.Must(template.New("readme").Parse(` +# [caddy](https://hub.docker.com/r/productionwentdown/caddy/) ![Docker Pulls](https://img.shields.io/docker/pulls/productionwentdown/caddy) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/productionwentdown/caddy/alpine?style=flat-square) + +A tiny <10MB Caddy image compressed with [UPX](https://github.com/upx/upx). + +# Shared Tags + +New versions are tracked within 4 hours. Currently available versions: +{{range $entry := .Entries}} +* {{range $index, $tag := $entry.Tags}}{{if $index}}, {{end}}` + "`{{$tag}}`" + `{{end}} +{{end}} +Legacy tags available that should not be used: + +* ` + "`2.0.0`" + ` +* ` + "`1.0.0`, `1.0.1`, `1.0.2`, `1.0.3`, `1.0.4`, `1.0.5`, `1`" + ` +* ` + "`0.10.*`, `0.11.*`" + ` + +# Usage + +See the [official image](https://hub.docker.com/_/caddy) for documentation. This image behaves the same way, except that it is much slimmer. +`)) + var dockerfileTemplate = template.Must(template.New("name").Parse(`FROM caddy:{{.Tag}} as build RUN apk add --no-cache upx ca-certificates \ @@ -58,12 +80,13 @@ CMD ["/usr/bin/caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", " type dockerfileData struct { Tag string Version string - Arch string + Arch string } func main() { doDockerfiles := flag.Bool("dockerfiles", false, "Update Dockerfiles") doManifest := flag.Bool("manifest", false, "Update manifest") + doReadme := flag.Bool("readme", false, "Update README.md") commit := flag.String("commit", "", "Current commit hash") flag.Parse() @@ -86,6 +109,12 @@ func main() { panic(err) } } + if *doReadme { + err = updateReadme(man) + if err != nil { + panic(err) + } + } } // subsetManifest returns the subset of the manifest that can be built @@ -171,3 +200,19 @@ func updateManifest(man *manifest.Manifest2822, gitCommit string) error { } return ioutil.WriteFile(manifestPath, []byte(man.String()), 0644) } + +// updateReadme generates a new README.md +func updateReadme(man *manifest.Manifest2822) error { + readmeFile, err := os.OpenFile("README.md", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + return err + } + defer readmeFile.Close() + + err = readmeTemplate.Execute(readmeFile, man) + if err != nil { + return err + } + + return nil +}