Skip to content

Commit cf845c6

Browse files
Add cookiecutter files.
1 parent 3bdf8a8 commit cf845c6

File tree

10 files changed

+358
-0
lines changed

10 files changed

+358
-0
lines changed

AUTHORS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Credits
2+
3+
## Development Lead
4+
5+
- Mikhail Yohman [FragmentedPacket](https://github.com/FragmentedPacket)
6+
7+
## Contributors
8+
9+
None yet. Why not be the first?

CONTRIBUTING.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Contributing
2+
3+
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
4+
5+
You can contribute in many ways:
6+
7+
## Types of Contributions
8+
9+
### Report Bugs
10+
11+
Report bugs at https://github.com/FragmentedPacket/net_backup/issues.
12+
13+
If you are reporting a bug, please include:
14+
15+
* Your operating system name and version.
16+
* Any details about your local setup that might be helpful in troubleshooting.
17+
* Detailed steps to reproduce the bug.
18+
19+
### Fix Bugs
20+
21+
Look through the GitHub issues for bugs. Anything tagged with "bug"
22+
is open to whoever wants to implement it.
23+
24+
### Implement Features
25+
26+
Look through the GitHub issues for features. Anything tagged with "feature"
27+
is open to whoever wants to implement it.
28+
29+
### Write Documentation
30+
31+
net_backup could always use more documentation, whether as part of the
32+
official net_backup docs, in docstrings, or even on the web in blog posts,
33+
articles, and such.
34+
35+
### Submit Feedback
36+
37+
The best way to send feedback is to file an issue at https://github.com/FragmentedPacket/net_backup/issues.
38+
39+
If you are proposing a feature:
40+
41+
* Explain in detail how it would work.
42+
* Keep the scope as narrow as possible, to make it easier to implement.
43+
* Remember that this is a volunteer-driven project, and that contributions
44+
are welcome :)
45+
46+
## Get Started!
47+
48+
Ready to contribute? Here's how to set up `net_backup` for local development.
49+
50+
1. Fork the `net_backup` repo on GitHub.
51+
2. Clone your fork locally::
52+
```bash
53+
$ git clone [email protected]:your_name_here/net_backup.git
54+
```
55+
3. Create a branch for local development::
56+
```bash
57+
$ git checkout -b name-of-your-bugfix-or-feature
58+
```
59+
Now you can make your changes locally.
60+
61+
4. When you're done making changes, check that your changes pass the tests::
62+
```bash
63+
$ make test
64+
```
65+
6. Commit your changes and push your branch to GitHub::
66+
```bash
67+
$ git add .
68+
$ git commit -m "Your detailed description of your changes."
69+
$ git push origin name-of-your-bugfix-or-feature
70+
```
71+
7. Submit a pull request through the GitHub website.
72+
73+
Pull Request Guidelines
74+
-----------------------
75+
76+
Before you submit a pull request, check that it meets these guidelines:
77+
78+
1. The pull request should include tests.
79+
2. If the pull request adds functionality, the docs should be updated. Put
80+
your new functionality into a function with a docstring, and add the
81+
feature to the list in README.md.

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Build Stage
2+
FROM lacion/alpine-golang-buildimage:1.13 AS build-stage
3+
4+
LABEL app="build-net_backup"
5+
LABEL REPO="https://github.com/FragmentedPacket/net_backup"
6+
7+
ENV PROJPATH=/go/src/github.com/FragmentedPacket/net_backup
8+
9+
# Because of https://github.com/docker/docker/issues/14914
10+
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
11+
12+
ADD . /go/src/github.com/FragmentedPacket/net_backup
13+
WORKDIR /go/src/github.com/FragmentedPacket/net_backup
14+
15+
RUN make build-alpine
16+
17+
# Final Stage
18+
FROM fragmentedpacket
19+
20+
ARG GIT_COMMIT
21+
ARG VERSION
22+
LABEL REPO="https://github.com/FragmentedPacket/net_backup"
23+
LABEL GIT_COMMIT=$GIT_COMMIT
24+
LABEL VERSION=$VERSION
25+
26+
# Because of https://github.com/docker/docker/issues/14914
27+
ENV PATH=$PATH:/opt/net_backup/bin
28+
29+
WORKDIR /opt/net_backup/bin
30+
31+
COPY --from=build-stage /go/src/github.com/FragmentedPacket/net_backup/bin/net_backup /opt/net_backup/bin/
32+
RUN chmod +x /opt/net_backup/bin/net_backup
33+
34+
# Create appuser
35+
RUN adduser -D -g '' net_backup
36+
USER net_backup
37+
38+
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
39+
40+
CMD ["/opt/net_backup/bin/net_backup"]

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
.PHONY: build build-alpine clean test help default
3+
4+
5+
6+
BIN_NAME=net_backup
7+
8+
VERSION := $(shell grep "const Version " version/version.go | sed -E 's/.*"(.+)"$$/\1/')
9+
GIT_COMMIT=$(shell git rev-parse HEAD)
10+
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
11+
BUILD_DATE=$(shell date '+%Y-%m-%d-%H:%M:%S')
12+
IMAGE_NAME := "lacion/net_backup"
13+
14+
default: test
15+
16+
help:
17+
@echo 'Management commands for net_backup:'
18+
@echo
19+
@echo 'Usage:'
20+
@echo ' make build Compile the project.'
21+
@echo ' make get-deps runs dep ensure, mostly used for ci.'
22+
@echo ' make build-alpine Compile optimized for alpine linux.'
23+
@echo ' make package Build final docker image with just the go binary inside'
24+
@echo ' make tag Tag image created by package with latest, git commit and version'
25+
@echo ' make test Run tests on a compiled project.'
26+
@echo ' make push Push tagged images to registry'
27+
@echo ' make clean Clean the directory tree.'
28+
@echo
29+
30+
build:
31+
@echo "building ${BIN_NAME} ${VERSION}"
32+
@echo "GOPATH=${GOPATH}"
33+
go build -ldflags "-X github.com/FragmentedPacket/net_backup/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/FragmentedPacket/net_backup/version.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME}
34+
35+
get-deps:
36+
dep ensure
37+
38+
build-alpine:
39+
@echo "building ${BIN_NAME} ${VERSION}"
40+
@echo "GOPATH=${GOPATH}"
41+
go build -ldflags '-w -linkmode external -extldflags "-static" -X github.com/FragmentedPacket/net_backup/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/FragmentedPacket/net_backup/version.BuildDate=${BUILD_DATE}' -o bin/${BIN_NAME}
42+
43+
package:
44+
@echo "building image ${BIN_NAME} ${VERSION} $(GIT_COMMIT)"
45+
docker build --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$(GIT_COMMIT) -t $(IMAGE_NAME):local .
46+
47+
tag:
48+
@echo "Tagging: latest ${VERSION} $(GIT_COMMIT)"
49+
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):$(GIT_COMMIT)
50+
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):${VERSION}
51+
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):latest
52+
53+
push: tag
54+
@echo "Pushing docker image to registry: latest ${VERSION} $(GIT_COMMIT)"
55+
docker push $(IMAGE_NAME):$(GIT_COMMIT)
56+
docker push $(IMAGE_NAME):${VERSION}
57+
docker push $(IMAGE_NAME):latest
58+
59+
clean:
60+
@test ! -e bin/${BIN_NAME} || rm bin/${BIN_NAME}
61+
62+
test:
63+
go test ./...
64+

cmd/root.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var cfgFile string
11+
12+
// rootCmd represents the base command when called without any subcommands
13+
var rootCmd = &cobra.Command{
14+
Use: "generated code example",
15+
Short: "A brief description of your application",
16+
Long: `A longer description that spans multiple lines and likely contains
17+
examples and usage of using your application. For example:
18+
19+
Cobra is a CLI library for Go that empowers applications.
20+
This application is a tool to generate the needed files
21+
to quickly create a Cobra application.`,
22+
// Uncomment the following line if your bare application
23+
// has an action associated with it:
24+
// Run: func(cmd *cobra.Command, args []string) { },
25+
}
26+
27+
// Execute adds all child commands to the root command and sets flags appropriately.
28+
// This is called by main.main(). It only needs to happen once to the rootCmd.
29+
func Execute() {
30+
if err := rootCmd.Execute(); err != nil {
31+
fmt.Println(err)
32+
os.Exit(1)
33+
}
34+
}
35+
36+
func init() {
37+
cobra.OnInitialize()
38+
39+
// Cobra also supports local flags, which will only run
40+
// when this action is called directly.
41+
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
42+
43+
}

cmd/version.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/FragmentedPacket/net_backup/version"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// versionCmd represents the version command
10+
var versionCmd = &cobra.Command{
11+
Use: "version",
12+
Short: "Print the version number of generated code example",
13+
Long: `All software has versions. This is generated code example`,
14+
Run: func(cmd *cobra.Command, args []string) {
15+
fmt.Println("Build Date:", version.BuildDate)
16+
fmt.Println("Git Commit:", version.GitCommit)
17+
fmt.Println("Version:", version.Version)
18+
fmt.Println("Go Version:", version.GoVersion)
19+
fmt.Println("OS / Arch:", version.OsArch)
20+
},
21+
}
22+
23+
func init() {
24+
rootCmd.AddCommand(versionCmd)
25+
}

config/config.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package config
2+
3+
import (
4+
"time"
5+
6+
"github.com/spf13/viper"
7+
)
8+
9+
// Provider defines a set of read-only methods for accessing the application
10+
// configuration params as defined in one of the config files.
11+
type Provider interface {
12+
ConfigFileUsed() string
13+
Get(key string) interface{}
14+
GetBool(key string) bool
15+
GetDuration(key string) time.Duration
16+
GetFloat64(key string) float64
17+
GetInt(key string) int
18+
GetInt64(key string) int64
19+
GetSizeInBytes(key string) uint
20+
GetString(key string) string
21+
GetStringMap(key string) map[string]interface{}
22+
GetStringMapString(key string) map[string]string
23+
GetStringMapStringSlice(key string) map[string][]string
24+
GetStringSlice(key string) []string
25+
GetTime(key string) time.Time
26+
InConfig(key string) bool
27+
IsSet(key string) bool
28+
}
29+
30+
var defaultConfig *viper.Viper
31+
32+
// Config returns a default config providers
33+
func Config() Provider {
34+
return defaultConfig
35+
}
36+
37+
// LoadConfigProvider returns a configured viper instance
38+
func LoadConfigProvider(appName string) Provider {
39+
return readViperConfig(appName)
40+
}
41+
42+
func init() {
43+
defaultConfig = readViperConfig("NET_BACKUP")
44+
}
45+
46+
func readViperConfig(appName string) *viper.Viper {
47+
v := viper.New()
48+
v.SetEnvPrefix(appName)
49+
v.AutomaticEnv()
50+
51+
// global defaults
52+
53+
54+
return v
55+
}

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/FragmentedPacket/net_backup
2+
3+
require (
4+
5+
github.com/spf13/cobra v0.0.3
6+
github.com/spf13/viper v1.3.2
7+
)

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
5+
"github.com/FragmentedPacket/net_backup/cmd"
6+
)
7+
8+
func main() {
9+
10+
11+
cmd.Execute()
12+
13+
}

version/version.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
7+
8+
// GitCommit returns the git commit that was compiled. This will be filled in by the compiler.
9+
var GitCommit string
10+
11+
// Version returns the main version number that is being run at the moment.
12+
const Version = "0.1.0"
13+
14+
// BuildDate returns the date the binary was built
15+
var BuildDate = ""
16+
17+
// GoVersion returns the version of the go runtime used to compile the binary
18+
var GoVersion = runtime.Version()
19+
20+
// OsArch returns the os and arch used to build the binary
21+
var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)

0 commit comments

Comments
 (0)