Skip to content

Commit

Permalink
Merge pull request #1 from Dorianteffo/dev
Browse files Browse the repository at this point in the history
edit cicd
  • Loading branch information
Dorianteffo authored Feb 6, 2024
2 parents ba990f1 + 55e0411 commit 5daa53f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 43 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ on:
branches:
- master

pull_request:
branches:
- master

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AUTHORIZATION: ${{ secrets.AUTHORIZATION }}


jobs:
ci_job:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AUTHORIZATION: ${{ secrets.AUTHORIZATION }}
steps:
- name: checkout repo
uses: actions/checkout@v2
Expand All @@ -23,13 +28,13 @@ jobs:
- name: Run CI test
run: make ci

- name: Stop container
run: make down


deploy_terraform:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AUTHORIZATION: ${{ secrets.AUTHORIZATION }}
needs: [ci_job]
steps:
- name: checkout repo
uses: actions/checkout@v2
Expand All @@ -41,9 +46,13 @@ jobs:
run: make infra-apply


deploy_docker_lamnda:
deploy_docker_lambda:
runs-on: ubuntu-latest
needs: [ci_job, deploy_terraform]
steps:
- name: checkout repo
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -61,6 +70,7 @@ jobs:
REPOSITORY: ecr-repo-lambda
IMAGE_TAG: ${{ github.sha }}
run: |
cd extract_api_data
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform/.terraform
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lint:
docker exec lambda_job flake8 .


ci: isort format type lint
ci: isort format #lint #type


infra-init:
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ version: "3.7"
services:
lambda_job:
build:
context: .

context: ./extract_api_data
container_name: lambda_job

terraform:
Expand Down
File renamed without changes.
51 changes: 20 additions & 31 deletions api_data.py → extract_api_data/api_data.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
import logging
import logging
import requests
import boto3
import os
import os
import datetime
import json

logging.basicConfig(level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

logger = logging.getLogger(__name__)


def extract_api_data(url : str, headers : dict)->dict:
try :
def extract_api_data(url: str, headers: dict) -> dict:
try:
response = requests.get(url, headers=headers)
if response.status_code == 200 :
if response.status_code == 200:
data = json.loads(response.text)['results']
logger.info('API data extracted')
return data
except Exception as e :
return data
except Exception as e:
logger.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
logger.error(f'Error while extracting data from the api: {e}')




def upload_to_s3(bucket_name : str, key : str, data : dict) :
def upload_to_s3(bucket_name: str, key: str, data: dict):
data_string = json.dumps(data, indent=2, default=str)


# Upload JSON String to an S3 Object
s3 = boto3.client('s3')

s3.put_object(
Bucket=bucket_name,
Key=key,
Body=data_string
)

s3.put_object(Bucket=bucket_name, Key=key, Body=data_string)


def lambda_handler(event, context):
def lambda_handler(event, context):
authorization = os.environ.get('Authorization')
url = "https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc"
headers = {
"accept": "application/json",
"Authorization": authorization
}

url = (
'https://api.themoviedb.org/3/discover/movie?include_adult='
+ 'false&include_video=false&language=en-US&page=1&sort_by=popularity.desc'
)
headers = {"accept": "application/json", "Authorization": authorization}

today_date = datetime.date.today().strftime("%Y-%m-%d")

Expand All @@ -57,8 +51,3 @@ def lambda_handler(event, context):
data = extract_api_data(url, headers)

upload_to_s3(bucket_name, key, data)





File renamed without changes.

0 comments on commit 5daa53f

Please sign in to comment.