Skip to content

Commit

Permalink
[CZID-8457] Replace localstack with moto (#48)
Browse files Browse the repository at this point in the history
* Replace localstack with moto
  • Loading branch information
robertaboukhalil authored Sep 18, 2023
1 parent a4994ad commit e725efb
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,5 @@ static
# VS Code
.vscode

# LocalStack
.volume
# Moto
.moto_recording
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
.PHONY: gha-setup
gha-setup:
-@docker swarm init 2>/dev/null | true
touch .moto_recording
docker compose up -d

.PHONY: init
init: gha-setup
$(MAKE) seed
$(MAKE) -C entities local-init
$(MAKE) -C workflows local-init

.PHONY: seed
seed:
./bin/seed_moto.sh

.PHONY: clean
clean:
$(MAKE) -C entities local-clean
$(MAKE) -C workflows local-clean
docker compose down
rm .moto_recording
8 changes: 0 additions & 8 deletions bin/init_aws.sh

This file was deleted.

12 changes: 12 additions & 0 deletions bin/init_moto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Script to initialize moto server; runs inside the motoserver container

# Launch moto server
moto_server --host 0.0.0.0 --port $MOTO_PORT &

# Initialize data once server is ready
sleep 1 && curl -X POST "http://localhost:${MOTO_PORT}/moto-api/recorder/replay-recording"

# Go back to moto server
wait
9 changes: 9 additions & 0 deletions bin/seed_moto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Script to seed moto server; runs outside the motoserver container for development

aws="aws --endpoint-url=http://localhost:4000"
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_REGION=us-west-2
$aws s3 mb s3://local-bucket
20 changes: 11 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
version: "3.8"

services:
localstack:
image: localstack/localstack:2.2.0
# Mock boto with persistence.
# To use it from the CLI: aws --endpoint-url=http://localhost:4000 s3 ls
# To reset all services without restarting the container: curl -X POST http://localhost:4000/moto-api/reset
motoserver:
image: motoserver/moto:4.2.2
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # External services port range
- "4000:4000"
environment:
- DOCKER_HOST=unix:///var/run/docker.sock
- S3_BUCKET_DEV=s3://local-bucket
- MOTO_PORT=4000
- MOTO_ENABLE_RECORDING=True
volumes:
- ".volume:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "./bin/init_aws.sh:/etc/localstack/init/ready.d/init-aws.sh" # ready hook
- .moto_recording:/moto/moto_recording
- ./bin/init_moto.sh:/moto/init_moto.sh
entrypoint: ["bash", "/moto/init_moto.sh"]

networks:
default:
Expand Down
2 changes: 1 addition & 1 deletion entities/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ local-shell: ## Open a command shell in one of the dev containers. ex: make loca

.PHONY: local-pgconsole
local-pgconsole: ## Connect to the local postgres database.
$(docker_compose) exec postgres psql "$(LOCAL_DB_CONN_STRING)"
$(docker_compose) exec entities-db psql "$(LOCAL_DB_CONN_STRING)"

.PHONY: local-update-deps
local-update-deps: ## Update poetry.lock to reflect pyproject.toml file changes.
Expand Down
4 changes: 4 additions & 0 deletions entities/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ services:
- DB_USER=postgres
- DB_PASS=password_postgres
- DB_NAME=entities
- AWS_REGION=us-west-2
- BOTO_ENDPOINT_URL=http://motoserver.czidnet:4000
- AWS_ACCESS_KEY_ID=ACCESS_ID
- AWS_SECRET_ACCESS_KEY=ACCESS_KEY
# TODO - these are keypairs for testing only! Do not use in prod!!
- JWK_PUBLIC_KEY_FILE=/czid-platformics/entities/test_infra/fixtures/public_key.pem
- JWK_PRIVATE_KEY_FILE=/czid-platformics/entities/test_infra/fixtures/private_key.pem
Expand Down
99 changes: 75 additions & 24 deletions entities/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions entities/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ black = "^23.7.0"
uuid6 = "^2023.5.2"
mypy = "^1.5.1"
types-requests = "^2.31.0.2"
boto3 = "^1.28.43"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit e725efb

Please sign in to comment.