Skip to content

Commit

Permalink
Add localstack container in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
bhapas committed Jul 10, 2023
1 parent b4d49d4 commit baf3198
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .ci/jobs/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions .ci/scripts/docker-services-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -exuo pipefail

${HOME}/bin/docker-compose -f ../jobs/docker-compose.yml down -v

exit 0
7 changes: 7 additions & 0 deletions .ci/scripts/install-docker-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -exuo pipefail

${HOME}/bin/docker-compose -f ../jobs/docker-compose.yml up -d

exit 0
8 changes: 8 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit baf3198

Please sign in to comment.