forked from bottlerocket-os/bottlerocket-ecs-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
90 lines (75 loc) · 2.62 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# SHELL is set as bash to use some bashisms.
SHELL = bash
BOTTLEROCKET_SDK_VERSION = v0.22.0
BOTTLEROCKET_SDK_ARCH = x86_64
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}
# IMAGE_NAME is the full name of the container being built
IMAGE_NAME = bottlerocket-ecs-updater:latest
# LICENSES_IMAGE is the name of the container image that has LICENSE files
# for distribution.
LICENSES_IMAGE = $(IMAGE_NAME)-licenses
SOURCEDIR=./updater
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
export GO111MODULE=on
export DOCKER_BUILDKIT=1
all: build
.PHONY: tidy
tidy:
cd updater && go mod tidy
.PHONY: build # builds updater
build: updater/bin/bottlerocket-ecs-updater
updater/bin/bottlerocket-ecs-updater: $(SOURCES) updater/go.mod updater/go.sum
GOARCH=$(UPDATER_TARGET_ARCH)
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: licenses
docker build \
--tag '$(IMAGE_NAME)' \
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
--build-arg GOARCH=$(UPDATER_TARGET_ARCH) \
--build-arg LICENSES_IMAGE=$(LICENSES_IMAGE) \
.
.PHONY: licenses
licenses:
docker build \
--tag '$(LICENSES_IMAGE)' \
--build-arg SDK_IMAGE=$(BUILDER_IMAGE) \
--build-arg GOLANG_IMAGE=$(BUILDER_IMAGE) \
--build-arg GOARCH=$(UPDATER_TARGET_ARCH) \
-f Dockerfile.licenses \
.
.PHONY: lint
lint: golang-lint cfn-lint
.PHONY: golang-lint
golang-lint:
cd updater; golangci-lint run
.PHONY: cfn-lint
cfn-lint:
cfn-lint ./stacks/bottlerocket-ecs-updater.yaml
cfn-lint ./integ/stacks/integ-shared.yaml
cfn-lint ./integ/stacks/cluster.yaml
# Check that the container has LICENSE files included for its dependencies.
.PHONY: check-licenses
check-licenses: CHECK_CONTAINER_NAME=check-licenses-bottlerocket-ecs-updater
check-licenses:
@echo "Running check: $@"
@-if docker inspect $(CHECK_CONTAINER_NAME) &>/dev/null; then\
docker rm $(CHECK_CONTAINER_NAME) &>/dev/null; \
fi
@docker create --name $(CHECK_CONTAINER_NAME) $(IMAGE_NAME) >/dev/null 2>&1
@echo "Checking if container image included dependencies' LICENSE files..."
@docker export $(CHECK_CONTAINER_NAME) | tar -tf - \
| grep usr/share/licenses/bottlerocket-ecs-updater/vendor \
| grep -q LICENSE || { \
echo "Container image is missing required LICENSE files (checked $(IMAGE_NAME))"; \
docker rm $(CHECK_CONTAINER_NAME) &>/dev/null; \
exit 1; \
}
@-docker rm $(CHECK_CONTAINER_NAME)
clean:
-rm -rf updater/bin