Skip to content

Commit

Permalink
Restructure Makefile
Browse files Browse the repository at this point in the history
This commit makes several changes to the Makefile
1. Define a default target via `all`
2. Track source files for the build so no rebuild is necessary when
   there are no source changes
3. Add a test target
4. Remove unnecessary dependency from the image target to the build
   target, as the image target performs its own rebuild inside Docker
  • Loading branch information
samuelkarp committed Apr 26, 2021
1 parent bcb7d3e commit e8979d1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@ UPDATER_TARGET_ARCH = amd64

# the docker image that will be used to compile go code
BUILDER_IMAGE = public.ecr.aws/bottlerocket/bottlerocket-sdk-${BOTTLEROCKET_SDK_ARCH}:${BOTTLEROCKET_SDK_VERSION}
SOURCEDIR=./updater
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
export GO111MODULE=on

.PHONY: fetch-dependency # downloads go.mod dependency
fetch-dependency:
cd updater && GO111MODULE=on go mod tidy
all: build

.PHONY: tidy
tidy:
cd updater && go mod tidy

.PHONY: build # builds updater
build: fetch-dependency
build: updater/bin/bottlerocket-ecs-updater
updater/bin/bottlerocket-ecs-updater: $(SOURCES) updater/go.mod updater/go.sum
GOARCH=$(UPDATER_TARGET_ARCH)
cd updater && GO111MODULE=on go build -v -o bin/bottlerocket-ecs-updater .
cd updater && go build -v -o bin/bottlerocket-ecs-updater .

.PHONY: test
test:
cd updater && go test -v ./...


.PHONY: image # creates a docker image with the updater binary
image: build
image:
DOCKER_BUILDKIT=1 \
docker build \
-t bottlerocket-ecs-updater:latest \
--build-arg BUILDER_IMAGE=${BUILDER_IMAGE} \
--build-arg GOARCH=${UPDATER_TARGET_ARCH} \
"${PWD}/updater"

clean:
-rm -rf updater/bin

0 comments on commit e8979d1

Please sign in to comment.