Skip to content

Commit a008433

Browse files
committed
Add get helper script and include commit info in binaries
1 parent cb02a32 commit a008433

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**/node_modules/
22
build/
33
faas-cli
4-
faas-cli-macos
4+
faas-cli-darwin
5+
faas-cli-armhf
6+
57
*.jpg
68
*.pyc

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /go/src/github.com/alexellis/faas-cli
44
COPY . .
55
RUN go get -d -v
66

7-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o faas-cli .
7+
RUN CGO_ENABLED=0 GOOS=linux go build --ldflags "-X main.GitCommit=${GIT_COMMIT}" -a -installsuffix cgo -o faas-cli .
88

99
FROM alpine:latest
1010
RUN apk --no-cache add ca-certificates

Dockerfile.redist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM golang:1.7.5
2+
3+
WORKDIR /go/src/github.com/alexellis/faas-cli
4+
COPY . .
5+
RUN go get -d -v
6+
7+
RUN GIT_COMMIT=$(git rev-list -1 HEAD) \
8+
&& GOARCH=arm GOARM=6 CGO_ENABLED=0 GOOS=linux go build --ldflags "-X main.GitCommit=${GIT_COMMIT}" -a -installsuffix cgo -o faas-cli-armhf . \
9+
&& CGO_ENABLED=0 GOOS=darwin go build --ldflags "-X main.GitCommit=${GIT_COMMIT}" -a -installsuffix cgo -o faas-cli-darwin \
10+
&& CGO_ENABLED=0 GOOS=linux go build --ldflags "-X main.GitCommit=${GIT_COMMIT}" -a -installsuffix cgo -o faas-cli .
11+
12+
FROM alpine:latest
13+
RUN apk --no-cache add ca-certificates
14+
15+
WORKDIR /root/
16+
17+
COPY --from=0 /go/src/github.com/alexellis/faas-cli/faas-cli .
18+
COPY --from=0 /go/src/github.com/alexellis/faas-cli/faas-cli-darwin .
19+
COPY --from=0 /go/src/github.com/alexellis/faas-cli/faas-cli-armhf .
20+
21+
CMD ["./faas"]

app.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
const providerName = "faas"
2929
const defaultNetwork = "func_functions"
30+
var GitCommit string
3031

3132
func main() {
3233
// var handler string
@@ -42,6 +43,7 @@ func main() {
4243
var nocache bool
4344
var yamlFile string
4445
var yamlFileShort string
46+
var version bool
4547

4648
flag.StringVar(&handler, "handler", "", "handler for function, i.e. handler.js")
4749
flag.StringVar(&image, "image", "", "Docker image name to build")
@@ -55,9 +57,15 @@ func main() {
5557

5658
flag.StringVar(&yamlFile, "yaml", "", "use a yaml file for a set of functions")
5759
flag.StringVar(&yamlFileShort, "f", "", "use a yaml file for a set of functions (same as -yaml)")
60+
flag.BoolVar(&version, "version", false, "show version and quit")
5861

5962
flag.Parse()
6063

64+
if version {
65+
fmt.Printf("Git Commit: %s\n", GitCommit)
66+
return
67+
}
68+
6169
// support short-argument -f
6270
if len(yamlFile) == 0 && len(yamlFileShort) > 0 {
6371
yamlFile = yamlFileShort

get.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
version=0.3
2+
3+
hasCli() {
4+
has=$(which faas-cli)
5+
6+
if [ "$?" = "0" ]; then
7+
echo "You already have the faas-cli!"
8+
export n=1
9+
echo "Overwriting in $n seconds.. Press Control+C to cancel."
10+
sleep $n
11+
fi
12+
13+
hasCurl=$(which curl)
14+
if [ "$?" = "1" ]; then
15+
echo "You need curl to use this script."
16+
exit 1
17+
fi
18+
}
19+
20+
getPackage() {
21+
22+
uname=$(uname)
23+
24+
suffix=""
25+
case $uname in
26+
"Darwin")
27+
suffix="-darwin"
28+
;;
29+
"Linux")
30+
arch=$(uname -m)
31+
echo $arch
32+
case $arch in
33+
"armv6l" | "armv7l")
34+
suffix="-armhf"
35+
;;
36+
esac
37+
;;
38+
esac
39+
40+
if [ -e /tmp/faas-cli ]; then
41+
rm /tmp/faas-cli
42+
fi
43+
44+
url=https://github.com/alexellis/faas-cli/releases/download/$version/faas-cli$suffix
45+
echo "Getting package $url"
46+
47+
curl -sSL $url > /tmp/faas-cli
48+
49+
if [ "$?" = "0" ]; then
50+
echo "Attemping to move faas-cli to /usr/local/bin"
51+
chmod +x /tmp/faas-cli
52+
cp /tmp/faas-cli /usr/local/bin/
53+
if [ "$?" = "0" ]; then
54+
echo "New version of faas-cli installed to /usr/local/bin"
55+
fi
56+
fi
57+
}
58+
59+
hasCli
60+
getPackage

0 commit comments

Comments
 (0)