mirror of
https://github.com/nicksherron/bashhub-server.git
synced 2024-11-13 03:04:47 +08:00
Initial Commit.
This commit is contained in:
commit
1ea90f91aa
12 changed files with 329 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bin
|
||||||
|
vendor
|
9
.travis.yml
Normal file
9
.travis.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
language: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.8.x
|
||||||
|
- master
|
||||||
|
|
||||||
|
install:
|
||||||
|
- go get -v github.com/Masterminds/glide
|
||||||
|
- make get-deps
|
9
AUTHORS.md
Normal file
9
AUTHORS.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Credits
|
||||||
|
|
||||||
|
## Development Lead
|
||||||
|
|
||||||
|
- Nick Sherron [nicksherron](https://github.com/nicksherron)
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
None yet. Why not be the first?
|
81
CONTRIBUTING.md
Normal file
81
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
|
||||||
|
|
||||||
|
You can contribute in many ways:
|
||||||
|
|
||||||
|
## Types of Contributions
|
||||||
|
|
||||||
|
### Report Bugs
|
||||||
|
|
||||||
|
Report bugs at https://github.com/nicksherron/bashhub-server/issues.
|
||||||
|
|
||||||
|
If you are reporting a bug, please include:
|
||||||
|
|
||||||
|
* Your operating system name and version.
|
||||||
|
* Any details about your local setup that might be helpful in troubleshooting.
|
||||||
|
* Detailed steps to reproduce the bug.
|
||||||
|
|
||||||
|
### Fix Bugs
|
||||||
|
|
||||||
|
Look through the GitHub issues for bugs. Anything tagged with "bug"
|
||||||
|
is open to whoever wants to implement it.
|
||||||
|
|
||||||
|
### Implement Features
|
||||||
|
|
||||||
|
Look through the GitHub issues for features. Anything tagged with "feature"
|
||||||
|
is open to whoever wants to implement it.
|
||||||
|
|
||||||
|
### Write Documentation
|
||||||
|
|
||||||
|
bashhub-server could always use more documentation, whether as part of the
|
||||||
|
official bashhub-server docs, in docstrings, or even on the web in blog posts,
|
||||||
|
articles, and such.
|
||||||
|
|
||||||
|
### Submit Feedback
|
||||||
|
|
||||||
|
The best way to send feedback is to file an issue at https://github.com/nicksherron/bashhub-server/issues.
|
||||||
|
|
||||||
|
If you are proposing a feature:
|
||||||
|
|
||||||
|
* Explain in detail how it would work.
|
||||||
|
* Keep the scope as narrow as possible, to make it easier to implement.
|
||||||
|
* Remember that this is a volunteer-driven project, and that contributions
|
||||||
|
are welcome :)
|
||||||
|
|
||||||
|
## Get Started!
|
||||||
|
|
||||||
|
Ready to contribute? Here's how to set up `bashhub-server` for local development.
|
||||||
|
|
||||||
|
1. Fork the `bashhub-server` repo on GitHub.
|
||||||
|
2. Clone your fork locally::
|
||||||
|
```bash
|
||||||
|
$ git clone git@github.com:your_name_here/bashhub-server.git
|
||||||
|
```
|
||||||
|
3. Create a branch for local development::
|
||||||
|
```bash
|
||||||
|
$ git checkout -b name-of-your-bugfix-or-feature
|
||||||
|
```
|
||||||
|
Now you can make your changes locally.
|
||||||
|
|
||||||
|
4. When you're done making changes, check that your changes pass the tests::
|
||||||
|
```bash
|
||||||
|
$ make test
|
||||||
|
```
|
||||||
|
6. Commit your changes and push your branch to GitHub::
|
||||||
|
```bash
|
||||||
|
$ git add .
|
||||||
|
$ git commit -m "Your detailed description of your changes."
|
||||||
|
$ git push origin name-of-your-bugfix-or-feature
|
||||||
|
```
|
||||||
|
7. Submit a pull request through the GitHub website.
|
||||||
|
|
||||||
|
Pull Request Guidelines
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Before you submit a pull request, check that it meets these guidelines:
|
||||||
|
|
||||||
|
1. The pull request should include tests.
|
||||||
|
2. If the pull request adds functionality, the docs should be updated. Put
|
||||||
|
your new functionality into a function with a docstring, and add the
|
||||||
|
feature to the list in README.md.
|
40
Dockerfile
Normal file
40
Dockerfile
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# Build Stage
|
||||||
|
FROM nicksherron/bashhub-server-build:1.13 AS build-stage
|
||||||
|
|
||||||
|
LABEL app="build-bashhub-server"
|
||||||
|
LABEL REPO="https://github.com/nicksherron/bashhub-server"
|
||||||
|
|
||||||
|
ENV PROJPATH=/go/src/github.com/nicksherron/bashhub-server
|
||||||
|
|
||||||
|
# Because of https://github.com/docker/docker/issues/14914
|
||||||
|
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
|
||||||
|
|
||||||
|
ADD . /go/src/github.com/nicksherron/bashhub-server
|
||||||
|
WORKDIR /go/src/github.com/nicksherron/bashhub-server
|
||||||
|
|
||||||
|
RUN make build-alpine
|
||||||
|
|
||||||
|
# Final Stage
|
||||||
|
FROM nicksherron/bashhub-server
|
||||||
|
|
||||||
|
ARG GIT_COMMIT
|
||||||
|
ARG VERSION
|
||||||
|
LABEL REPO="https://github.com/nicksherron/bashhub-server"
|
||||||
|
LABEL GIT_COMMIT=$GIT_COMMIT
|
||||||
|
LABEL VERSION=$VERSION
|
||||||
|
|
||||||
|
# Because of https://github.com/docker/docker/issues/14914
|
||||||
|
ENV PATH=$PATH:/opt/bashhub-server/bin
|
||||||
|
|
||||||
|
WORKDIR /opt/bashhub-server/bin
|
||||||
|
|
||||||
|
COPY --from=build-stage /go/src/github.com/nicksherron/bashhub-server/bin/bashhub-server /opt/bashhub-server/bin/
|
||||||
|
RUN chmod +x /opt/bashhub-server/bin/bashhub-server
|
||||||
|
|
||||||
|
# Create appuser
|
||||||
|
RUN adduser -D -g '' bashhub-server
|
||||||
|
USER bashhub-server
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
||||||
|
|
||||||
|
CMD ["/opt/bashhub-server/bin/bashhub-server"]
|
61
Makefile
Normal file
61
Makefile
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
.PHONY: build build-alpine clean test help default
|
||||||
|
|
||||||
|
BIN_NAME=bashhub-server
|
||||||
|
|
||||||
|
VERSION := $(shell grep "const Version " version/version.go | sed -E 's/.*"(.+)"$$/\1/')
|
||||||
|
GIT_COMMIT=$(shell git rev-parse HEAD)
|
||||||
|
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
||||||
|
BUILD_DATE=$(shell date '+%Y-%m-%d-%H:%M:%S')
|
||||||
|
IMAGE_NAME := "nicksherron/bashhub-server"
|
||||||
|
|
||||||
|
default: test
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo 'Management commands for bashhub-server:'
|
||||||
|
@echo
|
||||||
|
@echo 'Usage:'
|
||||||
|
@echo ' make build Compile the project.'
|
||||||
|
@echo ' make get-deps runs dep ensure, mostly used for ci.'
|
||||||
|
@echo ' make build-alpine Compile optimized for alpine linux.'
|
||||||
|
@echo ' make package Build final docker image with just the go binary inside'
|
||||||
|
@echo ' make tag Tag image created by package with latest, git commit and version'
|
||||||
|
@echo ' make test Run tests on a compiled project.'
|
||||||
|
@echo ' make push Push tagged images to registry'
|
||||||
|
@echo ' make clean Clean the directory tree.'
|
||||||
|
@echo
|
||||||
|
|
||||||
|
build:
|
||||||
|
@echo "building ${BIN_NAME} ${VERSION}"
|
||||||
|
@echo "GOPATH=${GOPATH}"
|
||||||
|
go build -ldflags "-X github.com/nicksherron/bashhub-server/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/nicksherron/bashhub-server/version.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME}
|
||||||
|
|
||||||
|
get-deps:
|
||||||
|
dep ensure
|
||||||
|
|
||||||
|
build-alpine:
|
||||||
|
@echo "building ${BIN_NAME} ${VERSION}"
|
||||||
|
@echo "GOPATH=${GOPATH}"
|
||||||
|
go build -ldflags '-w -linkmode external -extldflags "-static" -X github.com/nicksherron/bashhub-server/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/nicksherron/bashhub-server/version.BuildDate=${BUILD_DATE}' -o bin/${BIN_NAME}
|
||||||
|
|
||||||
|
package:
|
||||||
|
@echo "building image ${BIN_NAME} ${VERSION} $(GIT_COMMIT)"
|
||||||
|
docker build --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$(GIT_COMMIT) -t $(IMAGE_NAME):local .
|
||||||
|
|
||||||
|
tag:
|
||||||
|
@echo "Tagging: latest ${VERSION} $(GIT_COMMIT)"
|
||||||
|
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):$(GIT_COMMIT)
|
||||||
|
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):${VERSION}
|
||||||
|
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):latest
|
||||||
|
|
||||||
|
push: tag
|
||||||
|
@echo "Pushing docker image to registry: latest ${VERSION} $(GIT_COMMIT)"
|
||||||
|
docker push $(IMAGE_NAME):$(GIT_COMMIT)
|
||||||
|
docker push $(IMAGE_NAME):${VERSION}
|
||||||
|
docker push $(IMAGE_NAME):latest
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@test ! -e bin/${BIN_NAME} || rm bin/${BIN_NAME}
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test ./...
|
||||||
|
|
18
README.md
Normal file
18
README.md
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# bashhub-server
|
||||||
|
|
||||||
|
Private BashHub server
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
This project requires Go to be installed. On OS X with Homebrew you can just run `brew install go`.
|
||||||
|
|
||||||
|
Running it then should be as simple as:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ make
|
||||||
|
$ ./bin/bashhub-server
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
``make test``
|
43
cmd/root.go
Normal file
43
cmd/root.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cfgFile string
|
||||||
|
|
||||||
|
// rootCmd represents the base command when called without any subcommands
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "generated code example",
|
||||||
|
Short: "A brief description of your application",
|
||||||
|
Long: `A longer description that spans multiple lines and likely contains
|
||||||
|
examples and usage of using your application. For example:
|
||||||
|
|
||||||
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
|
This application is a tool to generate the needed files
|
||||||
|
to quickly create a Cobra application.`,
|
||||||
|
// Uncomment the following line if your bare application
|
||||||
|
// has an action associated with it:
|
||||||
|
// Run: func(cmd *cobra.Command, args []string) { },
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
|
func Execute() {
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cobra.OnInitialize()
|
||||||
|
|
||||||
|
// Cobra also supports local flags, which will only run
|
||||||
|
// when this action is called directly.
|
||||||
|
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
|
||||||
|
}
|
25
cmd/version.go
Normal file
25
cmd/version.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/lacion/cookiecutter_golang_example/version"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// versionCmd represents the version command
|
||||||
|
var versionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print the version number of generated code example",
|
||||||
|
Long: `All software has versions. This is generated code example`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Build Date:", version.BuildDate)
|
||||||
|
fmt.Println("Git Commit:", version.GitCommit)
|
||||||
|
fmt.Println("Version:", version.Version)
|
||||||
|
fmt.Println("Go Version:", version.GoVersion)
|
||||||
|
fmt.Println("OS / Arch:", version.OsArch)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
}
|
7
go.mod
Normal file
7
go.mod
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module github.com/nicksherron/bashhub-server
|
||||||
|
|
||||||
|
require (
|
||||||
|
|
||||||
|
github.com/spf13/cobra v0.0.3
|
||||||
|
|
||||||
|
)
|
13
main.go
Normal file
13
main.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
"github.com/nicksherron/bashhub-server/cmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
|
||||||
|
cmd.Execute()
|
||||||
|
|
||||||
|
}
|
21
version/version.go
Normal file
21
version/version.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GitCommit returns the git commit that was compiled. This will be filled in by the compiler.
|
||||||
|
var GitCommit string
|
||||||
|
|
||||||
|
// Version returns the main version number that is being run at the moment.
|
||||||
|
const Version = "0.1.0"
|
||||||
|
|
||||||
|
// BuildDate returns the date the binary was built
|
||||||
|
var BuildDate = ""
|
||||||
|
|
||||||
|
// GoVersion returns the version of the go runtime used to compile the binary
|
||||||
|
var GoVersion = runtime.Version()
|
||||||
|
|
||||||
|
// OsArch returns the os and arch used to build the binary
|
||||||
|
var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)
|
Loading…
Reference in a new issue