Skip to content

Commit

Permalink
♻️ Rename AWS_SQS_QUEUE_NAME_BUILDER to BUILDER_QUEUE_NAME (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 authored Dec 18, 2024
1 parent 9e8cb20 commit 9cbdc6b
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MESSENGER_SENTRY_DSN=https://01d9690bab0a81b2cb08d503d4cfb3b1@o4506985151856640.

# AWS
DEPLOYMENTS_BUCKET_NAME=fastapicloud-deployments-local
AWS_SQS_BUILDER_QUEUE_NAME=fastapicloud-builder-local
BUILDER_QUEUE_NAME=fastapicloud-builder-local
ECR_REGISTRY_URL=992382821657.dkr.ecr.us-east-1.amazonaws.com
AWS_REGION=us-east-1
# LocalStack
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
DOCKER_IMAGE_FRONTEND: "${{ vars.DOCKER_IMAGE_FRONTEND }}"
DEPLOYMENTS_BUCKET_NAME: "${{ vars.DEPLOYMENTS_BUCKET_NAME }}"
ECR_REGISTRY_URL: "${{ vars.ECR_REGISTRY_URL }}"
AWS_SQS_BUILDER_QUEUE_NAME: "${{ vars.AWS_SQS_BUILDER_QUEUE_NAME }}"
BUILDER_QUEUE_NAME: "${{ vars.BUILDER_QUEUE_NAME }}"
BUILDER_API_URL: "${{ vars.BUILDER_API_URL }}"
SECRET_KEY: "${{ secrets.SECRET_KEY }}"
FIRST_SUPERUSER_PASSWORD: "${{ secrets.FIRST_SUPERUSER_PASSWORD }}"
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
DOCKER_IMAGE_FRONTEND: "${{ vars.DOCKER_IMAGE_FRONTEND }}"
DEPLOYMENTS_BUCKET_NAME: "${{ vars.DEPLOYMENTS_BUCKET_NAME }}"
ECR_REGISTRY_URL: "${{ vars.ECR_REGISTRY_URL }}"
AWS_SQS_BUILDER_QUEUE_NAME: "${{ vars.AWS_SQS_BUILDER_QUEUE_NAME }}"
BUILDER_QUEUE_NAME: "${{ vars.BUILDER_QUEUE_NAME }}"
DEPOT_PROJECT_ID: "${{ vars.DEPOT_PROJECT_ID }}"
BUILDER_API_URL: "${{ vars.BUILDER_API_URL }}"
SECRET_KEY: "${{ secrets.SECRET_KEY }}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-messenger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
AWS_REGION: "${{ vars.AWS_REGION }}"
DEPLOYMENTS_BUCKET_NAME: "${{ vars.DEPLOYMENTS_BUCKET_NAME }}"
AWS_SQS_BUILDER_QUEUE_NAME: "${{ vars.AWS_SQS_BUILDER_QUEUE_NAME }}"
BUILDER_QUEUE_NAME: "${{ vars.BUILDER_QUEUE_NAME }}"
BUILDER_API_KEY: "${{ secrets.BUILDER_API_KEY }}"
BUILDER_API_URL: "${{ vars.BUILDER_API_URL }}"
MESSENGER_SENTRY_DSN: "${{ secrets.MESSENGER_SENTRY_DSN }}"
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/routes/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def upload_complete(
session.commit()

queue_url = sqs.get_queue_url(
QueueName=CommonSettings.get_settings().AWS_SQS_BUILDER_QUEUE_NAME
QueueName=CommonSettings.get_settings().BUILDER_QUEUE_NAME
)["QueueUrl"]
sqs.send_message(QueueUrl=queue_url, MessageBody=str(deployment_id))

Expand Down
2 changes: 1 addition & 1 deletion backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CommonSettings(SettingsEnv):
LOGFIRE_TOKEN: str | None = None
LOCALSTACK_HOST_NAME: str | None = None
ENABLE_LOCALSTACK: bool = False
AWS_SQS_BUILDER_QUEUE_NAME: str = "fastapicloud-builder"
BUILDER_QUEUE_NAME: str = "fastapicloud-builder"
AWS_REGION: str = "us-east-1"
BUILDER_API_URL: str

Expand Down
8 changes: 3 additions & 5 deletions backend/app/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ async def process_message(
response.raise_for_status()
with logfire.span("Delete message"):
await asyncify(sqs.delete_message)(
QueueUrl=common_settings.AWS_SQS_BUILDER_QUEUE_NAME,
QueueUrl=common_settings.BUILDER_QUEUE_NAME,
ReceiptHandle=receipt_handle,
)


async def main() -> None:
# Run in asyncify to not block the event loop, in case we call this function
# concurrently later
with logfire.span(
"Process queue: {name}", name=common_settings.AWS_SQS_BUILDER_QUEUE_NAME
):
with logfire.span("Process queue: {name}", name=common_settings.BUILDER_QUEUE_NAME):
queue_url_response = await asyncify(sqs.get_queue_url)(
QueueName=common_settings.AWS_SQS_BUILDER_QUEUE_NAME
QueueName=common_settings.BUILDER_QUEUE_NAME
)
queue_url = queue_url_response.get("QueueUrl")
assert queue_url
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ services:
command: >
bash -c "
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket "${DEPLOYMENTS_BUCKET_NAME}" --region us-east-1
&& aws --endpoint-url=http://localstack:4566 sqs create-queue --queue-name "${AWS_SQS_BUILDER_QUEUE_NAME}" --attributes VisibilityTimeout=600
&& aws --endpoint-url=http://localstack:4566 sqs create-queue --queue-name "${BUILDER_QUEUE_NAME}" --attributes VisibilityTimeout=600
"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion infra/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,4 @@
pulumi.export("aws_lb_controller_role_arn", aws_lb_controller_role.arn)
pulumi.export("fastapicloud_iam_role_arn", fastapicloud_iam_role.arn)
pulumi.export("ecr_iam_role_arn", ecr_iam_role.arn)
pulumi.export("sqs_builder_queue_name", sqs.sqs_builder_queue.name)
pulumi.export("builder_queue_name", sqs.builder_queue.name)
6 changes: 3 additions & 3 deletions infra/env-vars-01.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ REDIS_SERVER="$(pulumi stack output redis_backend --stack fastapilabs/$ENVIRONME
export REDIS_SERVER
echo "export REDIS_SERVER='${REDIS_SERVER}'"

AWS_SQS_BUILDER_QUEUE_NAME="$(pulumi stack output sqs_builder_queue_name --stack fastapilabs/$ENVIRONMENT)"
export AWS_SQS_BUILDER_QUEUE_NAME
echo "export AWS_SQS_BUILDER_QUEUE_NAME='${AWS_SQS_BUILDER_QUEUE_NAME}'"
BUILDER_QUEUE_NAME="$(pulumi stack output builder_queue_name --stack fastapilabs/$ENVIRONMENT)"
export BUILDER_QUEUE_NAME
echo "export BUILDER_QUEUE_NAME='${BUILDER_QUEUE_NAME}'"

echo '# Once this works, run it with: eval $(bash env-vars-01.sh)'
4 changes: 2 additions & 2 deletions infra/k8s/messenger/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ spec:
value: "${AWS_REGION}"
- name: DEPLOYMENTS_BUCKET_NAME
value: "${DEPLOYMENTS_BUCKET_NAME}"
- name: AWS_SQS_BUILDER_QUEUE_NAME
value: "${AWS_SQS_BUILDER_QUEUE_NAME}"
- name: BUILDER_QUEUE_NAME
value: "${BUILDER_QUEUE_NAME}"
- name: BUILDER_API_KEY
value: "${BUILDER_API_KEY}"
- name: BUILDER_API_URL
Expand Down
2 changes: 1 addition & 1 deletion infra/pulumi_deployment_workflow/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"sqs:StartMessageMoveTask",
"sqs:SetQueueAttributes",
],
"Resource": sqs.sqs_builder_queue.arn,
"Resource": sqs.builder_queue.arn,
},
],
}
Expand Down
2 changes: 1 addition & 1 deletion infra/pulumi_deployment_workflow/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# Reference: https://www.pulumi.com/registry/packages/aws/api-docs/sqs/queue/
sqs_builder_queue = aws.sqs.Queue(
builder_queue = aws.sqs.Queue(
f"fastapicloud-builder-queue-{stack_name}",
name=f"fastapicloud-builder-queue-{stack_name}",
visibility_timeout_seconds=600,
Expand Down
8 changes: 4 additions & 4 deletions infra/set_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GitHubSettings(BaseSettings):
deployments_bucket_name: str
ecr_registry_url: str
redis_server: str
aws_sqs_builder_queue_name: str
builder_queue_name: str


def main():
Expand All @@ -61,10 +61,10 @@ def main():
logging.info("Updating REDIS_SERVER")
environment.delete_variable("REDIS_SERVER")
environment.create_variable("REDIS_SERVER", github_settings.redis_server)
logging.info("Updating AWS_SQS_BUILDER_QUEUE_NAME")
environment.delete_variable("AWS_SQS_BUILDER_QUEUE_NAME")
logging.info("Updating BUILDER_QUEUE_NAME")
environment.delete_variable("BUILDER_QUEUE_NAME")
environment.create_variable(
"AWS_SQS_BUILDER_QUEUE_NAME", github_settings.aws_sqs_builder_queue_name
"BUILDER_QUEUE_NAME", github_settings.builder_queue_name
)

cloudflare = Cloudflare(
Expand Down

0 comments on commit 9cbdc6b

Please sign in to comment.