Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: deployment to AWS #4

Merged
merged 98 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
7df9c43
create yml deployment GitHub
KarineGEO6 Apr 4, 2024
0efa04d
Update ARN
KarineGEO6 Apr 4, 2024
d52c36f
Update cluster variable name
vincentlel Apr 4, 2024
3d842ca
Update ECS_deploy.yml
vincentlel Apr 4, 2024
73e6a12
Update ECS_deploy.yml
vincentlel Apr 4, 2024
034bacb
Update ECS_deploy.yml
vincentlel Apr 4, 2024
afa826c
Update documentation
vincentlel Apr 4, 2024
6aa3d94
update to aws credential v4
vincentlel Apr 4, 2024
4eeb5d4
add mangum
KarineGEO6 Apr 5, 2024
b45d264
update entrypoint for Lambda
KarineGEO6 Apr 5, 2024
da86f5b
Test for Lambda
KarineGEO6 Apr 6, 2024
95314b3
Test for Lambda
KarineGEO6 Apr 6, 2024
643b107
Test for Lambda
KarineGEO6 Apr 7, 2024
5a625a3
Delete get test
KarineGEO6 Apr 8, 2024
946b596
Test handler lambda
KarineGEO6 Apr 23, 2024
e485239
Update docker file
KarineGEO6 Apr 24, 2024
967a675
Test new docker file
KarineGEO6 Apr 27, 2024
99a3126
update requirements.txt
KarineGEO6 Apr 27, 2024
fd22f00
test without byoa in api.py
KarineGEO6 Apr 28, 2024
350b491
Update dockerfile
KarineGEO6 Apr 29, 2024
42a45f6
Update dockerfile
KarineGEO6 Apr 29, 2024
d86be46
Test different python version
KarineGEO6 Apr 29, 2024
6727bc8
workflow for Lambda
KarineGEO6 Apr 29, 2024
e662b97
update lambda workflow
KarineGEO6 Apr 29, 2024
b951cf9
update lambda workflow
KarineGEO6 Apr 29, 2024
c2690c6
Test new deploy
KarineGEO6 Apr 29, 2024
70d60b1
Update GitHub yaml
KarineGEO6 May 1, 2024
08abc61
Create test.txt
KarineGEO6 May 1, 2024
5bd093a
Update .github directories
KarineGEO6 May 1, 2024
5115182
Update github action Lambda
KarineGEO6 May 1, 2024
49cc739
Update Deploy Lambda yaml
KarineGEO6 May 1, 2024
474983f
Update actions path
KarineGEO6 May 1, 2024
0550c05
Update action.yml
KarineGEO6 May 1, 2024
a241795
Update AWS_deploy.yml
KarineGEO6 May 1, 2024
d4da82b
Update AWS_deploy.yml
KarineGEO6 May 1, 2024
4aa36d5
Update GitHub deployment
KarineGEO6 May 1, 2024
071599b
Update lambda action
KarineGEO6 May 1, 2024
413d41d
Update lambda action
KarineGEO6 May 1, 2024
50d7382
Update AWS_deploy.yml
KarineGEO6 May 1, 2024
376fb30
Update AWS_deploy.yml
KarineGEO6 May 1, 2024
680182d
Update for ECS deploy
KarineGEO6 May 1, 2024
85bdda8
Update for ECS deploy
KarineGEO6 May 2, 2024
ccfe769
Update for multi deployments
KarineGEO6 May 2, 2024
1cc41d3
Update for multi deployments
KarineGEO6 May 3, 2024
16cedf0
Test Lambda deployment
KarineGEO6 May 3, 2024
95d0ca7
Test ECS deployment
KarineGEO6 May 3, 2024
c72cde1
Update for ECS deployment
KarineGEO6 May 3, 2024
ca911f6
Update api.py for root message
KarineGEO6 May 3, 2024
a3b0ebf
Test for lambda
KarineGEO6 May 3, 2024
924de57
Update deploy.yml for aws secrets
KarineGEO6 May 3, 2024
da1dfc2
Update deploy.yml for DEPLOY_LAMBDA
KarineGEO6 May 4, 2024
5e2764c
Debug Lambda
KarineGEO6 May 4, 2024
589340d
Update Deploy.yml
KarineGEO6 May 5, 2024
90cc3e5
check .env file
KarineGEO6 May 5, 2024
bb2c92c
EDS URLs in .env
KarineGEO6 May 5, 2024
b890898
EDS URLs in .env
KarineGEO6 May 5, 2024
2533429
Update AWS_deploy.yml .env
KarineGEO6 May 5, 2024
bd9e8f6
Update dockerfile_lambda
KarineGEO6 May 5, 2024
1af1fe9
Update AWS_deploy.yml for env
KarineGEO6 May 5, 2024
64a4a1b
Update AWS_deploy.yml for env
KarineGEO6 May 5, 2024
3732d1d
Update dockerfile_lambda
KarineGEO6 May 5, 2024
23d7b67
Update AWS_deploy.yml for the build lambda
KarineGEO6 May 5, 2024
0535366
Update AWS_deploy.yml for the build lambda
KarineGEO6 May 5, 2024
f286f1d
Update dockerfile_lambda
KarineGEO6 May 5, 2024
17a7e4d
Update env for RDS deploy
KarineGEO6 May 6, 2024
52df38a
Update dockerfile
KarineGEO6 May 6, 2024
85d4e9a
Update dockerfile
KarineGEO6 May 6, 2024
c23a58a
Update dockerfile
KarineGEO6 May 6, 2024
b376db6
Test dockerfile
KarineGEO6 May 6, 2024
e860197
Test dockerfile
KarineGEO6 May 6, 2024
35328c2
Test .env dockerfile
KarineGEO6 May 6, 2024
bac2ecd
Test .env dockerfile
KarineGEO6 May 6, 2024
d8e28f1
Update .env dockerfile
KarineGEO6 May 6, 2024
416f0fe
Update for .env local build
KarineGEO6 May 6, 2024
ebd73fe
Update for .env local build
KarineGEO6 May 6, 2024
6dc7f72
Update for .env local build
KarineGEO6 May 6, 2024
92bd7c1
Update for .env local build
KarineGEO6 May 6, 2024
7d131d5
Update for .env local build
KarineGEO6 May 6, 2024
0017c64
New version dockerfile
KarineGEO6 May 6, 2024
45615eb
Remove debug from api.py
KarineGEO6 May 7, 2024
63b0d1d
Update args dockerfile lambda
KarineGEO6 May 7, 2024
97b6592
Update args dockerfile lambda
KarineGEO6 May 7, 2024
31af9ad
Update deploy for Lambda configuration
KarineGEO6 May 7, 2024
0f3f36a
Update lambda configuration
KarineGEO6 May 7, 2024
c1eb3bf
Update lambda configuration
KarineGEO6 May 7, 2024
9a32aef
Update lambda config
KarineGEO6 May 7, 2024
c6dcfb2
Update lambda config
KarineGEO6 May 7, 2024
170f285
Lambda config with args
KarineGEO6 May 7, 2024
fddf63d
Correction deploy.yml
KarineGEO6 May 7, 2024
30bd57f
Correction deploy.yml
KarineGEO6 May 7, 2024
df376dc
Deployment
KarineGEO6 May 13, 2024
81800ef
Notebook updates
KarineGEO6 May 14, 2024
09a8d26
Adding Lambda Terraform script
KarineGEO6 May 20, 2024
701200c
Update Terraform for ECS
KarineGEO6 May 21, 2024
782eb61
Update deployment.yaml
KarineGEO6 May 21, 2024
bb84529
Update ECS.tf
KarineGEO6 May 21, 2024
28e4c7f
deployment.yaml
KarineGEO6 May 21, 2024
a911d9d
AWS_deploy.yml
KarineGEO6 May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ AWS_BUCKET_NAME=
AZURE_ACCOUNT_NAME=
AZURE_BLOB_CONTAINER_NAME=
AZURE_SAS_CREDENTIAL=

GATEWAY_STAGE=
157 changes: 157 additions & 0 deletions .github/workflows/AWS_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: Deployment AWS

on:
push:
branches:
- deploy1

env:
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
EDS_API_URL: ${{ secrets.EDS_API_URL }}
EDS_AUTH_URL: ${{ secrets.EDS_AUTH_URL }}
LAMBDA_FUNCTION: ${{ secrets.LAMBDA_FUNCTION }}
GATEWAY_STAGE: ${{ secrets.GATEWAY_STAGE }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DEPLOY_LAMBDA: ${{ secrets.DEPLOY_LAMBDA }}

permissions:
id-token: write # This is required for requesting the JWT
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check if secret gateway stage exists and assign to variable
id: gateway-key
run: |
if [[ -n "${{ env.GATEWAY_STAGE }}" ]]; then
echo "::set-output name=key_gateway_stage::${{ env.GATEWAY_STAGE }}"
else
echo "::set-output name=key_gateway_stage::\"\""
fi
shell: bash

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::489065051964:role/GitHubActionProcessor-AssumeRoleWithAction #change to reflect your IAM role’s ARN
role-session-name: GitHub_to_AWS_via_gitaction_devOps
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push image Lambda to Amazon ECR
id: build-image-lambda
if: ${{ env.DEPLOY_LAMBDA == 'true' }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build \
--build-arg EDS_API_URL=${{ env.EDS_API_URL }} \
--build-arg EDS_AUTH_URL=${{ env.EDS_AUTH_URL }} \
--build-arg AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
--build-arg AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
--build-arg INPUT_JSON_PATH="data/processor_input_example.json" \
--build-arg GATEWAY_STAGE=${{ steps.gateway-key.outputs.key_gateway_stage }} \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . -f Dockerfile_lambda
# docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: Update image to lambda funtion
id: lambda-function
if: ${{ env.DEPLOY_LAMBDA == 'true' }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
aws lambda update-function-code \
--function-name $LAMBDA_FUNCTION \
--image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

# - name: Update lambda funtion configuration
# id: lambda-function-config
# if: ${{ env.DEPLOY_LAMBDA == 'true' }}
# run: |
# aws lambda update-function-configuration \
# --function-name $LAMBDA_FUNCTION \
# --environment "Variables={EDS_API_URL=${{ env.EDS_API_URL }},EDS_AUTH_URL=${{ env.EDS_AUTH_URL }}}"

- name: Build, tag, and push image Task to Amazon ECR
id: build-image
if: ${{ env.DEPLOY_LAMBDA != 'true' }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build \
--build-arg EDS_API_URL=${{ env.EDS_API_URL }} \
--build-arg EDS_AUTH_URL=${{ env.EDS_AUTH_URL }} \
--build-arg AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
--build-arg AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
--build-arg INPUT_JSON_PATH="data/processor_input_example.json" \
--build-arg GATEWAY_STAGE=${{ steps.gateway-key.outputs.key_gateway_stage }} \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . -f Dockerfile_ECS
# docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "::set-output name=IMAGE_URI::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

- name: Download task definition
if: ${{ env.DEPLOY_LAMBDA != 'true' }}
run: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --query taskDefinition > task-definition.json
echo $(cat task-definition.json | jq 'del(
.taskDefinitionArn,
.requiresAttributes,
.compatibilities,
.revision,
.status,
.registeredAt,
.registeredBy
)') > task-definition.json
cat task-definition.json

- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
if: ${{ env.DEPLOY_LAMBDA != 'true' }}
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: updating task-definition file
if: ${{ env.DEPLOY_LAMBDA != 'true' }}
run: cat ${{ steps.task-def.outputs.task-definition }}

- name: Deploy Amazon ECS task definition
if: ${{ env.DEPLOY_LAMBDA != 'true' }}
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ target/

# Mypy cache
.mypy_cache/

# credentials AWS for Terraform
#aws_credentials.tfvars
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ COPY docker-entrypoint.sh /usr/local/bin/
RUN dos2unix /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]
RUN chmod 644 api/api.py

ENTRYPOINT ["docker-entrypoint.sh"]
37 changes: 37 additions & 0 deletions Dockerfile_ECS
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM continuumio/miniconda3:23.10.0-1
EXPOSE 80

RUN pip install --upgrade pip==22.0.4
RUN conda clean --all
RUN pip cache purge

WORKDIR /app

COPY ./requirements.txt .

RUN pip install -r requirements.txt
RUN pip cache purge; exit 0
RUN apt-get update && apt-get install -y dos2unix
COPY ./src .

# Set up environment variables
ARG EDS_API_URL
ENV EDS_API_URL=${EDS_API_URL}
ARG EDS_AUTH_URL
ENV EDS_AUTH_URL=${EDS_AUTH_URL}
ARG AWS_ACCESS_KEY_ID
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ARG AWS_SECRET_ACCESS_KEY
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ARG INPUT_JSON_PATH
ENV INPUT_JSON_PATH=${INPUT_JSON_PATH}
ARG GATEWAY_STAGE
ENV GATEWAY_STAGE=${GATEWAY_STAGE}

COPY docker-entrypoint.sh /usr/local/bin/
RUN dos2unix /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

RUN chmod 644 api/api.py

ENTRYPOINT ["docker-entrypoint.sh"]
29 changes: 29 additions & 0 deletions Dockerfile_lambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM public.ecr.aws/lambda/python:3.11

RUN pip install --upgrade pip==22.0.4
RUN pip cache purge

# Copy function code
COPY ./src ${LAMBDA_TASK_ROOT}

# Set up environment variables
ARG EDS_API_URL
ENV EDS_API_URL=${EDS_API_URL}
ARG EDS_AUTH_URL
ENV EDS_AUTH_URL=${EDS_AUTH_URL}
ARG AWS_ACCESS_KEY_ID
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ARG AWS_SECRET_ACCESS_KEY
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ARG INPUT_JSON_PATH
ENV INPUT_JSON_PATH=${INPUT_JSON_PATH}
ARG GATEWAY_STAGE
ENV GATEWAY_STAGE=${GATEWAY_STAGE}

# Install the function's dependencies using file requirements.txt
# from your project folder.
COPY requirements.txt ${LAMBDA_TASK_ROOT}
# Install the specified packages
RUN pip install -r requirements.txt
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "api.api.handler" ]
7 changes: 1 addition & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#!/bin/bash
set -e
if [ "$RUN_MODE_ENV" = "API" ]; then
exec hypercorn api.api:app -b 0.0.0.0:80 --worker-class trio
else
exec python main.py "$@"
fi
exec hypercorn api.api:app -b 0.0.0.0:80 --worker-class trio
37 changes: 20 additions & 17 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
name: earthdaily-processor
name: reflectance-processor
channels:
- conda-forge
- defaults
- conda-forge
- defaults
dependencies:
- python>3.11
- ipykernel
- python-dotenv>=0.5.1
- geojson
- pyproj
- zarr
- pip
- pip
- pip:
# aws
- boto3
# azure
- azure-storage-blob
- earthdaily==0.0.6
- jupyter
- matplotlib
- numpy
- scipy
- geogif
- fastapi
- pydantic
- byoa==0.1.0a2
# aws
- boto3
# azure
- azure-storage-blob
- earthdaily==0.0.6
- jupyter
- matplotlib
- numpy
- scipy
- geogif
- fastapi
- pydantic
- byoa==0.1.0a2
- mangum
- cloudpathlib
- adlfs
Loading
Loading