Skip to content

Commit

Permalink
Package as a Docker image (#12)
Browse files Browse the repository at this point in the history
* Package as a Docker image

* Addressed Viswa's comment
  • Loading branch information
kreamkorokke authored Nov 18, 2020
1 parent e814a88 commit cfa64e0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Setting files of JetBrains IDE
.idea
/.idea

# Empty file touched by `make deps`
/deps

# Project specifc $GOBIN
/.gobin

# Binary
/image/network-crawler
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ifeq ($(UNAME_S),Darwin)
HOST_OS := darwin
endif

TAG := $(shell ./get-tag)

GOBIN := $(CURDIR)/.gobin
PATH := $(GOBIN):$(PATH)
Expand All @@ -39,7 +40,7 @@ $(STATICCHECK_BIN): deps
@go install honnef.co/go/tools/cmd/staticcheck

###########
## Lint ##
## Lint ##
###########

.PHONY: golangci-lint
Expand Down Expand Up @@ -69,3 +70,34 @@ lint: golangci-lint staticcheck
test:
go test ./...


###########
## Build ##
###########

.PHONY: tag
tag:
@echo $(TAG)

.PHONY: build
build:
@echo "+ $@"
@mkdir -p "$(GOBIN)"
@CGO_ENABLED=0 GOOS=linux \
go build -a -ldflags "-s -w" \
-o $(GOBIN)/linux/network-crawler ./cmd/network-crawler
@CGO_ENABLED=0 GOOS=darwin \
go build -a -ldflags "-s -w" \
-o $(GOBIN)/darwin/network-crawler ./cmd/network-crawler
@cp $(GOBIN)/$(HOST_OS)/network-crawler $(GOBIN)/network-crawler

.PHONY: image
image: build
@echo "+ $@"
@cp $(GOBIN)/linux/network-crawler ./image
@docker build -t us.gcr.io/stackrox-hub/network-crawler:$(TAG) image

.PHONY: push
push: image
@echo "+ $@"
@docker push us.gcr.io/stackrox-hub/network-crawler:$(TAG) | cat
7 changes: 7 additions & 0 deletions get-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [ -n "${CIRCLE_TAG}" ]; then
echo "${CIRCLE_TAG}"
else
git describe --long --tags --abbrev=10 --dirty
fi
8 changes: 8 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3.12

# Needed by network-crawler script
RUN apk add curl

COPY network-crawler /usr/bin/network-crawler

ENTRYPOINT ["/usr/bin/network-crawler"]
2 changes: 1 addition & 1 deletion pkg/crawlers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (c *azureNetworkCrawler) redirectToJSONURL(rawURL string) (string, error) {
// Trim trailing newline char
"tr -d '\n'",
rawURL)
out, err := exec.Command("bash", "-c", cmd).Output()
out, err := exec.Command("/bin/sh", "-c", cmd).Output()
if err != nil {
errors.Wrapf(err, "failed to redirect to JSON URL while trying to crawl Azure with URL: %s", rawURL)
return "", err
Expand Down

0 comments on commit cfa64e0

Please sign in to comment.