From 353a7a8adef37ca5e7e7dfa8ab66930d596b19ce Mon Sep 17 00:00:00 2001 From: khorevaa Date: Thu, 4 Mar 2021 14:02:23 +0300 Subject: [PATCH] first init --- .github/workflows/releaser.yaml | 44 ++++++++++++++++++++++ .github/workflows/test.yml | 22 +++++++++++ .gitignore | 9 +++++ .goreleaser.yaml | 66 +++++++++++++++++++++++++++++++++ Dockerfile | 3 ++ LICENSE | 21 +++++++++++ cmd/commands.go | 19 ++++++++++ cmd/some_command.go | 61 ++++++++++++++++++++++++++++++ goreleaser.bat | 1 + goreleaser.sh | 7 ++++ main.go | 41 ++++++++++++++++++++ readme.md | 25 +++++++++++++ 12 files changed, 319 insertions(+) create mode 100644 .github/workflows/releaser.yaml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 cmd/commands.go create mode 100644 cmd/some_command.go create mode 100644 goreleaser.bat create mode 100644 goreleaser.sh create mode 100644 main.go create mode 100644 readme.md diff --git a/.github/workflows/releaser.yaml b/.github/workflows/releaser.yaml new file mode 100644 index 0000000..5bb801d --- /dev/null +++ b/.github/workflows/releaser.yaml @@ -0,0 +1,44 @@ +name: goreleaser + +on: + pull_request: + push: + tags: + - '*' +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - + name: Docker Login + if: success() && startsWith(github.ref, 'refs/tags/v') + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + echo "${GITHUB_TOKEN}" | docker login ghcr.io --username $GITHUB_ACTOR --password-stdin + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Clear + if: always() && startsWith(github.ref, 'refs/tags/v') + run: | + rm -f ${HOME}/.docker/config.json \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2131c8e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +on: [push, pull_request] +name: Test +jobs: + Build: + strategy: + matrix: + go-version: [1.16.x] + platform: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Fetch Repository + uses: actions/checkout@v2 + - name: Setup modules + run: | + go mod tidy + - name: Run Test + run: | + go test -race \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fdc5ad2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.exe +*.gz +*.zip + + +dist +.idea +*.logs + diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..5415268 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,66 @@ +project_name: app-template + +env: + - GO111MODULE=on +# - GOPROXY=https://goproxy.io +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + # - 386 + - amd64 +# - arm +# - arm64 +dist: dist + +checksum: + name_template: '{{ .ProjectName }}_checksums.txt' +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - Merge pull request + - Merge branch +dockers: + - image_templates: + - 'khorevaa/{{.ProjectName}}:{{ .Tag }}' + - 'khorevaa/{{.ProjectName}}:v{{ .Major }}.{{ .Minor }}' + - 'khorevaa/{{.ProjectName}}:latest' + - 'ghcr.io/khorevaa/{{.ProjectName}}:{{ .Tag }}' + - 'ghcr.io/khorevaa/{{.ProjectName}}:v{{ .Major }}.{{ .Minor }}' + - 'ghcr.io/khorevaa/{{.ProjectName}}:latest' + dockerfile: Dockerfile + binaries: + - app-template + build_flag_templates: + - "--label=org.label-schema.schema-version=1.0" + - "--label=org.label-schema.version={{.Version}}" + - "--label=org.label-schema.name={{.ProjectName}}" + - "--label=com.github.actions.name={{.ProjectName}}" + - "--label=com.github.actions.description=Setup new app-template description" + - "--label=com.github.actions.icon=terminal" + - "--label=com.github.actions.color=blue" + - "--label=repository=http://github.com/khorevaa/app-template" + - "--label=homepage=http://github.com/khorevaa/app-template" + - "--label=maintainerAleksey Khorev khorevaa@gmail.com" +archives: + - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8578bcc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +COPY app-template / +ENTRYPOINT ["/app-template"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4209135 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 khorevaa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cmd/commands.go b/cmd/commands.go new file mode 100644 index 0000000..08db319 --- /dev/null +++ b/cmd/commands.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/urfave/cli/v2" +) + +var Commands = []Command{ + + &someCommand{}, + //&commandWithSub{ + // sub: []Command{ + // &subCommand{}, + // }, + //}, +} + +type Command interface { + Cmd() *cli.Command +} diff --git a/cmd/some_command.go b/cmd/some_command.go new file mode 100644 index 0000000..45863fc --- /dev/null +++ b/cmd/some_command.go @@ -0,0 +1,61 @@ +package cmd + +import ( + "github.com/urfave/cli/v2" +) + +type someCommand struct { +} + +func (c *someCommand) run(context *cli.Context) error { + + return nil +} + +func (c *someCommand) Cmd() *cli.Command { + + cmd := &cli.Command{ + //Category: "some_category", + Name: "some_command", + Usage: "Usage decription", + Description: `Full usage description `, + Action: c.run, + Flags: []cli.Flag{ + //&cli.StringFlag{ + // Destination: &c.cluster, Name: "cluster-id", + // Value: "", Usage: "cluster uuid for join new work server"}, + //&cli.StringFlag{ + // Destination: &c.Name, Name: "name", Aliases: []string{"N"}, + // Value: "", Usage: "work server name", EnvVars: []string{"SERVER_NAME"}, Required: true}, + //&cli.StringFlag{ + // Destination: &c.AgentHost, Name: "host", + // Value: "", Usage: "work server agent host", EnvVars: []string{"SERVER_AGENT_HOST"}, Required: true}, + //&cli.IntFlag{ + // Destination: &c.AgentPort, Name: "port", + // Value: 1540, Usage: "work server agent port", EnvVars: []string{"SERVER_AGENT_HOST"}, DefaultText: "1540"}, + //&cli.StringFlag{ + // Destination: &c.PortRange, Name: "port-range", + // Value: "1560:1591", Usage: "work server port range", EnvVars: []string{"SERVER_PORT_RANGE"}, DefaultText: "1560:1591"}, + //&cli.StringFlag{ + // Destination: &c.Using, Name: "using", + // Value: "normal", Usage: "variant of using work server (main, normal)", EnvVars: []string{"SERVER_USING"}, DefaultText: "normal"}, + //&cli.StringFlag{ + // Destination: &c.DedicateManagers, Name: "dedicate-managers", + // Value: "none", Usage: "вариант размещения менеджеров сервисов (all, none)", EnvVars: []string{"SERVER_DEDICATE_MANAGERS"}, DefaultText: "none"}, + //&cli.IntFlag{ + // Destination: &c.ClusterPort, Name: "cluster-port", + // Value: 1541, Usage: "номер порта главного менеджера кластера", EnvVars: []string{"SERVER_CLUSTER_PORT"}, DefaultText: "1541"}, + //&cli.Int64Flag{ + // Destination: &c.MemoryLimit, Name: "memory-limit", + // Value: 0, Usage: "предел использования памяти рабочими процессами (kilobytes)", EnvVars: []string{"SERVER_MEMORY_LIMIT"}}, + //&cli.Int64Flag{ + // Destination: &c.ConnectionsLimit, Name: "connections-limit", + // Value: 128, Usage: "максимальное количество соединения на рабочий процесс", EnvVars: []string{"SERVER_CONNECTIONS_LIMIT"}, DefaultText: "128"}, + //&cli.Int64Flag{ + // Destination: &c.CriticalTotalMemory, Name: "total-memory", + // Value: 0, Usage: "максимальный объем памяти процессов рабочего сервера (bytes)", EnvVars: []string{"SERVER_TOTAL_MEMORY"}}, + }, + } + + return cmd +} diff --git a/goreleaser.bat b/goreleaser.bat new file mode 100644 index 0000000..f26e4fd --- /dev/null +++ b/goreleaser.bat @@ -0,0 +1 @@ +docker run --rm --privileged -v %cd%:/go/src/app -v /var/run/docker.sock:/var/run/docker.sock -w /go/src/app goreleaser/goreleaser:latest release --snapshot --skip-publish --rm-dist \ No newline at end of file diff --git a/goreleaser.sh b/goreleaser.sh new file mode 100644 index 0000000..e279eb8 --- /dev/null +++ b/goreleaser.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +docker run --rm --privileged \ + -v $PWD:/go/src/app \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -w /go/src/app \ + goreleaser/goreleaser:latest release --snapshot --skip-publish --rm-dist \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..eb7582f --- /dev/null +++ b/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "github.com/khorevaa/go-app-template/cmd" + "github.com/urfave/cli/v2" + "log" + "os" +) + +// nolint: gochecknoglobals +var ( + version = "dev" + commit = "" + date = "" + builtBy = "" +) + +func main() { + + app := &cli.App{ + Name: "go-app-template", + Version: version, + Authors: []*cli.Author{ + { + Name: "Aleksey Khorev", + }, + }, + Usage: "Description for go-app-template", + Copyright: "(c) 2021 Khorevaa", + //Description: "Command line utilities for server 1S.Enterprise", + } + + for _, command := range cmd.Commands { + app.Commands = append(app.Commands, command.Cmd()) + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..b2dd0f2 --- /dev/null +++ b/readme.md @@ -0,0 +1,25 @@ +# go-app-template + +[![Release](https://img.shields.io/github/release/khorevaa/go-app-template.svg?style=for-the-badge)](https://github.com/khorevaa/go-app-template/releases/latest) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge)](/LICENSE.md) +[![Build status](https://img.shields.io/github/workflow/status/khorevaa/go-app-template/build?style=for-the-badge)](https://github.com/khorevaa/go-app-template/actions?workflow=releaser) +[![Codecov branch](https://img.shields.io/codecov/c/github/khorevaa/go-app-template/master.svg?style=for-the-badge)](https://codecov.io/gh/khorevaa/go-app-template) +[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=for-the-badge)](http://godoc.org/github.com/khorevaa/go-app-template) +[![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=for-the-badge)](https://saythanks.io/to/khorevaa) +[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=for-the-badge)](https://github.com/goreleaser) +[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org) + +## Features + + +## Installation + + + +## How to use + +### Docker + +### Github Release + +## License \ No newline at end of file