blob: b31eee3447fc026b5b88ae893ed310c1bcab7398 [file] [log] [blame]
# Copyright 2017 The LUCI Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This Makefile (GNU) controls the construction and deployment of the
# "luci-logdog" application. This is a common Makefile, and is expected to be
# imported by an implementation-specific Makefile. The implementation-specific
# Makefile must supply the following variables:
#
# - CLOUD_PROJECT: Name of the Google Cloud Project.
# - GKE_SERVICES_YAML: Path to the YAML file used by "gke.py" services.
#
# The Makefile may supply the following optional variables:
# - TAG: The AppEngine tag. If not specified, let "gae.py" choose a
# tag (default, important for production).
.PHONY: default
default: help
# Determine "luci-go" repository paths.
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
APP_DIR := $(dir $(mkfile_path))
LUCI_GO_DIR := $(abspath $(APP_DIR)/../../../..)
# VPATH determines the relative paths of Makefile targets. We need to set it
# here, since we're expecting to be invoked from a Makefile in a different
# directory. This allows our relative paths to be resolved by `make`.
VPATH := $(APP_DIR)
# If a tag was provided, add it to the "GAE_PY" args.
export LUCI_PY_USE_GCLOUD=1
GAE_PY_EXTRA_ARGS =
ifdef TAG
GAE_PY_EXTRA_ARGS := $(GAE_PY_EXTRA_ARGS) -t $(TAG)
endif
# Assert that all required variables are provided.
ifndef CLOUD_PROJECT
$(error Missing required variable: CLOUD_PROJECT)
endif
ifndef GKE_SERVICES_YAML
$(error Missing required variable: GKE_SERVICES_YAML)
endif
# Define services.
ALL_SERVICES = default logs services static
YAMLS = dispatch queue cron index
ALL_GKE_CLUSTERS = collector archivist
GAE_VERSION := $(shell \
cd $(APP_DIR) && \
gae.py version -A $(CLOUD_PROJECT) $(GAE_PY_EXTRA_ARGS))
# Define a literal space and comma, for substitution.
space :=
space +=
comma := ,
define HELP_BODY
Manage LogDog distributions.
Management targets:
web: Builds static web content into the 'static' module.
Service Targets for: $(subst $(space),$(comma),$(ALL_SERVICES))
upload: uploads all AppEngie
upload-SERVICE: uploads an instance of the service, but doesn't migrate.
switch: Switches all services over to the uploaded version.
Cluster Targets for: $(subst $(space),$(comma),$(ALL_GKE_CLUSTERS))
upload-CLUSTER: deploys an instance of the cluster to Kubernetes. Note that
additional "kubectl" commands will be required to verify correctness,
migrate traffic, and remove old instances.
switch-CLUSTER: switch active image over to the last uploaded image.
rollback-CLUSTER: rollback cluster to the last "stable" image.
promote-CLUSTER: promote last uploaded image to "stable".
status-CLUSTER: show status for the specified cluster.
Special Service Targets:
update-{$(subst $(space),$(comma),$(YAMLS))}
Explicitly update one of the configuration YAML files.
upload-static-dev: special command to upload an instance of the static
module named "dev". This can be whitelisted for OAuth for authenticated
testing.
endef
.PHONY: help
help:
$(info $(HELP_BODY))
YAML_PATHS = $(addprefix default/,$(addsuffix .yaml,$(YAMLS)))
.PHONY: yamls
yamls: default/app.yaml $(YAML_PATHS)
.PHONY: web
web:
-rm -rf $(APP_DIR)static/dist
$(LUCI_GO_DIR)/web/web.py build \
--build-dir $(APP_DIR)static \
logdog-app \
logdog-view \
rpcexplorer
# Default resources definition.
.PHONY: $(addsuffix -resources,$(ALL_SERVICES))
$(addsuffix -resources,$(ALL_SERVICES))::
# The "static" module requires additional resources.
static-resources:: web
##
# Per-module Build Rules
#
# upload-<module>: Uploads the module, but doesn't set it to be default.
##
.PHONY: $(addprefix upload-,$(ALL_SERVICES))
$(addprefix upload-,$(ALL_SERVICES)): upload-%: %-resources yamls
cd $(APP_DIR) && \
gae.py upload \
-A $(CLOUD_PROJECT) \
$(GAE_PY_EXTRA_ARGS) \
--force \
$*
.PHONY: upload
upload: $(addsuffix -resources,$(ALL_SERVICES))
cd $(APP_DIR) && \
gae.py upload \
-A $(CLOUD_PROJECT) \
$(GAE_PY_EXTRA_ARGS) \
--force \
$(ALL_SERVICES)
# "switch" switches all traffic over to the new set of instances.
#
# Ideally we'd "migrate', which is a gradual control flow. However, migration is
# not supported in Flex environment at the moment, so we have to do a hard
# "set-traffic".
#
# Ideal command is:
# $ gcloud app versions migrate
.PHONY: switch
switch:
cd $(APP_DIR) && \
gcloud \
--project $(CLOUD_PROJECT) \
app services set-traffic $(ALL_SERVICES) \
--splits=$(GAE_VERSION)=100
# This is a special make target to upload the static module named "dev". This
# version can be specifically whitelisted by the service account to enable
# authentication and test a production instance.
.PHONY: upload-static-dev
upload-static-dev: static-resources yamls
cd $(APP_DIR) && \
gcloud app deploy \
--project $(CLOUD_PROJECT) \
--version "dev" \
--quiet \
--no-promote \
static/module-static.yaml
$(addprefix update-,$(YAMLS)): update-%:
cd $(APP_DIR) && \
gcloud app deploy \
--project $(CLOUD_PROJECT) \
--quiet \
default/$*.yaml
##
# Per-GKE Cluster Build Rules
#
# upload-<cluster>: Uploads the GKE cluster.
##
.PHONY: $(addprefix upload-,$(ALL_GKE_CLUSTERS))
$(addprefix upload-,$(ALL_GKE_CLUSTERS)): upload-%:
cd $(APP_DIR) && \
gke.py \
-v \
-C $(GKE_SERVICES_YAML) \
upload \
-K $*
.PHONY: $(addprefix switch-,$(ALL_GKE_CLUSTERS))
$(addprefix switch-,$(ALL_GKE_CLUSTERS)): switch-%:
cd $(APP_DIR) && \
gke.py \
-v \
-C $(GKE_SERVICES_YAML) \
switch \
-K $*
.PHONY: $(addprefix rollback-,$(ALL_GKE_CLUSTERS))
$(addprefix rollback-,$(ALL_GKE_CLUSTERS)): rollback-%:
cd $(APP_DIR) && \
gke.py \
-v \
-C $(GKE_SERVICES_YAML) \
rollback \
-K $*
.PHONY: $(addprefix promote-,$(ALL_GKE_CLUSTERS))
$(addprefix promote-,$(ALL_GKE_CLUSTERS)): promote-%:
cd $(APP_DIR) && \
gke.py \
-v \
-C $(GKE_SERVICES_YAML) \
promote \
-K $*
.PHONY: $(addprefix status-,$(ALL_GKE_CLUSTERS))
$(addprefix status-,$(ALL_GKE_CLUSTERS)): status-%:
cd $(APP_DIR) && \
gke.py \
-v \
-C $(GKE_SERVICES_YAML) \
status \
-K $*