-
Notifications
You must be signed in to change notification settings - Fork 129
Add test package with docker service deployers using terraform too #2670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2cd9a67
Add test package with docker and terraform
mrodm 7155d5c
Update system testing docs
mrodm aaa1c9e
Remove some environment variables in test package example
mrodm 191b9c4
Update section about test package example
mrodm 533e11b
Merge upstream/main into example-several-service-deployers
mrodm 3a4648b
Rephrase paragraph from test package example section
mrodm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
...rallel/nginx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/Dockerfile
This file contains hidden or 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,6 @@ | ||
| ARG SERVICE_VERSION=${SERVICE_VERSION:-1.19.5} | ||
| FROM nginx:${SERVICE_VERSION} | ||
| RUN sed -i "/jessie-updates/d" /etc/apt/sources.list | ||
| RUN apt-get update && apt-get install -y curl | ||
| HEALTHCHECK --interval=1s --retries=90 CMD curl -f http://localhost/server-status | ||
| COPY ./nginx.conf /etc/nginx/ |
26 changes: 26 additions & 0 deletions
26
...nx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/Dockerfile.terraform
This file contains hidden or 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,26 @@ | ||
| FROM --platform=linux/amd64 ubuntu:24.04 | ||
| ENV TERRAFORM_VERSION=1.9.6 | ||
|
|
||
| # Based on this Dockerfile: | ||
| # https://github.com/elastic/elastic-package/blob/d8e4300715af43b3b792d25960d75c3382948dcd/internal/servicedeployer/_static/Dockerfile.terraform_deployer | ||
| # This dockerfile just installs terraform and sets up the environment to run terraform commands. | ||
|
|
||
| RUN apt-get -qq update \ | ||
| && apt-get install -yq curl apt-transport-https ca-certificates gnupg \ | ||
| && apt-get clean | ||
|
|
||
| RUN curl -fsSL https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg \ | ||
| && echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com noble main" | tee /etc/apt/sources.list.d/hashicorp.list \ | ||
| && apt-get update -qq \ | ||
| && apt-get install -yq terraform=${TERRAFORM_VERSION}-1 \ | ||
| && apt-get clean | ||
|
|
||
| HEALTHCHECK --timeout=3s CMD sh -c "[ -f /tmp/tf-applied ]" | ||
|
|
||
| ENV TF_IN_AUTOMATION=true | ||
| ENV TF_CLI_ARGS="-no-color" | ||
| ADD terraform.run.sh /run.sh | ||
| RUN chmod +x /run.sh | ||
| WORKDIR /workspace | ||
|
|
||
| ENTRYPOINT exec /run.sh |
29 changes: 29 additions & 0 deletions
29
...ginx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/docker-compose.yml
This file contains hidden or 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,29 @@ | ||
| version: '2.3' | ||
| services: | ||
| nginx: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| ports: | ||
| - 80 | ||
| volumes: | ||
| - ${SERVICE_LOGS_DIR}:/var/log/nginx | ||
| depends_on: | ||
| terraform: | ||
| condition: service_healthy | ||
| terraform: | ||
| tty: true | ||
| stop_grace_period: 5m | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile.terraform | ||
| environment: | ||
| - TF_VAR_TEST_RUN_ID=${TEST_RUN_ID:-detached} | ||
| - TF_VAR_CREATED_DATE=${CREATED_DATE:-unknown} | ||
| - TF_VAR_BRANCH=${BRANCH_NAME_LOWER_CASE:-unknown} | ||
| - TF_VAR_BUILD_ID=${BUILD_ID:-unknown} | ||
| - TF_VAR_ENVIRONMENT=${ENVIRONMENT:-unknown} | ||
| - TF_VAR_REPO=${REPO:-unknown} | ||
| volumes: | ||
| - ./tf/:/stage/ | ||
| - ${SERVICE_LOGS_DIR}:/tmp/service_logs/ |
33 changes: 33 additions & 0 deletions
33
...rallel/nginx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/nginx.conf
This file contains hidden or 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,33 @@ | ||
| user nginx; | ||
| worker_processes 1; | ||
|
|
||
| error_log /dev/stderr warn; | ||
| pid /var/run/nginx.pid; | ||
|
|
||
|
|
||
| events { | ||
| worker_connections 1024; | ||
| } | ||
|
|
||
|
|
||
| http { | ||
| include /etc/nginx/mime.types; | ||
| default_type application/octet-stream; | ||
|
|
||
| log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
| '$status $body_bytes_sent "$http_referer" ' | ||
| '"$http_user_agent" "$http_x_forwarded_for"'; | ||
| access_log /var/log/nginx/access.log main; | ||
|
|
||
| server { | ||
| listen [::]:80; | ||
| listen 80; | ||
| server_name localhost; | ||
|
|
||
| location /server-status { | ||
| stub_status on; | ||
| } | ||
| } | ||
|
|
||
| include /etc/nginx/conf.d/*; | ||
| } |
33 changes: 33 additions & 0 deletions
33
.../nginx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/terraform.run.sh
This file contains hidden or 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,33 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euxo pipefail | ||
|
|
||
| # Terraform code may rely on content from other files than .tf files (es json, zip, html, text), so we copy all the content over | ||
| # See more: https://github.com/elastic/elastic-package/pull/603 | ||
| # NOTE: must copy hidden files too (supported by "/.") | ||
| # See more: https://github.com/elastic/package-spec/issues/269 | ||
| cp -r /stage/. /workspace | ||
|
|
||
| cleanup() { | ||
| r=$? | ||
|
|
||
| set -x | ||
| terraform destroy -auto-approve | ||
|
|
||
| exit $r | ||
| } | ||
| trap cleanup EXIT INT TERM | ||
|
|
||
| terraform init | ||
| terraform plan | ||
| terraform apply -auto-approve | ||
|
|
||
| mkdir -p /output | ||
| terraform output -json > /output/tfOutputValues.json | ||
|
|
||
| touch /tmp/tf-applied # This file is used as indicator (healthcheck) that the service is UP, and so it must be placed as the last statement in the script | ||
|
|
||
| echo "Terraform definitions applied." | ||
|
|
||
| set +x | ||
| while true; do sleep 1; done # wait for ctrl-c |
21 changes: 21 additions & 0 deletions
21
...nx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/tf/files/example.log
This file contains hidden or 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,21 @@ | ||
| ::1 - - [03/Jun/2025:14:41:33 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:34 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:35 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:36 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:37 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:38 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:39 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:40 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:41 +0000] "GET /server-status-tf HTTP/1.1" 200 97 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:42 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:43 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:45 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:46 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:47 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:48 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:49 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:50 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:51 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:52 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:53 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" | ||
| ::1 - - [03/Jun/2025:14:41:54 +0000] "GET /server-status-tf HTTP/1.1" 200 100 "-" "curl/7.64.0" "-" |
37 changes: 37 additions & 0 deletions
37
...rallel/nginx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/tf/main.tf
This file contains hidden or 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,37 @@ | ||
| # Remember to set default tags in case the provider allows for that. | ||
| # Example for the "aws" provider | ||
| # provider "aws" { | ||
| # region = "us-east-1" | ||
| # default_tags { | ||
| # tags = { | ||
| # environment = var.ENVIRONMENT | ||
| # repo = var.REPO | ||
| # branch = var.BRANCH | ||
| # build = var.BUILD_ID | ||
| # created_date = var.CREATED_DATE | ||
| # } | ||
| # } | ||
| # } | ||
|
|
||
| resource "local_file" "log" { | ||
| source = "./files/example.log" | ||
| filename = "/tmp/service_logs/file.log" | ||
| file_permission = "0777" | ||
| } | ||
|
|
||
| locals { | ||
| items ={ | ||
| environment = "${var.ENVIRONMENT}" | ||
| repo = "${var.REPO}" | ||
| branch = "${var.BRANCH}" | ||
| build = "${var.BUILD_ID}" | ||
| created_date = "${var.CREATED_DATE}" | ||
| test_run_id = "${var.TEST_RUN_ID}" | ||
| } | ||
| } | ||
|
|
||
| resource "local_file" "log_variables" { | ||
| content = format("%s\n", jsonencode(local.items)) | ||
| filename = "/tmp/service_logs/file_vars.log" | ||
| file_permission = "0777" | ||
| } |
26 changes: 26 additions & 0 deletions
26
...l/nginx_multiple_services/data_stream/access_docker_tf/_dev/deploy/docker/tf/variables.tf
This file contains hidden or 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,26 @@ | ||
| variable "BRANCH" { | ||
| description = "Branch name or pull request for tagging purposes" | ||
| default = "unknown-branch" | ||
| } | ||
|
|
||
| variable "BUILD_ID" { | ||
| description = "Build ID in the CI for tagging purposes" | ||
| default = "unknown-build" | ||
| } | ||
|
|
||
| variable "CREATED_DATE" { | ||
| description = "Creation date in epoch time for tagging purposes" | ||
| default = "unknown-date" | ||
| } | ||
|
|
||
| variable "ENVIRONMENT" { | ||
| default = "unknown-environment" | ||
| } | ||
|
|
||
| variable "REPO" { | ||
| default = "unknown-repo-name" | ||
| } | ||
|
|
||
| variable "TEST_RUN_ID" { | ||
| default = "detached" | ||
| } |
12 changes: 12 additions & 0 deletions
12
...x_multiple_services/data_stream/access_docker_tf/_dev/test/system/test-default-config.yml
This file contains hidden or 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,12 @@ | ||
| deployer: docker | ||
| service: nginx | ||
| wait_for_data_timeout: 2m | ||
| assert: | ||
| min_count: 50 | ||
| vars: ~ | ||
| data_stream: | ||
| vars: | ||
| paths: | ||
| - "{{SERVICE_LOGS_DIR}}/file.log*" | ||
| - "{{SERVICE_LOGS_DIR}}/access.log*" | ||
| - "{{SERVICE_LOGS_DIR}}/access-{{TEST_RUN_ID}}.log*" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove support for
agentdeployer based on some package spec version, maybe 3.5. Do you know if we have an open issue for the removal of this deployer?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK there is no issue for that.
Just created a new one #2679