Skip to content

Commit

Permalink
feat/price-pusher-infra: offchain/onchain buildspec (#154)
Browse files Browse the repository at this point in the history
* feat: add infra folder for deployments

* fix: use bash parameter substitution for entrypoint

* feat: add offchain/onchain buildspec for infra deployment

* fix: buildspecs path for each price-pusher

* fix: config.yml inside Dockerfile, remove useless config.yml

* fix: try with poetry run script

* feat: API_BASE_URL variable envfor offchain price-pusher, fix script name for vrf-listener
  • Loading branch information
hel-kame authored Jul 23, 2024
1 parent 26081e2 commit 056e39e
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 5 deletions.
33 changes: 33 additions & 0 deletions infra/price-pusher/offchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 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 /opt /opt
WORKDIR /opt/price-pusher
ENTRYPOINT /opt/price-pusher/.venv/bin/python3.12 price_pusher/main.py -c config/config.example.yaml -t ${TARGET} -n ${NETWORK} -p ${PRIVATE_KEY} --publisher-name ${PUBLISHER_NAME} --publisher-address ${PUBLISHER_ADDRESS} --rpc-url ${RPC_URL} --api-key ${API_KEY} --api-base-url ${API_BASE_URL}
30 changes: 30 additions & 0 deletions infra/price-pusher/offchain/buildspec.yml
Original file line number Diff line number Diff line change
@@ -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/offchain/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/offchain/config.yml
discard-paths: yes
15 changes: 15 additions & 0 deletions infra/price-pusher/offchain/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
path: "/"
container_port: 8080
health_check_path: "/"
container_environment:
- region: "eu-west-3"
- prefix: "/conf/{{ SERVICE_NAME }}/{{ RUN_ENV }}"
- keys:
- TARGET
- NETWORK
- PRIVATE_KEY
- PUBLISHER_NAME
- PUBLISHER_ADDRESS
- RPC_URL
- API_KEY
- API_BASE_URL
33 changes: 33 additions & 0 deletions infra/price-pusher/onchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 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 /opt /opt
WORKDIR /opt/price-pusher
ENTRYPOINT /opt/price-pusher/.venv/bin/python3.12 price_pusher/main.py -c config/config.example.yaml -t ${TARGET} -n ${NETWORK} -p ${PRIVATE_KEY} --publisher-name ${PUBLISHER_NAME} --publisher-address ${PUBLISHER_ADDRESS} --rpc-url ${RPC_URL}
30 changes: 30 additions & 0 deletions infra/price-pusher/onchain/buildspec.yml
Original file line number Diff line number Diff line change
@@ -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/onchain/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/onchain/config.yml
discard-paths: yes
13 changes: 13 additions & 0 deletions infra/price-pusher/onchain/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
path: "/"
container_port: 8080
health_check_path: "/"
container_environment:
- region: "eu-west-3"
- prefix: "/conf/{{ SERVICE_NAME }}/{{ RUN_ENV }}"
- keys:
- TARGET
- NETWORK
- PRIVATE_KEY
- PUBLISHER_NAME
- PUBLISHER_ADDRESS
- RPC_URL
6 changes: 1 addition & 5 deletions infra/vrf-listener/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ COPY vrf-listener/ /opt/vrf-listener/
WORKDIR /opt/vrf-listener
RUN poetry env use 3.12
RUN poetry install

FROM base as final
COPY --from=builder /opt /opt
WORKDIR /opt/vrf-listener
ENTRYPOINT /opt/vrf-listener/.venv/bin/python3.12 vrf_listener/main.py -n ${NETWORK} --oracle-address ${ORACLE_ADDRESS} --vrf-address ${VRF_ADDRESS} --admin-address ${ADMIN_ADDRESS} --private-key ${PRIVATE_KEY} -t ${CHECK_INTERVAL} --rpc-url ${RPC_URL}
ENTRYPOINT poetry run vrf-listener -n ${NETWORK} --oracle-address ${ORACLE_ADDRESS} --vrf-address ${VRF_ADDRESS} --admin-address ${ADMIN_ADDRESS} --private-key ${PRIVATE_KEY} -t ${CHECK_INTERVAL} --rpc-url ${RPC_URL}

0 comments on commit 056e39e

Please sign in to comment.