Skip to content

Commit

Permalink
Add main.go and supporting materials (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Warnicke <[email protected]>
  • Loading branch information
edwarnicke authored Nov 18, 2020
1 parent 2253d9c commit 39d5ebd
Show file tree
Hide file tree
Showing 11 changed files with 1,050 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,8 @@ issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: main.go
linters:
- funlen
text: "Function 'main'"
3 changes: 2 additions & 1 deletion .templateignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
README.md
.github/workflows/update-cmd-repositories.yaml
.github/workflows/update-cmd-repositories.yaml
.golangci.yml
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
FROM golang:1.15-buster as go
FROM ghcr.io/edwarnicke/govpp/vpp:20.09 as go
COPY --from=golang:1.15.3-buster /usr/local/go/ /go
ENV PATH ${PATH}:/go/bin
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOBIN=/bin
RUN go get github.com/go-delve/delve/cmd/[email protected]
RUN go run github.com/edwarnicke/dl \
RUN rm -r /etc/vpp
RUN go get github.com/go-delve/delve/cmd/[email protected]
RUN go get github.com/edwarnicke/dl
RUN 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 go.mod go.sum ./
COPY ./local ./local
COPY ./internal/imports ./internal/imports
RUN go build ./internal/imports
COPY . .
RUN go build -o /bin/app .
RUN go build -o /bin/forwarder .

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
FROM ghcr.io/edwarnicke/govpp/vpp:20.09 as runtime
COPY --from=build /bin/forwarder /bin/forwarder
CMD /bin/forwarder
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ docker run --privileged -e DLV_LISTEN_FORWARDER=:50000 -p 40000:40000 -p 50000:5
```

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.
through to the point of running cmd, you will not be able to attach a debugger on port 50000 to the cmd.

## A Note on Running golangci-lint

Because cmd-forwarder-vppagent is only anticipated to run in Linux, you will need to run golangci-lint run with:

```go
GOOS=linux golangci-lint run
```
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
module github.com/networkservicemesh/cmd-template

go 1.15

require (
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/edwarnicke/debug v1.0.0
github.com/edwarnicke/grpcfd v0.0.0-20201107002751-f220aed0c5c8
github.com/edwarnicke/log v1.0.0
github.com/edwarnicke/signalctx v0.0.0-20201105214533-3a35840b3011
github.com/edwarnicke/vpphelper v0.0.0-20201118000727-c5667bc2b1a4
github.com/golang/protobuf v1.4.3
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20201117093615-ae6039374f31
github.com/networkservicemesh/sdk v0.0.0-20201118101019-1866c4819823
github.com/networkservicemesh/sdk-vpp v0.0.0-20201118180433-1079138cd080
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-beta.2
google.golang.org/grpc v1.33.2
)
704 changes: 704 additions & 0 deletions go.sum

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions internal/imports/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

package imports

//go:generate bash -c "cd $(mktemp -d) && GO111MODULE=on go get github.com/edwarnicke/[email protected]"
//go:generate bash -c "GOOS=linux ${GOPATH}/bin/imports-gen"
34 changes: 34 additions & 0 deletions internal/imports/imports_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// DO NOT EDIT - generated by github.com/edwarnicke/imports-gen
package imports

import (
_ "context"
_ "io/ioutil"
_ "net"
_ "net/url"
_ "os"
_ "path/filepath"
_ "time"

_ "github.com/antonfisher/nested-logrus-formatter"
_ "github.com/edwarnicke/debug"
_ "github.com/edwarnicke/grpcfd"
_ "github.com/edwarnicke/log"
_ "github.com/edwarnicke/signalctx"
_ "github.com/edwarnicke/vpphelper"
_ "github.com/golang/protobuf/ptypes"
_ "github.com/kelseyhightower/envconfig"
_ "github.com/sirupsen/logrus"
_ "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
_ "github.com/spiffe/go-spiffe/v2/workloadapi"
_ "google.golang.org/grpc"
_ "google.golang.org/grpc/credentials"

_ "github.com/networkservicemesh/api/pkg/api/registry"
_ "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/chains/xconnectns"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
_ "github.com/networkservicemesh/sdk/pkg/registry/core/chain"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
)
3 changes: 3 additions & 0 deletions local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!README.md
27 changes: 27 additions & 0 deletions local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
To work with a local dependent module, check out that module into this
directory, and put the local replace into the main go.mod.

Example:

```bash
cd local
git clone [email protected]:edwarnicke/sdk.git
cd sdk
git remote add upstream [email protected]:networkservicemesh/sdk.git
cd ../..
```

And then edit the go.mod file utilize a replace:

```vgo
module github.com/networkservicemesh/cmd-forwarder-vpp
go 1.13
require (
...
)
replace github.com/networkservicemesh/sdk => ./local/sdk
```

Loading

0 comments on commit 39d5ebd

Please sign in to comment.