Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit b577b4b

Browse files
committed
Set version number
1 parent e801f47 commit b577b4b

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
bin/
1515
output/
16+
17+
GITCOMMIT_SHA

Diff for: Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
FROM golang:1.11 AS builder
22

3-
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
4-
53
WORKDIR /go/src/github.com/awslabs/img2lambda
64

75
COPY . ./
8-
RUN make
6+
RUN make install-deps && make
97

108
FROM busybox:glibc
119
COPY --from=builder /go/src/github.com/awslabs/img2lambda/bin/local/img2lambda /bin/img2lambda

Diff for: Makefile

+19-15
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ LINUX_BINARY := bin/linux-amd64/img2lambda
99
DARWIN_BINARY := bin/darwin-amd64/img2lambda
1010
WINDOWS_BINARY := bin/windows-amd64/img2lambda.exe
1111
LOCAL_PATH := $(ROOT)/scripts:${PATH}
12-
DEP_RELEASE_TAG := v0.4.1
12+
VERSION := $(shell cat VERSION)
13+
GITFILES := $(shell find ".git/")
1314

1415
.PHONY: build
1516
build: $(LOCAL_BINARY)
1617

17-
$(LOCAL_BINARY): $(SOURCES)
18-
./scripts/build_binary.sh ./bin/local
18+
$(LOCAL_BINARY): $(SOURCES) GITCOMMIT_SHA
19+
./scripts/build_binary.sh ./bin/local $(VERSION) $(shell cat GITCOMMIT_SHA)
1920
@echo "Built img2lambda"
2021

2122
.PHONY: test
@@ -26,9 +27,8 @@ test:
2627
generate: $(SOURCES)
2728
PATH=$(LOCAL_PATH) go generate ./...
2829

29-
.PHONY: generate-deps
30-
generate-deps:
31-
DEP_RELEASE_TAG=$DEP_RELEASE_TAG
30+
.PHONY: install-deps
31+
install-deps:
3232
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
3333

3434
.PHONY: windows-build
@@ -57,25 +57,29 @@ docker-test:
5757
--env IMG_TOOL_RELEASE=$(IMG_TOOL_RELEASE) \
5858
golang:1.11 make test
5959

60-
.PHONY: supported-platforms
61-
supported-platforms: $(LINUX_BINARY) $(DARWIN_BINARY) $(WINDOWS_BINARY)
60+
.PHONY: all-platforms
61+
all-platforms: $(LINUX_BINARY) $(DARWIN_BINARY) $(WINDOWS_BINARY)
6262

63-
$(WINDOWS_BINARY): $(SOURCES)
63+
$(WINDOWS_BINARY): $(SOURCES) GITCOMMIT_SHA
6464
@mkdir -p ./bin/windows-amd64
65-
TARGET_GOOS=windows GOARCH=amd64 ./scripts/build_binary.sh ./bin/windows-amd64
65+
TARGET_GOOS=windows GOARCH=amd64 ./scripts/build_binary.sh ./bin/windows-amd64 $(VERSION) $(shell cat GITCOMMIT_SHA)
6666
mv ./bin/windows-amd64/img2lambda ./bin/windows-amd64/img2lambda.exe
6767
@echo "Built img2lambda.exe for windows"
6868

69-
$(LINUX_BINARY): $(SOURCES)
69+
$(LINUX_BINARY): $(SOURCES) GITCOMMIT_SHA
7070
@mkdir -p ./bin/linux-amd64
71-
TARGET_GOOS=linux GOARCH=amd64 ./scripts/build_binary.sh ./bin/linux-amd64
71+
TARGET_GOOS=linux GOARCH=amd64 ./scripts/build_binary.sh ./bin/linux-amd64 $(VERSION) $(shell cat GITCOMMIT_SHA)
7272
@echo "Built img2lambda for linux"
7373

74-
$(DARWIN_BINARY): $(SOURCES)
74+
$(DARWIN_BINARY): $(SOURCES) GITCOMMIT_SHA
7575
@mkdir -p ./bin/darwin-amd64
76-
TARGET_GOOS=darwin GOARCH=amd64 ./scripts/build_binary.sh ./bin/darwin-amd64
76+
TARGET_GOOS=darwin GOARCH=amd64 ./scripts/build_binary.sh ./bin/darwin-amd64 $(VERSION) $(shell cat GITCOMMIT_SHA)
7777
@echo "Built img2lambda for darwin"
7878

79+
GITCOMMIT_SHA: $(GITFILES)
80+
git rev-parse --short=7 HEAD > GITCOMMIT_SHA
81+
7982
.PHONY: clean
8083
clean:
81-
rm -rf ./bin/ ||:
84+
- rm -rf ./bin
85+
- rm -f GITCOMMIT_SHA

Diff for: VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

Diff for: main.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func createApp() (*cli.App, *cmdOptions) {
2323
app := cli.NewApp()
2424
app.EnableBashCompletion = true
2525
app.Name = "img2lambda"
26+
app.Version = VersionString()
2627
app.Usage = "Repackages a container image into AWS Lambda layers and publishes them to Lambda"
2728
app.Action = func(c *cli.Context) error {
2829
validateCliOptions(&opts, c)

Diff for: scripts/build_binary.sh

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
55
cd "${ROOT}"
66

7-
# Builds the ecs-cli binary from source in the specified destination paths.
7+
# Builds the binary from source in the specified destination paths.
88
mkdir -p $1
99

1010
cd "${ROOT}"
1111

12-
GOOS=$TARGET_GOOS go build -tags="containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_overlay exclude_graphdriver_btrfs containers_image_openpgp" -o $1/img2lambda .
12+
BUILDTAGS="containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_overlay exclude_graphdriver_btrfs containers_image_openpgp"
13+
14+
VERSION_LDFLAGS=""
15+
if [[ -n "${2}" ]]; then
16+
VERSION_LDFLAGS="-X main.Version=${2}"
17+
fi
18+
19+
if [[ -n "${3}" ]]; then
20+
VERSION_LDFLAGS="$VERSION_LDFLAGS -X main.GitCommitSHA=${3}"
21+
fi
22+
23+
GOOS=$TARGET_GOOS go build -a -tags="${BUILDTAGS}" -ldflags "-s ${VERSION_LDFLAGS}" -o $1/img2lambda .

Diff for: version.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
// Version indicates which version of the binary is running.
4+
var Version = "master"
5+
6+
// GitCommitSHA indicates which git shorthash the binary was built off of
7+
var GitCommitSHA string
8+
9+
func VersionString() string {
10+
return Version + " (" + GitCommitSHA + ")"
11+
}

0 commit comments

Comments
 (0)