BitBucket
Introduction
Section titled โIntroductionโBitBucket Pipeline is a CI/CD tool that allows you to build, test, and deploy your code directly from BitBucket. This guide will show you how to use LocalStack in BitBucket Pipelines.
Setting up the BitBucket Pipeline
Section titled โSetting up the BitBucket PipelineโWhen you want to integrate LocalStack into your job configuration, you just have to execute the following steps:
- Specify the Docker Socket to allow the LocalStack container to access the Docker daemon.
- Export the
AWS_ENDPOINT_URLenvironment variable to point to the LocalStack endpoint. - Install the
localstackCLI andawscli-localto interact with LocalStackโs emulated services. - Start the LocalStack container in detached mode by specifying the Docker Socket and Docker Host.
The following example BitBucket Pipeline configuration (bitbucket-pipelines.yaml) executes these steps, creates a new S3 bucket, and queries the list of S3 buckets:
image: python:3.9
definitions: services: docker: memory: 2048
pipelines: default: - step: name: Test Localstack services: - docker script: - export PYTHONPATH=$PYTHONPATH:$(pwd) - export DOCKER_SOCK=$DOCKER_HOST - export AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566" - env - echo "${BITBUCKET_DOCKER_HOST_INTERNAL} localhost.localstack.cloud " >> /etc/hosts - pip install localstack awscli-local - | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip ./aws/install - docker run -d --rm -p 4566:4566 -p 4510-4559:4510-4559 -e DOCKER_SOCK=tcp://${BITBUCKET_DOCKER_HOST_INTERNAL}:2375 -e DOCKER_HOST=tcp://${BITBUCKET_DOCKER_HOST_INTERNAL}:2375 --name localstack-main localstack/localstack - localstack wait -t 60 - awslocal s3 mb s3://test-bucket - awslocal s3 lsConfiguring a CI Auth Token
Section titled โConfiguring a CI Auth TokenโYou can enable LocalStack for AWS by using the localstack/localstack-pro image and adding your CI Auth Token to the projectโs environment variables.
The LocalStack container will automatically pick it up and activate the Pro features.
Go to the CI Auth Token page and copy your CI Auth Token. To add a CI Auth Token to your BitBucket Pipeline:
- Select a workspace from the BitBucket dashboard.
- Select the Settings on the top navigation bar.
- Select Workspace settings from the Settings dropdown menu.
- On the left-hand menu, navigate to Pipelines and click on Workspace variables.
- Add a new variable with the name
LOCALSTACK_AUTH_TOKENand the value of your CI Auth Token.
Navigate to your BitBucket Pipeline and add the following lines to the bitbucket-pipelines.yaml file:
pipelines: default: - step: name: Test Localstack services: - docker script: ... - export LOCALSTACK_AUTH_TOKEN=$LOCALSTACK_AUTH_TOKEN ... - docker run -d --rm -p 4566:4566 -p 4510-4559:4510-4559 -e LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} -e DEBUG=1 -e LS_LOG=trace -e DOCKER_SOCK=tcp://${BITBUCKET_DOCKER_HOST_INTERNAL}:2375 -e DOCKER_HOST=tcp://${BITBUCKET_DOCKER_HOST_INTERNAL}:2375 --name localstack-main localstack/localstack-pro ...Current Limitations
Section titled โCurrent LimitationsโMounting Volumes
Section titled โMounting VolumesโBitBucket Pipelines does not support mounting volumes, so you cannot mount a volume to the LocalStack container. This limitation prevents you from mounting the Docker Socket to the LocalStack container, which is required to create compute resources, such as Lambda functions or ECS tasks.