diff --git a/.ci/jobs/docker-compose.yml b/.ci/jobs/docker-compose.yml new file mode 100644 index 000000000000..11f43b37a24f --- /dev/null +++ b/.ci/jobs/docker-compose.yml @@ -0,0 +1,25 @@ +version: '2.3' +services: + # This is a proxy used to block beats until all services are healthy. + # See: https://github.com/docker/compose/issues/4369 + proxy_dep: + image: busybox + depends_on: + localstack: { condition: service_healthy } + + localstack: + image: localstack/localstack + hostname: localhost + ports: + - "4566:4566" # LocalStack Gateway + environment: + - SERVICES=s3,sqs,sns,secretsmanager + - DEBUG=1 + - DOCKER_HOST=unix:///var/run/docker.sock + - HOST_TMP_FOLDER=${TMPDIR} + - HOSTNAME_EXTERNAL=localhost + - S3_HOSTNAME=localhost + - PROVIDER_OVERRIDE_S3=asf + volumes: + - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" + - "/var/run/docker.sock:/var/run/docker.sock" diff --git a/.ci/scripts/docker-services-cleanup.sh b/.ci/scripts/docker-services-cleanup.sh new file mode 100755 index 000000000000..19f11e5eb649 --- /dev/null +++ b/.ci/scripts/docker-services-cleanup.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -exuo pipefail + +${HOME}/bin/docker-compose -f ../jobs/docker-compose.yml down -v + +exit 0 diff --git a/.ci/scripts/install-docker-services.sh b/.ci/scripts/install-docker-services.sh new file mode 100755 index 000000000000..7c91edcda94a --- /dev/null +++ b/.ci/scripts/install-docker-services.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -exuo pipefail + +${HOME}/bin/docker-compose -f ../jobs/docker-compose.yml up -d + +exit 0 diff --git a/Jenkinsfile b/Jenkinsfile index d9192e1e1ad8..9597f6a8c944 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -920,6 +920,8 @@ def startCloudTestEnv(Map args = [:]) { stage("${name}-prepare-cloud-env"){ withBeatsEnv(archive: false, withModule: false) { try { + // Run the docker compose file to setup the emulated cloud environment + sh(label: 'Run docker-compose services for emulated cloud env', script: ".ci/scripts/install-docker-services.sh ", returnStatus: true) dirs?.each { folder -> retryWithSleep(retries: 2, seconds: 5, backoff: true){ terraformApply(folder) @@ -930,6 +932,9 @@ def startCloudTestEnv(Map args = [:]) { // If it failed then cleanup without failing the build sh(label: 'Terraform Cleanup', script: ".ci/scripts/terraform-cleanup.sh ${folder}", returnStatus: true) } + // Cleanup the docker services + sh(label: 'Docker Compose Cleanup', script: ".ci/scripts/docker-services-cleanup.sh", returnStatus: true) + error('startCloudTestEnv: terraform apply failed.') } finally { // Archive terraform states in case manual cleanup is needed. @@ -954,12 +959,15 @@ def terraformApply(String directory) { sh(label: "Terraform Apply on ${directory}", script: "terraform apply -auto-approve") } } + // Cleanup associated docker services + sh(label: 'Docker Compose Cleanup', script: ".ci/scripts/docker-services-cleanup.sh", returnStatus: true) } /** * Tear down the terraform environments, by looking for all terraform states in directory * then it runs terraform destroy for each one. * It uses terraform states previously stashed by startCloudTestEnv. +* This also tears down any associated docker services */ def terraformCleanup(Map args = [:]) { String name = normalise(args.name)