From 4144144dd5d8d30f0ef367854a4d1c1b1bb39c54 Mon Sep 17 00:00:00 2001 From: devops72 <43383438+devops72-sre@users.noreply.github.com> Date: Wed, 16 Oct 2024 04:56:04 +0530 Subject: [PATCH] feat:added price-pusher service infra for pragma (#210) * feat:added price-pusher service infra for pragma * fixed error --------- Co-authored-by: devops72-sre <> --- infra/price-pusher/pragma/Dockerfile | 41 +++++++++++++++++++++++++ infra/price-pusher/pragma/buildspec.yml | 30 ++++++++++++++++++ infra/price-pusher/pragma/config.yml | 9 ++++++ infra/price-pusher/pragma/entrypoint.sh | 6 ++++ 4 files changed, 86 insertions(+) create mode 100644 infra/price-pusher/pragma/Dockerfile create mode 100644 infra/price-pusher/pragma/buildspec.yml create mode 100644 infra/price-pusher/pragma/config.yml create mode 100644 infra/price-pusher/pragma/entrypoint.sh diff --git a/infra/price-pusher/pragma/Dockerfile b/infra/price-pusher/pragma/Dockerfile new file mode 100644 index 00000000..f9b1cf89 --- /dev/null +++ b/infra/price-pusher/pragma/Dockerfile @@ -0,0 +1,41 @@ +FROM python:3.12-slim AS base + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 \ + POETRY_VERSION=1.8.3 \ + POETRY_VIRTUALENVS_IN_PROJECT=true \ + POETRY_NO_INTERACTION=1 + +ENV PATH="/root/.local/bin:${PATH}" + +FROM base as builder + +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + gcc \ + libgmp3-dev \ + pipx + +RUN apt-get update && apt-get install -y bash curl && curl -1sLf \ +'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' | bash \ +&& apt-get update && apt-get install -y infisical + + +RUN pipx install poetry +COPY pragma-sdk/ /opt/pragma-sdk/ +COPY pragma-utils/ /opt/pragma-utils/ +COPY price-pusher/ /opt/price-pusher/ +WORKDIR /opt/price-pusher +RUN poetry env use 3.12 +RUN poetry install + +FROM base as final +COPY --from=builder /usr/bin/infisical /usr/bin/infisical +COPY --from=builder /opt /opt +COPY infra/price-pusher/pragma/entrypoint.sh /opt/price-pusher/ +COPY infra/price-pusher/config/ /opt/price-pusher/config/ +WORKDIR /opt/price-pusher +ENTRYPOINT ["bash","/opt/price-pusher/entrypoint.sh"] \ No newline at end of file diff --git a/infra/price-pusher/pragma/buildspec.yml b/infra/price-pusher/pragma/buildspec.yml new file mode 100644 index 00000000..68ee4a3c --- /dev/null +++ b/infra/price-pusher/pragma/buildspec.yml @@ -0,0 +1,30 @@ +version: 0.2 +phases: + pre_build: + commands: + - echo Logging in to Amazon ECR... + - aws --version + - aws ecr get-login-password --region $ECR_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$ECR_REGION.amazonaws.com + - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$ECR_REGION.amazonaws.com/$ECR_REPOSITORY_NAME + - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + - IMAGE_TAG=${COMMIT_HASH:=latest} + build: + commands: + - echo Build started on `date` + - echo Building the Docker image... + - ls -ltr + - docker build -f infra/price-pusher/pragma/Dockerfile -t $REPOSITORY_URI:latest . + - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker images... + - docker push $REPOSITORY_URI:latest + - docker push $REPOSITORY_URI:$IMAGE_TAG + - echo Writing image definitions file... + - printf '[{"name":"%s","imageUri":"%s"}]' $ECS_CONTAINER_NAME $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json +artifacts: + files: + - imagedefinitions.json + - infra/price-pusher/pragma/config.yml + discard-paths: yes \ No newline at end of file diff --git a/infra/price-pusher/pragma/config.yml b/infra/price-pusher/pragma/config.yml new file mode 100644 index 00000000..e7f2e026 --- /dev/null +++ b/infra/price-pusher/pragma/config.yml @@ -0,0 +1,9 @@ +path: "/" +container_port: 8080 +health_check_path: "/" +container_environment: + - region: "eu-west-3" + - prefix: "/conf/{{ SERVICE_NAME }}/{{ RUN_ENV }}" + - keys: + - INFISICAL_ENV + - INFISICAL_APP_PATH \ No newline at end of file diff --git a/infra/price-pusher/pragma/entrypoint.sh b/infra/price-pusher/pragma/entrypoint.sh new file mode 100644 index 00000000..4a2cf3bb --- /dev/null +++ b/infra/price-pusher/pragma/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail +export INFISICAL_TOKEN=$(infisical login --method=universal-auth --client-id=${INFISICAL_CLIENT_ID} --client-secret=${INFISICAL_CLIENT_SECRET} --silent --plain) +infisical export --projectId=${INFISICAL_PROJECT_ID} --env=${INFISICAL_ENV} --path=${INFISICAL_APP_PATH} > .env +source .env +exec /opt/price-pusher/.venv/bin/python3.12 price_pusher/main.py ${ARGS} \ No newline at end of file