-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cloud deployment with local agent (#2143)
Cloud deployment with local agent (#2143)
- Loading branch information
1 parent
33a7172
commit 06a8da1
Showing
23 changed files
with
1,098 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.auto.tfvars |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
MAKEFILE_PATH:=$(abspath $(lastword ${MAKEFILE_LIST})) | ||
MAKEFILE_DIR:=$(dir ${MAKEFILE_PATH}) | ||
REPO_ROOT:=$(abspath ${MAKEFILE_DIR}/../../../) | ||
SNAPSHOT_SUFFIX:=-SNAPSHOT | ||
ifeq (${SNAPSHOT}, false) | ||
SNAPSHOT_SUFFIX:="" | ||
endif | ||
ifeq (${SNAPSHOT}, 0) | ||
SNAPSHOT_SUFFIX:="" | ||
endif | ||
VERSION:=$(shell grep defaultBeatVersion ${REPO_ROOT}/version/version.go | cut -d\" -f2)${SNAPSHOT_SUFFIX} | ||
|
||
export DOCKER_BUILDKIT=1 | ||
|
||
ELASTIC_AGENT_DOCKER_IMAGE=docker.elastic.co/cloud-release/elastic-agent-cloud | ||
ELASTICSEARCH_DOCKER_IMAGE=docker.elastic.co/cloud-release/elasticsearch-cloud-ess | ||
KIBANA_DOCKER_IMAGE=docker.elastic.co/cloud-release/kibana-cloud | ||
|
||
CI_ELASTIC_AGENT_DOCKER_IMAGE=docker.elastic.co/observability-ci/elastic-agent | ||
CI_KIBANA_DOCKER_IMAGE=docker.elastic.co/observability-ci/kibana | ||
|
||
# Tag custom images with the username and current timestamp. | ||
# The timestamp must be included to force images to be pulled. | ||
USER_NAME?=${USER} | ||
CUSTOM_IMAGE_TAG:=${VERSION}-${USER_NAME}-$(shell date +%s) | ||
|
||
USER_ELASTIC_AGENT_DOCKER_IMAGE=docker.elastic.co/observability-ci/${USER_NAME}-elastic-agent | ||
USER_KIBANA_DOCKER_IMAGE=docker.elastic.co/observability-ci/${USER_NAME}-kibana | ||
|
||
.DEFAULT_GOAL := docker_image.auto.tfvars | ||
|
||
############################################################################## | ||
# Target for creating a .tfvars file, defining the custom Docker images to | ||
# use in the deployment. | ||
############################################################################## | ||
|
||
docker_image.auto.tfvars: kibana_docker_image elastic_agent_docker_image | ||
@echo 'docker_image_override={"elasticsearch":"${ELASTICSEARCH_DOCKER_IMAGE}","kibana":"${CI_KIBANA_DOCKER_IMAGE}","agent":"${CI_ELASTIC_AGENT_DOCKER_IMAGE}"}' > $@ | ||
@echo 'docker_image_tag_override={"elasticsearch":"${VERSION}","kibana":"${VERSION}","agent":"${CUSTOM_IMAGE_TAG}"}' >> $@ | ||
|
||
############################################################################## | ||
# Terraform shortcut rules. | ||
############################################################################## | ||
|
||
.PHONY: apply | ||
apply: | ||
@terraform apply -auto-approve | ||
|
||
|
||
.PHONY: snap | ||
snap: | ||
@echo ${VERSION} | ||
|
||
.PHONY: destroy | ||
destroy: | ||
@terraform destroy -auto-approve | ||
|
||
|
||
.PHONY: deploy_local | ||
deploy_local: build_elastic_agent_docker_image push_elastic_agent_docker_image | ||
@echo 'docker_image_override={"elasticsearch":"${ELASTICSEARCH_DOCKER_IMAGE}","kibana":"${KIBANA_DOCKER_IMAGE}","agent":"${CI_ELASTIC_AGENT_DOCKER_IMAGE}"}' > docker_image.auto.tfvars | ||
@echo 'docker_image_tag_override={"elasticsearch":"${VERSION}","kibana":"${VERSION}","agent":"${CUSTOM_IMAGE_TAG}"}' >> docker_image.auto.tfvars | ||
@terraform apply -auto-approve | ||
|
||
############################################################################## | ||
# Targets for building and pushing custom Kibana and Elastic Agent images. | ||
############################################################################## | ||
|
||
# kibana_docker_image builds the Cloud Kibana image. | ||
# The image will be based off the | ||
# stack version defined in ${REPO_ROOT}/.env, unless overridden. | ||
.PHONY: build_kibana_docker_image | ||
kibana_docker_image: build_kibana_docker_image | ||
docker push ${CI_KIBANA_DOCKER_IMAGE}:${CUSTOM_IMAGE_TAG} | ||
build_kibana_docker_image: | ||
$(MAKE) -C ${REPO_ROOT} build-package | ||
docker build -t ${CI_KIBANA_DOCKER_IMAGE}:${CUSTOM_IMAGE_TAG} \ | ||
-f "${REPO_ROOT}/testing/docker/kibana/Dockerfile-apmpackage" \ | ||
--build-arg KIBANA_IMAGE=${KIBANA_DOCKER_IMAGE}:${IMAGE_TAG} \ | ||
--platform linux/amd64 \ | ||
"${REPO_ROOT}/build/packages" | ||
|
||
# build_elastic_agent_docker_image builds the Cloud Elastic Agent image. | ||
# The image will be based | ||
# off the version defined in version.go, | ||
# CUSTOM_IMAGE_TAG is appended to the version resulting in e.g: | ||
# 8.7.0-SNAPSHOT-doe-1673961915 | ||
# unless overridden. | ||
.PHONY: build_elastic_agent_docker_image | ||
push_elastic_agent_docker_image: | ||
cd ${REPO_ROOT}; CI_ELASTIC_AGENT_DOCKER_IMAGE=${CI_ELASTIC_AGENT_DOCKER_IMAGE} CUSTOM_IMAGE_TAG=${CUSTOM_IMAGE_TAG} mage cloud:push | ||
build_elastic_agent_docker_image: | ||
cd ${REPO_ROOT}; DOCKER_BUILDKIT=0 COMPOSE_DOCKER_CLI_BUILD=0 DOCKER_DEFAULT_PLATFORM=linux/amd64 mage cloud:image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Cloud-first testing | ||
|
||
Elastic employees can create an Elastic Cloud deployment with a locally | ||
built Elastic Agent, by pushing images to an internal Docker repository. The images will be | ||
based on the SNAPSHOT images with the version defined in `version/version.go`. | ||
|
||
Prerequisite to running following commands is having `terraform` installed and running `terraform init` from within `testing/environments/cloud`. | ||
|
||
Running a shorthand `make deploy_local` in `testing/environments/cloud` will build Agent, tag the docker image correctly, push it to the repository and deploy to Elastic Cloud. | ||
|
||
For more advanced scenarios: | ||
Running `make build_elastic_agent_docker_image` in `testing/environments/cloud` will build and push the images. | ||
Running `make push_elastic_agent_docker_image` in `testing/environments/cloud` will publish built docker image to CI docker repository. | ||
|
||
Once docker images are published you can run `EC_API_KEY=your_api_key make apply` from `testing/environments/cloud` directory to deploy them to Elastic Cloud. | ||
To get `EC_API_KEY` follow [this guide](https://www.elastic.co/guide/en/cloud/current/ec-api-authentication.html) | ||
|
||
The custom images are tagged with the current version, commit and timestamp. The | ||
timestamp is included to force a new Docker image to be used, which enables pushing new | ||
binaries without recreating the deployment. | ||
|
||
To specify custom images create your `docker_image.auto.tfvars` file similar to `docker_image.auto.tfvars.sample`. | ||
|
||
You can also use `mage cloud:image` and `mage cloud:push` respectively from repo root directory. | ||
To deploy your changes use `make apply` (from `testing/environments/cloud`) with `EC_API_KEY` instead of `make deploy_local` described above. | ||
|
||
SNAPSHOT images are used by default. To use non-snapshot image specify `SNAPSHOT=false` explicitly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
docker_image_override={"elasticsearch":"docker.elastic.co/cloud-release/elasticsearch-cloud-ess","kibana":"docker.elastic.co/cloud-release/kibana-cloud","agent":"docker.elastic.co/observability-ci/elastic-agent"} | ||
docker_image_tag_override={"elasticsearch":"8.6.0-f96862e0-SNAPSHOT","kibana":"8.6.0-f96862e0-SNAPSHOT","agent":"mysampletag"} |
Oops, something went wrong.