forked from Azure/application-gateway-kubernetes-ingress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
113 lines (99 loc) · 4.22 KB
/
CMakeLists.txt
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
cmake_minimum_required(VERSION 2.8.9)
project(application-gateway-kubernetes-ingress)
string(TOLOWER ${CMAKE_PROJECT_NAME} project_name_lowercase)
set(package_name "github.com/Azure/application-gateway-kubernetes-ingress")
set(devenv_image_name "${project_name_lowercase}-dev")
set(devenv_workpath "/gopath/src/${package_name}")
set(deployment_image_name ${project_name_lowercase}
CACHE STRING "string <deployment_image_name> for docker tag/push <prefix>/<deployment_image_name>")
set(deployment_push_prefix ""
CACHE STRING "string <prefix> for docker tag/push <prefix>/<deployment_image_name>")
set(deployment_image_version "latest"
CACHE STRING "version of the deployment image")
message("[image name] ${deployment_push_prefix}/${deployment_image_name}:${deployment_image_version}")
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/vendor/vendor.stamp
COMMAND docker run --rm --security-opt seccomp:unconfined -t
-v ${CMAKE_SOURCE_DIR}:${devenv_workpath}
-w ${devenv_workpath}
--name ${devenv_image_name} ${devenv_image_name}
/bin/bash -c './scripts/vendor.sh'
COMMAND cmake -E touch ${CMAKE_SOURCE_DIR}/vendor/vendor.stamp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS go.mod devenv
COMMENT "running go mod vendor"
)
# Go vendoring
add_custom_target(
vendor
DEPENDS ${CMAKE_SOURCE_DIR}/vendor/vendor.stamp
)
# Docker image for build environment
add_custom_target(devenv
COMMAND docker build -t ${devenv_image_name}
-f dockerfiles/devenv.Dockerfile ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "building devenv docker image"
)
add_custom_command(
OUTPUT .always_rebuild
COMMAND cmake -E echo
)
# Custom command to generate the GoLang binaries
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/bin/appgw-ingress
COMMAND docker run --rm --security-opt seccomp:unconfined -t
-v ${CMAKE_SOURCE_DIR}:${devenv_workpath}
-w ${devenv_workpath}
--name ${devenv_image_name}-devenv ${devenv_image_name}
/bin/bash -c './scripts/build.sh'
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS devenv .always_rebuild
COMMENT "compiling project in devenv"
)
# Generate a new helm release.
add_custom_target(helm-release
COMMAND docker run --rm --security-opt seccomp:unconfined -t
-v ${CMAKE_SOURCE_DIR}:${devenv_workpath}
-w ${devenv_workpath}/helm
--name ${devenv_image_name}-devenv ${devenv_image_name}
/bin/bash -c './release.sh'
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# Build target for building the GoLang binaries
add_custom_target(
appgw-ingress
DEPENDS ${CMAKE_SOURCE_DIR}/bin/appgw-ingress
)
# Test target for all Go tests
add_custom_target(go-tests
COMMAND docker run --rm --security-opt seccomp:unconfined -t
-v ${CMAKE_SOURCE_DIR}:${devenv_workpath}
-w ${devenv_workpath}
--name ${devenv_image_name}-devenv ${devenv_image_name}
go test -timeout 80s -v -coverprofile=coverage.txt -tags unittest -covermode count ./...
DEPENDS appgw-ingress
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# Target for building a docker image for deploying on a Kubernetes cluster.
add_custom_target(dockerize
COMMAND docker build -t ${deployment_image_name}:${deployment_image_version}
-f dockerfiles/deploy.Dockerfile ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS go-tests
COMMENT "building deployment docker image"
)
# Target for pushing the docker image of the Kuberentes pod to a container registry.
add_custom_target(dockerpush
COMMAND docker tag ${deployment_image_name}:${deployment_image_version} ${deployment_push_prefix}/${deployment_image_name}:${deployment_image_version}
COMMAND docker tag ${deployment_image_name}:${deployment_image_version} ${deployment_push_prefix}/${deployment_image_name}:latest
COMMAND docker push ${deployment_push_prefix}/${deployment_image_name}:${deployment_image_version}
COMMAND docker push ${deployment_push_prefix}/${deployment_image_name}:latest
DEPENDS dockerize
COMMENT "pushing to container registry"
)
# Target to capture ALL semantics.
add_custom_target(appgw-ingress-all
ALL
DEPENDS appgw-ingress go-tests
)