mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-19 23:38:06 +02:00
Added localstack example using docker compose
Signed-off-by: ulises-jeremias <ulisescf.24@gmail.com>
This commit is contained in:
parent
e6b1d2755f
commit
199c896dee
5 changed files with 162 additions and 0 deletions
|
@ -79,6 +79,7 @@ with Spring framework and a Postgres database. <a href="spring-postgres"><i
|
|||
- [`Pi-hole / cloudflared`](pihole-cloudflared-DoH) - Sample Pi-hole setup with use of DoH cloudflared service
|
||||
- [`Prometheus / Grafana`](prometheus-grafana)
|
||||
- [`Wordpress / MySQL`](wordpress-mysql)
|
||||
- [`LocalStack`](localstack)
|
||||
|
||||
<!--lint disable awesome-toc-->
|
||||
|
||||
|
|
2
localstack/.gitignore
vendored
Normal file
2
localstack/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.env
|
||||
volume/
|
90
localstack/README.md
Normal file
90
localstack/README.md
Normal file
|
@ -0,0 +1,90 @@
|
|||
# LocalStack
|
||||
|
||||
This example shows how to use [LocalStack](https://localstack.cloud/) to emulate AWS services locally using docker compose.
|
||||
|
||||
Project structure:
|
||||
|
||||
```text
|
||||
.
|
||||
├── compose.yaml
|
||||
├── README.md
|
||||
└── setup-resources.sh
|
||||
```
|
||||
|
||||
[_compose.yaml_](compose.yaml)
|
||||
|
||||
```yml
|
||||
services:
|
||||
localstack:
|
||||
image: localstack/localstack:2.3.2
|
||||
ports:
|
||||
- "4566:4566" # LocalStack Gateway
|
||||
- "4510-4559:4510-4559" # external services port range
|
||||
...
|
||||
setup-resources:
|
||||
image: mesosphere/aws-cli:1.14.5
|
||||
volumes:
|
||||
- ./:/project
|
||||
...
|
||||
```
|
||||
|
||||
## Deploy with docker compose
|
||||
|
||||
```sh
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
It will execute the script `setup-resources.sh` to setup the resources.
|
||||
|
||||
## Resources
|
||||
|
||||
Once the docker compose is up, it will create the following resources:
|
||||
|
||||
- [DynamoDB Table](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)
|
||||
- [Kinesis Stream](https://docs.aws.amazon.com/streams/latest/dev/getting-started.html)
|
||||
- [S3 Bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
|
||||
- [SQS Queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html)
|
||||
|
||||
## Testing the services
|
||||
|
||||
From outside the container you can execute the following commands to test the service each service:
|
||||
|
||||
- **DynamoDB**
|
||||
|
||||
```sh
|
||||
$ aws --endpoint-url=http://localhost:4566 dynamodb list-tables
|
||||
{
|
||||
"TableNames": [
|
||||
"my_table"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- **Kinesis**
|
||||
|
||||
```sh
|
||||
$ aws --endpoint-url=http://localhost:4566 kinesis list-streams
|
||||
{
|
||||
"StreamNames": [
|
||||
"my_stream"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- **S3**
|
||||
|
||||
```sh
|
||||
$ aws --endpoint-url=http://localhost:4566 s3 ls
|
||||
2022-08-08 03:16:01 example-bucket
|
||||
```
|
||||
|
||||
- **SQS**
|
||||
|
||||
```sh
|
||||
$ aws --endpoint-url=http://localhost:4566 sqs list-queues
|
||||
{
|
||||
"QueueUrls": [
|
||||
"http://localhost:4566/000000000000/my_queue"
|
||||
]
|
||||
}
|
||||
```
|
42
localstack/compose.yml
Normal file
42
localstack/compose.yml
Normal file
|
@ -0,0 +1,42 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
localstack:
|
||||
image: localstack/localstack:2.3.2
|
||||
ports:
|
||||
- "4566:4566" # LocalStack Gateway
|
||||
- "4510-4559:4510-4559" # external services port range
|
||||
- "53:53" # DNS config (only required for Pro)
|
||||
- "53:53/udp" # DNS config (only required for Pro)
|
||||
- "443:443" # LocalStack HTTPS Gateway (only required for Pro)
|
||||
environment:
|
||||
- DEBUG=${DEBUG-}
|
||||
- PERSISTENCE=${PERSISTENCE-}
|
||||
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
|
||||
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY-} # only required for Pro
|
||||
- DOCKER_HOST=unix:///var/run/docker.sock
|
||||
- SERVICES=dynamodb,kinesis,s3,sqs
|
||||
volumes:
|
||||
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
networks:
|
||||
- localstack-net
|
||||
|
||||
setup-resources:
|
||||
image: mesosphere/aws-cli:1.14.5
|
||||
volumes:
|
||||
- ./:/project
|
||||
environment:
|
||||
- AWS_ACCESS_KEY_ID=dummyaccess
|
||||
- AWS_SECRET_ACCESS_KEY=dummysecret
|
||||
- AWS_DEFAULT_REGION=us-east-1
|
||||
entrypoint: /bin/sh -c
|
||||
command: /project/setup-resources.sh
|
||||
networks:
|
||||
- localstack-net
|
||||
depends_on:
|
||||
- localstack
|
||||
|
||||
networks:
|
||||
localstack-net:
|
||||
driver: bridge
|
27
localstack/setup-resources.sh
Executable file
27
localstack/setup-resources.sh
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Lets check if localstack is available. If we can't reach to localstack
|
||||
# in 60 seconds we error out
|
||||
counter=0
|
||||
until nc -z localstack 4566; do
|
||||
if [ ${counter} -eq 60 ]; then
|
||||
echo "Timeout: Failed to reach localstack."
|
||||
exit 1
|
||||
fi
|
||||
counter=$((counter + 1))
|
||||
printf '.'
|
||||
sleep 1
|
||||
done
|
||||
|
||||
aws dynamodb create-table --endpoint-url=http://localstack:4566 --table-name my_table \
|
||||
--attribute-definitions AttributeName=key,AttributeType=S \
|
||||
--key-schema AttributeName=key,KeyType=HASH \
|
||||
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
|
||||
|
||||
aws kinesis create-stream --endpoint-url=http://localstack:4566 --stream-name my_stream --shard-count 1
|
||||
|
||||
aws s3 mb s3://example-bucket --endpoint-url=http://localstack:4566
|
||||
|
||||
aws sqs create-queue --endpoint-url=http://localstack:4566 --queue-name my_queue
|
||||
|
||||
# you can go on and put initial items in tables...
|
Loading…
Add table
Add a link
Reference in a new issue