From 1ab431542e7c486151ae545611b86e34645a06e4 Mon Sep 17 00:00:00 2001 From: Denis Tingaikin <49399980+denis-tingajkin@users.noreply.github.com> Date: Fri, 9 Oct 2020 13:11:58 +0700 Subject: [PATCH] Initial commit --- .github/workflows/ci.yaml | 203 ++++++++++++++++++ .github/workflows/docker-push.yaml | 30 +++ .github/workflows/pr-for-updates.yaml | 23 ++ .../workflows/update-cmd-repositories.yaml | 67 ++++++ .gitignore | 18 ++ .golangci.yml | 171 +++++++++++++++ .license/README.md | 48 +++++ .license/template.txt | 13 ++ .yamllint.yml | 15 ++ Dockerfile | 23 ++ LICENSE | 201 +++++++++++++++++ README.md | 75 +++++++ exclude.patch.conf | 2 + go.mod | 3 + go.sum | 0 main.go | 20 ++ staticcheck.conf | 10 + 17 files changed, 922 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/docker-push.yaml create mode 100644 .github/workflows/pr-for-updates.yaml create mode 100644 .github/workflows/update-cmd-repositories.yaml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 .license/README.md create mode 100644 .license/template.txt create mode 100644 .yamllint.yml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 exclude.patch.conf create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 staticcheck.conf diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..d9b5dbe --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,203 @@ +--- +name: ci +on: + push: + branches: + - master + pull_request: +jobs: + yamllint: + name: yamllint + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: yaml-lint + uses: ibiqlik/action-yamllint@v1 + with: + config_file: .yamllint.yml + strict: true + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: shellcheck + uses: fkautz/shell-linter@v1.0.1 + build: + name: build and test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Build + run: go build -race ./... + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + if: github.repository != 'networkservicemesh/cmd-template' + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.31 + + excludeFmtErrorf: + name: exclude fmt.Errorf + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Exclude fmt.Errorf + run: | + if grep -r --include=*.go --exclude=*.pb.go fmt.Errorf . ; then + echo "Please use errors.Errorf (or errors.New or errors.Wrap or errors.Wrapf) as appropriate rather than fmt.Errorf" + exit 1 + fi + + restrictNSMDeps: + name: Restrict dependencies on github.com/networkservicemesh/* + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Restrict dependencies on github.com/networkservicemesh/* + env: + ALLOWED_REPOSITORIES: "sdk, api, sdk-k8s, sdk-vppagent, sdk-sriov" + run: | + for i in $(grep github.com/networkservicemesh/ go.mod |grep -v '^module' | sed 's;.*\(github.com\/networkservicemesh\/[a-zA-z\/]*\).*;\1;g' | sort -u);do + if ! [ "$(echo ${ALLOWED_REPOSITORIES}| grep ${i#github.com/networkservicemesh/})" ]; then + echo Dependency on "${i}" is forbidden + exit 1 + fi; + done + + checkgomod: + name: check go.mod and go.sum + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: go mod tidy + - name: Check for changes in go.mod or go.sum + run: | + git diff --name-only --exit-code go.mod || ( echo "Run go tidy" && false ) + git diff --name-only --exit-code go.sum || ( echo "Run go tidy" && false ) + + gogenerate: + name: Check generated files + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: arduino/setup-protoc@master + with: + version: '3.8.0' + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - name: Install proto-gen-go + run: go get -u github.com/golang/protobuf/protoc-gen-go@v1.3.3 + - name: Install proto-gen-go + run: go get github.com/searKing/golang/tools/cmd/go-syncmap + - name: Generate files + run: go generate ./... + - name: Check for changes in generated code + run: | + git diff -- '*.pb.go' || ( echo "Rerun go generate ./... locally and resubmit" && false ) + git diff -- '*.gen.go' || ( echo "Rerun go generate ./... locally and resubmit" && false ) + + excludereplace: + name: Exclude Replace in go.mod + runs-on: ubuntu-latest + steps: + - name: Check out the code + uses: actions/checkout@v2 + - name: Exclude replace in go.mod + run: | + grep ^replace go.mod || exit 0 + exit 1 + docker: + name: Docker Build & Test + runs-on: ubuntu-latest + if: github.repository != 'networkservicemesh/cmd-template' + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Build container + run: docker build . + - name: Run tests + run: docker run --privileged --rm $(docker build -q . --target test) + - name: Find merged PR + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: jwalton/gh-find-current-pr@v1 + id: findPr + with: + github-token: ${{ github.token }} + + - name: Publish Image + if: github.event_name == 'push' && github.ref == 'refs/heads/master' && success() && steps.findPr.outputs.number + uses: matootie/github-docker@v3.0.0 + with: + accessToken: ${{ github.token }} + tag: | + pr-${{ steps.findPr.outputs.pr }} + commit-${{ github.sha }} + latest + pushImage: + name: Push docker image + runs-on: ubuntu-latest + env: + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_USER: ${{ secrets.DOCKER_LOGIN }} + TAG: master + ORG: networkservicemeshci + CGO_ENABLED: 0 + NAME: ${{ github.event.repository.name }} + needs: + - automerge + if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request' && github.repository != 'networkservicemesh/cmd-template' + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Build ${NAME} image + run: docker build . -t "${ORG}/${NAME}:${TAG}" --target runtime + - name: Push ${NAME} image + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + docker push "${ORG}/${NAME}:${TAG}" + docker image rm "${ORG}/${NAME}:${TAG}" + + automerge: + name: automerge + runs-on: ubuntu-latest + needs: + - build + - docker + if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request' + steps: + - name: Check out the code + uses: actions/checkout@v2 + - name: Fetch master + run: | + git remote -v + git fetch --depth=1 origin master + - name: NSMBot should update only config files + run: find . -type f ! -name 'go.mod' ! -name 'go.sum' ! -name '*.yaml' ! -name '*.yml' ! -name '*.txt' ! -name '*.md' ! -name '*.conf' -exec git diff --exit-code origin/master -- {} + + - name: Automerge nsmbot PR + uses: ridedott/merge-me-action@master + with: + GITHUB_LOGIN: nsmbot + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/docker-push.yaml b/.github/workflows/docker-push.yaml new file mode 100644 index 0000000..3f35b8a --- /dev/null +++ b/.github/workflows/docker-push.yaml @@ -0,0 +1,30 @@ +--- +name: push +on: + push: + branches: + - master +jobs: + pushImage: + name: Push docker image + runs-on: ubuntu-latest + env: + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_USER: ${{ secrets.DOCKER_LOGIN }} + TAG: master + ORG: networkservicemeshci + CGO_ENABLED: 0 + NAME: ${{ github.event.repository.name }} + if: github.repository != 'networkservicemesh/cmd-template' + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Build ${NAME} image + run: docker build . -t "${ORG}/${NAME}:${TAG}" --target runtime + - name: Push ${NAME} image + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + docker push "${ORG}/${NAME}:${TAG}" + docker image rm "${ORG}/${NAME}:${TAG}" diff --git a/.github/workflows/pr-for-updates.yaml b/.github/workflows/pr-for-updates.yaml new file mode 100644 index 0000000..ab804fc --- /dev/null +++ b/.github/workflows/pr-for-updates.yaml @@ -0,0 +1,23 @@ +--- +name: Pull Request on update/* Branch Push +on: + push: + branches: + - update/** +jobs: + auto-pull-request: + name: Pull Request on update/* Branch Push + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Construct PR message + run: | + PULL_REQUEST_BODY=$(git log -1) + echo ${PULL_REQUEST_BODY} + echo "::set-env name=PULL_REQUEST_BODY::${PULL_REQUEST_BODY}" + - name: pull-request-action + uses: vsoch/pull-request-action@1.0.6 + env: + GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + BRANCH_PREFIX: "update/" + PULL_REQUEST_BRANCH: "master" diff --git a/.github/workflows/update-cmd-repositories.yaml b/.github/workflows/update-cmd-repositories.yaml new file mode 100644 index 0000000..3900fef --- /dev/null +++ b/.github/workflows/update-cmd-repositories.yaml @@ -0,0 +1,67 @@ +--- +name: Update dependent repositories +on: + push: + branches: + - master + +jobs: + update-dependent-repositories: + strategy: + matrix: + repository: [cmd-registry-proxy-dns, cmd-nsc, cmd-registry-memory, cmd-nsmgr, cmd-forwarder-vppagent, cmd-exclude-prefixes-k8s] + name: Update ${{ matrix.repository }} + runs-on: ubuntu-latest + if: github.repository == 'networkservicemesh/cmd-template' + steps: + - name: Checkout ${{ github.repository }} + uses: actions/checkout@v2 + with: + path: ${{ github.repository }} + repository: ${{ github.repository }} + token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + - name: Find merged PR + uses: jwalton/gh-find-current-pr@v1 + id: findPr + with: + github-token: ${{ github.token }} + - name: Create commit message + working-directory: ${{ github.repository }} + run: | + echo "Update common CI files to latest version from ${{ github.repository }}@master ${{ github.repository }}#${{ steps.findPr.outputs.pr }}" >> /tmp/commit-message + echo "" >> /tmp/commit-message + echo "${{ github.repository }} PR link: https://github.com/${{ github.repository }}/pull/${{ steps.findPr.outputs.pr }}" >> /tmp/commit-message + echo "" >> /tmp/commit-message + echo "${{ github.repository }} commit message:" >> /tmp/commit-message + git log -1 >> /tmp/commit-message + echo "Commit Message:" + cat /tmp/commit-message + - name: Checkout networkservicemesh/${{ matrix.repository }} + uses: actions/checkout@v2 + with: + path: networkservicemesh/${{ matrix.repository }} + repository: networkservicemesh/${{ matrix.repository }} + token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Push update to the ${{ matrix.repository }} + working-directory: networkservicemesh/${{ matrix.repository }} + run: | + echo Starting to update repositotry ${{ matrix.repository }} + git config --global user.email "nsmbot@networkservicmesh.io" + git config --global user.name "NSMBot" + git remote add cmd_template https://github.com/networkservicemesh/cmd-template.git + git fetch cmd_template + git diff cmd_template/master -R | git apply + git add $(git ls-tree --name-only -r cmd_template/master | grep ".*\.yml\|.*\.yaml\|.*\.md\|.*\.txt\|.*.\.conf") + git restore --staged -- exclude.patch.conf + git restore -- exclude.patch.conf + git restore --staged -- $(cat exclude.patch.conf) + git restore -- $(cat exclude.patch.conf) + if ! [ -n "$(git diff --cached --exit-code)" ]; then + exit 0; + fi + git commit -s -F /tmp/commit-message + git checkout -b update/${{ github.repository }} + git push -f origin update/${{ github.repository }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be19042 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.idea/ +junit/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4f3e400 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,171 @@ +--- +run: + # concurrency: 6 + timeout: 2m + issues-exit-code: 1 + tests: true +linters-settings: + goheader: + template-path: ".license/template.txt" + values: + const: + year: 2020 + regexp: + year-range: ((\d\d\d\d-{{year}})|({{year}})) + company: .* + copyright-holder: Copyright \(c\) {{year-range}} {{company}}\n\n + copyright-holders: ({{copyright-holder}})+ + errcheck: + check-type-assertions: false + check-blank: false + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/sirupsen/logrus.FieldLogger).Infof + - (github.com/sirupsen/logrus.FieldLogger).Warnf + - (github.com/sirupsen/logrus.FieldLogger).Errorf + - (github.com/sirupsen/logrus.FieldLogger).Fatalf + golint: + min-confidence: 0.8 + goimports: + local-prefixes: github.com/networkservicemesh + gocyclo: + min-complexity: 15 + maligned: + suggest-new: true + dupl: + threshold: 150 + funlen: + Lines: 100 + Statements: 50 + goconst: + min-len: 2 + min-occurrences: 2 + depguard: + list-type: blacklist + include-go-root: false + packages: + - errors + packages-with-error-message: + # specify an error message to output when a blacklisted package is used + - errors: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" + misspell: + locale: US + unparam: + check-exported: false + nakedret: + max-func-lines: 30 + prealloc: + simple: true + range-loops: true + for-loops: false + gocritic: + enabled-checks: + - appendAssign + - assignOp + - appendCombine + - argOrder + - badCall + - badCond + - boolExprSimplify + - builtinShadow + - captLocal + - caseOrder + - codegenComment + - commentFormatting + - commentedOutCode + - commentedOutImport + - defaultCaseOrder + - deprecatedComment + - docStub + - dupArg + - dupBranchBody + - dupCase + - dupImport + - dupSubExpr + - elseif + - emptyFallthrough + - emptyStringTest + - equalFold + - evalOrder + - exitAfterDefer + - flagDeref + - flagName + - hexLiteral + - hugeParam + - ifElseChain + - importShadow + - indexAlloc + - initClause + - methodExprCall + - nestingReduce + - newDeref + - nilValReturn + - octalLiteral + - offBy1 + - paramTypeCombine + - rangeExprCopy + - rangeValCopy + - regexpMust + - regexpPattern + - singleCaseSwitch + - sloppyLen + - sloppyReassign + - stringXbytes + - switchTrue + - typeAssertChain + - typeSwitchVar + - typeUnparen + - unlabelStmt + - unnamedResult + - unnecessaryBlock + - underef + - unlambda + - unslice + - valSwap + - weakCond + - wrapperFunc + - yodaStyleExpr +linters: + disable-all: true + enable: + # - rowserrcheck + - goheader + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + # - lll + - misspell + - nakedret + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + # - unused + - varcheck + - whitespace +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/.license/README.md b/.license/README.md new file mode 100644 index 0000000..de881ea --- /dev/null +++ b/.license/README.md @@ -0,0 +1,48 @@ +## Copyright headers for source code +This folder contains the copyright templates for source files of NSM project. + +Below is an example of valid copyright header for `.go` files: +``` +// Copyright (c) 2020 Doc.ai and/or its affiliates. +// +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +``` +Note you can use your company name instead of `Cisco and/or its affiliates`. +Also, source code files can have multi copyright holders, for example: +``` +// Copyright (c) 2020 Doc.ai and/or its affiliates. +// +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// Copyright (c) 2020 Red Hat Inc. and/or its affiliates. +// +// Copyright (c) 2020 VMware, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +``` \ No newline at end of file diff --git a/.license/template.txt b/.license/template.txt new file mode 100644 index 0000000..cc3feeb --- /dev/null +++ b/.license/template.txt @@ -0,0 +1,13 @@ +{{copyright-holders}}SPDX-License-Identifier: Apache-2.0 + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..d4a3b49 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,15 @@ +--- +extends: default + +yaml-files: + - '*.yaml' + - '*.yml' + +rules: + truthy: disable + # 80 chars should be enough, but don't fail if a line is longer + line-length: disable + comments-indentation: + ignore: .circleci/config.yml + +ignore: scripts/aws/aws-k8s-cni.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4cb5e5c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.13-buster as go +ENV GO111MODULE=on +ENV CGO_ENABLED=0 +ENV GOBIN=/bin +RUN go get github.com/go-delve/delve/cmd/dlv@v1.4.0 +RUN go run github.com/edwarnicke/dl \ + https://github.com/spiffe/spire/releases/download/v0.9.3/spire-0.9.3-linux-x86_64-glibc.tar.gz | \ + tar -xzvf - -C /bin --strip=3 ./spire-0.9.3/bin/spire-server ./spire-0.9.3/bin/spire-agent + +FROM go as build +WORKDIR /build +COPY . . +RUN go build -o /bin/app . + +FROM build as test +CMD go test -test.v ./... + +FROM test as debug +CMD dlv -l :40000 --headless=true --api-version=2 test -test.v ./... + +FROM alpine as runtime +COPY --from=build /bin/app /bin/app +CMD /bin/app \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..80fa61b --- /dev/null +++ b/README.md @@ -0,0 +1,75 @@ +# Build + +## Build cmd binary locally + +You can build the locally by executing + +```bash +go build ./... +``` + +## Build Docker container + +You can build the docker container by running: + +```bash +docker build . +``` + +# Testing + +## Testing Docker container + +Testing is run via a Docker container. To run testing run: + +```bash +docker run --privileged --rm $(docker build -q --target test .) +``` + +# Debugging + +## Debugging the tests +If you wish to debug the test code itself, that can be acheived by running: + +```bash +docker run --privileged --rm -p 40000:40000 $(docker build -q --target debug .) +``` + +This will result in the tests running under dlv. Connecting your debugger to localhost:40000 will allow you to debug. + +```bash +-p 40000:40000 +``` +forwards port 40000 in the container to localhost:40000 where you can attach with your debugger. + +```bash +--target debug +``` + +Runs the debug target, which is just like the test target, but starts tests with dlv listening on port 40000 inside the container. + +## Debugging the cmd + +When you run 'cmd' you will see an early line of output that tells you: + +```Setting env variable DLV_LISTEN_FORWARDER to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.``` + +If you follow those instructions when running the Docker container: +```bash +docker run --privileged -e DLV_LISTEN_FORWARDER=:50000 -p 50000:50000 --rm $(docker build -q --target test .) +``` + +```-e DLV_LISTEN_FORWARDER=:50000``` tells docker to set the environment variable DLV_LISTEN_FORWARDER to :50000 telling +dlv to listen on port 50000. + +```-p 50000:50000``` tells docker to forward port 50000 in the container to port 50000 in the host. From there, you can +just connect dlv using your favorite IDE and debug cmd. + +## Debugging the tests and the cmd + +```bash +docker run --privileged -e DLV_LISTEN_FORWARDER=:50000 -p 40000:40000 -p 50000:50000 --rm $(docker build -q --target debug .) +``` + +Please note, the tests **start** the cmd, so until you connect to port 40000 with your debugger and walk the tests +through to the point of running cmd, you will not be able to attach a debugger on port 50000 to the cmd. \ No newline at end of file diff --git a/exclude.patch.conf b/exclude.patch.conf new file mode 100644 index 0000000..7631db6 --- /dev/null +++ b/exclude.patch.conf @@ -0,0 +1,2 @@ +README.md +.github/workflows/update-cmd-repositories.yaml \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..947c498 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/networkservicemesh/cmd-template + +go 1.14 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..6bd7d6a --- /dev/null +++ b/main.go @@ -0,0 +1,20 @@ +// Copyright (c) 2020 Doc.ai and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +func main() { +} diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 0000000..6b78d47 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,10 @@ +checks = ["all", "-ST1000", "-ST1016"] +initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", + "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", + "IP", "JSON", "NS", "NSM", "QPS", "RAM", "RPC", "SLA", + "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", + "UDP", "UI", "GID", "UID", "UUID", "URI", + "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", + "XSS"] +dot_import_whitelist = [] +http_status_code_whitelist = ["200", "400", "404", "500"]