From 8f7be724f3eccb4c46a963a575ced300f045f672 Mon Sep 17 00:00:00 2001 From: Helder M Date: Wed, 21 Feb 2024 15:10:44 +0000 Subject: [PATCH] adapt for nibiru --- .github/goreleaser.yml | 32 -------------------------------- .github/workflows/ci.yml | 34 ---------------------------------- .github/workflows/docker.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 27 +++++++++++++++++++++++++++ .gitignore | 2 ++ Dockerfile | 11 +++++++++++ go.mod | 2 +- handler/config.go | 4 ++-- handler/handler.go | 15 ++++++++++----- handler/handler_test.go | 2 +- main.go | 4 ++-- scripts/install.rb.tmpl | 2 +- scripts/install.txt.tmpl | 2 +- 13 files changed, 90 insertions(+), 79 deletions(-) delete mode 100644 .github/goreleaser.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/test.yml create mode 100644 Dockerfile diff --git a/.github/goreleaser.yml b/.github/goreleaser.yml deleted file mode 100644 index e2838dc..0000000 --- a/.github/goreleaser.yml +++ /dev/null @@ -1,32 +0,0 @@ -# test this file with -# goreleaser --skip-publish --rm-dist --config goreleaser.yml -builds: - - env: - - CGO_ENABLED=0 - flags: - - -trimpath - ldflags: - - -s -w -X main.version={{.Version}} - goos: - - linux - - darwin - - windows - - openbsd - goarch: - - 386 - - amd64 - - arm - - arm64 - goarm: - - 6 - - 7 -archives: - - format: gz - files: - - none* -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index af7defe..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: CI -on: - pull_request: {} - push: {} - workflow_dispatch: - inputs: {} -jobs: - ci: - name: CI - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.19' - check-latest: true - cache: true - - name: Build - run: go build -v -o /dev/null . - - name: Test - run: go test -v ./... - - name: Run GoReleaser - if: startsWith(github.ref, 'refs/tags/v') - uses: goreleaser/goreleaser-action@v3 - with: - distribution: goreleaser - version: latest - args: release --rm-dist --config .github/goreleaser.yml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d51aa04 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,32 @@ +name: Build docker image + +on: + push: + tags: + - "*" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get version + id: get_version + uses: battila7/get-version-action@v2 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + platforms: linux/amd64 + tags: ghcr.io/nibiruchain/installer:latest,ghcr.io/nibiruchain/installer:${{ steps.get_version.outputs.version-without-v }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..50fa120 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Test +on: + pull_request: {} + push: {} + workflow_dispatch: + inputs: {} +jobs: + ci: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.18' + check-latest: true + cache: true + - name: Checkout code + uses: actions/checkout@v2 + - name: Build + run: go build -v . + - name: Test + run: go test -v ./... \ No newline at end of file diff --git a/.gitignore b/.gitignore index 32081ed..fa8e196 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ tmp/ test.sh +.idea +.envrc \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..51dffc0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:alpine AS builder +WORKDIR /src/app/ +COPY go.mod go.sum* ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 go build -o=/usr/local/bin/installer main.go + +FROM gcr.io/distroless/base +COPY --from=builder /usr/local/bin /usr/local/bin +USER nonroot:nonroot +ENTRYPOINT [ "/usr/local/bin/installer" ] \ No newline at end of file diff --git a/go.mod b/go.mod index da7d879..3a6862e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/jpillora/installer +module github.com/nibiruchain/installer go 1.18 diff --git a/handler/config.go b/handler/config.go index b7f3cb0..d711b69 100644 --- a/handler/config.go +++ b/handler/config.go @@ -4,7 +4,7 @@ package handler type Config struct { Host string `opts:"help=host, env=HTTP_HOST"` Port int `opts:"help=port, env"` - User string `opts:"help=default user when not provided in URL, env"` + User string `opts:"help=default user when not provided in URL"` Token string `opts:"help=github api token, env=GITHUB_TOKEN"` ForceUser string `opts:"help=lock installer to a single user, env=FORCE_USER"` ForceRepo string `opts:"help=lock installer to a single repo, env=FORCE_REPO"` @@ -13,5 +13,5 @@ type Config struct { // DefaultConfig for an installer handler var DefaultConfig = Config{ Port: 3000, - User: "jpillora", + User: "NibiruChain", } diff --git a/handler/handler.go b/handler/handler.go index 76c0db5..47fd1a2 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -16,7 +16,7 @@ import ( "text/template" "time" - "github.com/jpillora/installer/scripts" + "github.com/nibiruchain/installer/scripts" ) const ( @@ -132,9 +132,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if q.Release == "" { q.Release = "latest" } - // micro > nano! - if q.User == "" && q.Program == "micro" { - q.User = "zyedidia" + if q.User == "" { + q.User = "NibiruChain" + } + if q.Program == "" { + q.Program = "nibiru" + } + if q.Program == "nibiru" { + q.AsProgram = "nibid" } // force user/repo if h.Config.ForceUser != "" { @@ -146,7 +151,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // validate query valid := q.Program != "" if !valid && path == "" { - http.Redirect(w, r, "https://github.com/jpillora/installer", http.StatusMovedPermanently) + http.Redirect(w, r, "https://github.com/NibiruChain/installer", http.StatusMovedPermanently) return } if !valid { diff --git a/handler/handler_test.go b/handler/handler_test.go index ec58361..963dfb6 100644 --- a/handler/handler_test.go +++ b/handler/handler_test.go @@ -6,7 +6,7 @@ import ( "os/exec" "testing" - "github.com/jpillora/installer/handler" + "github.com/nibiruchain/installer/handler" ) func TestJPilloraServe(t *testing.T) { diff --git a/main.go b/main.go index 5821441..f040e1a 100644 --- a/main.go +++ b/main.go @@ -8,16 +8,16 @@ import ( "os" "time" - "github.com/jpillora/installer/handler" "github.com/jpillora/opts" "github.com/jpillora/requestlog" + "github.com/nibiruchain/installer/handler" ) var version = "0.0.0-src" func main() { c := handler.DefaultConfig - opts.New(&c).Repo("github.com/jpillora/installer").Version(version).Parse() + opts.New(&c).Repo("github.com/NibiruChain/installer").Version(version).Parse() log.Printf("default user is '%s'", c.User) if c.Token == "" && os.Getenv("GH_TOKEN") != "" { c.Token = os.Getenv("GH_TOKEN") // GH_TOKEN was renamed diff --git a/scripts/install.rb.tmpl b/scripts/install.rb.tmpl index 4fee373..a608f33 100644 --- a/scripts/install.rb.tmpl +++ b/scripts/install.rb.tmpl @@ -18,6 +18,6 @@ class Installer < Formula end def caveats - "{{ .Program }} was installed using https://github.com/jpillora/installer" + "{{ .Program }} was installed using https://github.com/NibiruChain/installer" end end diff --git a/scripts/install.txt.tmpl b/scripts/install.txt.tmpl index bb601f5..668b55b 100644 --- a/scripts/install.txt.tmpl +++ b/scripts/install.txt.tmpl @@ -16,6 +16,6 @@ has-m1-asset: {{ .M1Asset }} to see shell script, append ?type=script for more information on this server, visit: - github.com/jpillora/installer + github.com/NibiruChain/installer