Skip to content

Commit

Permalink
Add version when build; Remove debug info from docker image.
Browse files Browse the repository at this point in the history
  • Loading branch information
ihciah committed Oct 14, 2019
1 parent 61c1124 commit 6a1c449
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 25 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
uses: actions/checkout@v1

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@cade1bc
uses: ihciah/Publish-Docker-Github-Action@master
with:
name: ihciah/rabbit
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
password: ${{ secrets.DOCKER_PASSWORD }}
spectag: ${{ github.ref }}
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ jobs:
go get -v -t -d ./...
- name: Build
run: make releases
run: |
TAG=${{ github.ref }}
TAG=${TAG#"refs/tags/"}
TAG=${TAG#"v"}
TAG=${TAG#"V"}
make releases RABBITVERSION=$TAG
- name: Create Release
id: create_release
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ COPY . /go/src/github.com/ihciah/rabbit-tcp

RUN apk upgrade \
&& apk add git \
&& go get github.com/ihciah/rabbit-tcp/cmd
&& apk add make \
&& cd /go/src/github.com/ihciah/rabbit-tcp \
&& go get -v -t -d ./... \
&& make

FROM alpine:latest AS dist
LABEL maintainer="ihciah <[email protected]>"
Expand All @@ -18,7 +21,7 @@ ENV DEST=
ENV TUNNELN 6
ENV VERBOSE 2

COPY --from=builder /go/bin/cmd /usr/bin/rabbit
COPY --from=builder /go/src/github.com/ihciah/rabbit-tcp/bin/rabbit /usr/bin/rabbit

CMD exec rabbit \
--mode=$MODE \
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
NAME=rabbit
BINDIR=bin
GOBUILD=CGO_ENABLED=0 go build -ldflags '-w -s'
VERSIONPARAM=
ifdef RABBITVERSION
VERSIONPARAM=-X 'main.Version=$(RABBITVERSION)'
endif
GOBUILD=CGO_ENABLED=0 go build -ldflags "-w -s $(VERSIONPARAM)"
BUILDFILE=cmd/rabbit.go
# The -w and -s flags reduce binary sizes by excluding unnecessary symbols and debug info

current:
$(GOBUILD) -o $(BINDIR)/$(NAME) $(BUILDFILE)

all: linux-amd64 linux-386 linux-arm64 linux-arm darwin-amd64 darwin-386 windows-amd64 windows-386

Expand Down
61 changes: 43 additions & 18 deletions cmd/rabbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,84 @@ import (
"strings"
)

var Version = "No version information"

const (
ClientMode = iota
ServerMode
DefaultPassword = "PASSWORD"
)

func parseFlags() (int, string, string, string, string, int, int) {
var mode int
func parseFlags() (pass bool, mode int, password string, addr string, listen string, dest string, tunnelN int, verbose int) {
var modeString string
var password string
var addr string
var listen string
var dest string
var tunnelN int
var verbose int
var printVersion bool
flag.StringVar(&modeString, "mode", "c", "running mode(s or c)")
flag.StringVar(&password, "password", DefaultPassword, "password")
flag.StringVar(&addr, "rabbit-addr", ":443", "listen(server mode) or remote(client mode) address used by rabbit-tcp")
flag.StringVar(&listen, "listen", "", "[Client Only] listen address, eg: 127.0.0.1:2333")
flag.StringVar(&dest, "dest", "", "[Client Only] destination address, eg: shadowsocks server address")
flag.IntVar(&tunnelN, "tunnelN", 6, "[Client Only] number of tunnels to use in rabbit-tcp")
flag.IntVar(&verbose, "verbose", 2, "Verbose level(0~5)")
flag.IntVar(&tunnelN, "tunnelN", 4, "[Client Only] number of tunnels to use in rabbit-tcp")
flag.IntVar(&verbose, "verbose", 2, "verbose level(0~5)")
flag.BoolVar(&printVersion, "version", false, "show version")
flag.Parse()

pass = true

// version
if printVersion {
log.Println("Rabbit TCP (https://github.com/ihciah/rabbit-tcp/)")
log.Printf("Version: %s.\n", Version)
pass = false
return
}

// mode
modeString = strings.ToLower(modeString)
if modeString == "c" || modeString == "client" {
mode = ClientMode
} else if modeString == "s" || modeString == "server" {
mode = ServerMode
} else {
log.Panicf("Unsupported mode %s.\n", modeString)
log.Printf("Unsupported mode %s.\n", modeString)
pass = false
return
}

if password == "" || password == DefaultPassword {
log.Panicln("Password must be changed instead of default password.")
// password
if password == "" {
log.Println("Password must be specified.")
pass = false
return
}
if password == DefaultPassword {
log.Println("Password must be changed instead of default password.")
pass = false
return
}

// listen, dest, tunnelN
if mode == ClientMode {
if listen == "" {
log.Panicln("Listen address must be specified in client mode.")
log.Println("Listen address must be specified in client mode.")
pass = false
}
if dest == "" {
log.Panicln("Destination address must be specified in client mode.")
log.Println("Destination address must be specified in client mode.")
pass = false
}
if tunnelN == 0 {
log.Panicln("Tunnel number must be positive.")
log.Println("Tunnel number must be positive.")
pass = false
}
}
return mode, password, addr, listen, dest, tunnelN, verbose
return
}

func main() {
mode, password, addr, listen, dest, tunnelN, verbose := parseFlags()
pass, mode, password, addr, listen, dest, tunnelN, verbose := parseFlags()
if !pass {
return
}
cipher, _ := tunnel.NewAEADCipher("CHACHA20-IETF-POLY1305", nil, password)
logger.LEVEL = verbose
if mode == ClientMode {
Expand Down

0 comments on commit 6a1c449

Please sign in to comment.