-
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.
- Loading branch information
Showing
14 changed files
with
166 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Publish Docker image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
name: Check out code | ||
|
||
- uses: mr-smithers-excellent/docker-build-push@v6 | ||
name: Build & push Docker image frontnend | ||
with: | ||
image: kahmed23/serverlessmovies | ||
tags: frontend-v1, latest | ||
registry: docker.io | ||
directory: frontend | ||
dockerfile: Dockerfile | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- uses: mr-smithers-excellent/docker-build-push@v6 | ||
name: Build & push Docker image backend | ||
with: | ||
image: kahmed23/serverlessmovies | ||
tags: backend-v1, latest | ||
registry: docker.io | ||
directory: backend | ||
dockerfile: Dockerfile | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
|
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,2 @@ | ||
.env | ||
.vscode |
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,2 @@ | ||
AWS_ACCESS_KEY_ID=value_here | ||
AWS_SECRET_ACCESS_KEY=value_here |
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,10 @@ | ||
FROM python:3.12 | ||
WORKDIR /usr/local/app | ||
|
||
# Install the application dependencies | ||
COPY . ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
EXPOSE 5000 | ||
|
||
CMD ["python", "flask-db-request.py", "--port", "5000"] |
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,61 @@ | ||
from flask import Flask, jsonify, request | ||
from flask_cors import CORS | ||
import boto3 | ||
from boto3.dynamodb.conditions import Key | ||
import os | ||
from decimal import Decimal | ||
|
||
# Initialize Flask app | ||
app = Flask(__name__) | ||
|
||
# Enable CORS for all routes | ||
CORS(app) | ||
|
||
# Set up DynamoDB session | ||
session = boto3.Session( | ||
region_name='us-east-1' | ||
) | ||
dynamodb = session.resource( | ||
'dynamodb', | ||
aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'), | ||
aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY') | ||
) | ||
|
||
# Connect to the DynamoDB table | ||
table = dynamodb.Table('serverlessMovieApiTable') | ||
|
||
# Helper function to handle Decimal type from DynamoDB | ||
def decimal_to_float(data): | ||
if isinstance(data, list): | ||
return [decimal_to_float(item) for item in data] | ||
elif isinstance(data, dict): | ||
return {key: decimal_to_float(value) for key, value in data.items()} | ||
elif isinstance(data, Decimal): | ||
return float(data) | ||
return data | ||
|
||
# Route to get all movies | ||
@app.route('/movies', methods=['GET']) | ||
def get_all_movies(): | ||
try: | ||
response = table.scan() | ||
items = decimal_to_float(response['Items']) # Convert Decimals to floats | ||
return jsonify(items), 200 | ||
except Exception as e: | ||
return jsonify({'error': str(e)}), 500 | ||
|
||
# Route to get movies by year | ||
@app.route('/movies/<int:year>', methods=['GET']) | ||
def get_movies_by_year(year): | ||
try: | ||
response = table.query( | ||
KeyConditionExpression=Key('releaseYear').eq(year) | ||
) | ||
items = decimal_to_float(response['Items']) # Convert Decimals to floats | ||
return jsonify(items), 200 | ||
except Exception as e: | ||
return jsonify({'error': str(e)}), 500 | ||
|
||
# Run the Flask app | ||
if __name__ == '__main__': | ||
app.run(debug=True, host="0.0.0.0", port=5000) |
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,6 @@ | ||
Flask==1.1.4 | ||
Flask-Cors==3.0.10 | ||
boto3==1.28.0 # Or the latest compatible version | ||
botocore==1.31.0 # Ensure compatibility with boto3 | ||
python-dotenv==0.18.0 | ||
markupsafe<2.1 |
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,12 @@ | ||
services: | ||
backend-api: | ||
build: ./backend | ||
env_file: | ||
- ./backend/.env | ||
ports: | ||
- "5000:5000" | ||
|
||
frontend-web: | ||
build: ./frontend | ||
ports: | ||
- "80:80" |
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,11 @@ | ||
FROM nginx:stable | ||
|
||
WORKDIR /usr/share/nginx/html | ||
|
||
# Copy the HTML, CSS, and JavaScript files into the container | ||
COPY . ./ | ||
|
||
EXPOSE 80 | ||
|
||
# Start Nginx when the container starts | ||
CMD ["nginx", "-g", "daemon off;"] |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.