forked from paowongsakorn/get_price_on_dex_BSC_Web3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make bot dependent from service on deployment (microservices)
- Loading branch information
Showing
7 changed files
with
133 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Deploy FastAPI service to ECS (EC2) | ||
|
||
on: | ||
push: | ||
paths: | ||
- service/* | ||
branches: | ||
- multiple-services-in-container | ||
- develop | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-southeast-1 | ||
|
||
# For private ECR Repository | ||
# - name: Login to Amazon ECR | ||
# id: login-ecr | ||
# uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
# For private ECR Repository | ||
# - name: Login to ECR via docker/login-action | ||
# uses: docker/[email protected] | ||
# with: | ||
# registry: ${{ steps.login-ecr.outputs.registry }} | ||
|
||
- name: Login to Public ECR | ||
uses: docker/[email protected] | ||
with: | ||
registry: public.ecr.aws | ||
username: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
env: | ||
AWS_REGION: us-east-1 | ||
|
||
- name: Docker Setup Buildx | ||
uses: docker/[email protected] | ||
|
||
- name: Build and push Docker images | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.AWS_ECR_REGISTRY }}/${{ secrets.AWS_AWS_ECR_REPOSITORY_FAST_API_SERVICE }}:${{ github.sha }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Fill in the new image ID in the Amazon ECS task definition | ||
id: task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: .github/task-definition-fast-api.json | ||
container-name: ${{ secrets.AWS_ECS_CONTAINER_FAST_API }} | ||
image: ${{ secrets.AWS_ECR_REGISTRY }}/${{ secrets.AWS_ECR_REPOSITORY_FAST_API_SERVICE }}:${{ github.sha }} | ||
environment-variables: | | ||
APP_REVISION=${{ github.sha }} | ||
- name: Deploy Amazon ECS task definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: ${{ secrets.AWS_ECS_SERVICE_FAST_API }} | ||
cluster: ${{ secrets.AWS_ECS_CLUSTER }} | ||
wait-for-service-stability: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# use python container image | ||
FROM python:3.9.5-alpine as builder | ||
|
||
# set the working directory of the image filesystem | ||
WORKDIR /dependencies | ||
|
||
RUN pip install pipenv==2021.5.29 | ||
|
||
COPY Pipfile Pipfile.lock ./ | ||
|
||
# Generate requirements file for pip to install dependencies | ||
RUN pipenv lock --keep-outdated --requirements > requirements.txt | ||
|
||
#################################################################### | ||
|
||
FROM python:3.9.5-slim as production | ||
|
||
# Fix .local/bin not in PATH warning on pip | ||
ENV PATH "$PATH:/home/python/.local/bin" | ||
|
||
WORKDIR /usr/src/app | ||
|
||
RUN apt-get update \ | ||
&& apt-get install gcc dumb-init redis-server -y \ | ||
&& apt-get clean | ||
|
||
RUN groupadd -r python && useradd -m -r -g python python | ||
|
||
USER python | ||
|
||
COPY --from=builder /dependencies/requirements.txt . | ||
|
||
RUN pip install -r requirements.txt && pip cache purge | ||
|
||
COPY /telegram_bot/ ./telegram_bot | ||
|
||
# Start the bit | ||
CMD ["dumb-init", "python", "telegram_bot/main.py"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters