Skip to content

Commit

Permalink
update personal website frontend, add backend and setup deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinAlandzes committed Aug 26, 2024
1 parent deb40b9 commit 64ec8e8
Show file tree
Hide file tree
Showing 86 changed files with 1,120 additions and 155 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/backend-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy on server
on:
workflow_run:
workflows: [ backend-deploy ]
branches: [ main ]
types:
- completed
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: echo 'The triggering workflow passed'
- name: Checkout
uses: actions/checkout@v4

- 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: ${{ env.AWS_REGION }}
- name: Install Dependencies
run: pip install -r requirements.txt -t ./package --platform manylinux2014_x86_64 --only-binary=:all
- name: Archive the lambda function code and dependencies
run: zip -r ../deployment_package.zip package
- name: Push code to lambda
run: aws lambda update-function-code --function-name ${{ env.AWS_LAMBDA_FUNCTION_ARN }} --zip-file fileb://deployment_package.zip
29 changes: 29 additions & 0 deletions .github/workflows/backend-test-and-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Python testing and linting
on:
push:
branches:
- main
pull_request:
branches:
- main

env:
AWS_REGION: us-east-1

jobs:
lint-and-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend/contact_form_lambda
steps:
- uses: actions/checkout@v4
name: Checkout source code
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- run: pip install -r requirements.txt
- uses: chartboost/ruff-action@v1
- name: Run Tests
run: python -m pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,6 @@ fabric.properties

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# ignore folder created to package lambda
/backend/contact_form_lambda/package/
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: detect-aws-credentials
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.2
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
7 changes: 7 additions & 0 deletions backend/contact_form_lambda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contact Form

## Testing
With Httpie: https://httpie.io/
```bash
http POST https://lp2rry5bz9.execute-api.us-east-1.amazonaws.com/ name=Dustin email=dustin@alandzes.com body=Hey
```
55 changes: 55 additions & 0 deletions backend/contact_form_lambda/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import json
import os
from typing import TypedDict, Any

import boto3
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
from aws_lambda_powertools.utilities.typing import LambdaContext
from mypy_boto3_sns.service_resource import SNSServiceResource
from pydantic import BaseModel


# APIGatewayProxyEvent
class ContactFormSubmission(BaseModel):
name: str
email: str
body: str


class Event(TypedDict):
name: str
email: str
body: str


class Response(TypedDict):
statusCode: int
success: bool


def handler(event: dict[str, Any], context: LambdaContext) -> Response:
"""Accepts input from a contact form and publishes it to an SNS topic.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html
https://docs.aws.amazon.com/sns/
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic
see: main.tf for sns topic details
"""
event = APIGatewayProxyEvent(event)
sns: SNSServiceResource = boto3.resource("sns", region_name="us-east-1")
sns_topic_arn: str = os.environ["SNS_TOPIC_ARN"]
topic: sns.Topic = sns.Topic(sns_topic_arn)
body = json.loads(event.body)
topic.publish(
Message=f"""
Name: {body['name']}
Email: {body['email']}
Body: {body['body']}
"""
)

# if everything goes well, return a 200 status and success: true
return {
"statusCode": 200,
"success": True,
}
49 changes: 49 additions & 0 deletions backend/contact_form_lambda/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json
import os
from unittest import mock

import boto3
from aws_lambda_powertools.utilities.typing import LambdaContext
from moto import mock_aws

from main import handler

from moto.core import DEFAULT_ACCOUNT_ID
from moto.sns import sns_backends


@mock_aws
def test_happy_path():
"""Tests the happy path where we successfully publish to the topic."""
sns = boto3.resource("sns", region_name="us-east-1")
# We need to create the bucket since this is all in Moto's 'virtual' AWS account
topic = sns.create_topic(Name="TestTopic")

sns_backend = sns_backends[DEFAULT_ACCOUNT_ID][
"us-east-1"
] # Use the appropriate account/region
all_send_notifications = sns_backend.topics[topic.arn].sent_notifications
assert len(all_send_notifications) == 0

sample_event = {
"body": '{"name": "Dustin", "email": "dustin@alandzes.com", "body": "Hey"}'
}
with mock.patch.dict(os.environ, {"SNS_TOPIC_ARN": topic.arn}):
actual = handler(sample_event, LambdaContext())

expected = {
"statusCode": 200,
"success": True,
}
assert actual == expected
assert len(all_send_notifications) == 1

body = json.loads(sample_event["body"])
assert (
all_send_notifications[0][1]
== f"""
Name: {body['name']}
Email: {body['email']}
Body: {body['body']}
"""
)
42 changes: 42 additions & 0 deletions backend/contact_form_lambda/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
annotated-types==0.7.0
aws-lambda-powertools==2.43.1
boto3==1.35.5
boto3-stubs==1.35.5
botocore==1.35.5
botocore-stubs==1.35.5
certifi==2024.7.4
cffi==1.17.0
charset-normalizer==3.3.2
cryptography==43.0.0
idna==3.8
iniconfig==2.0.0
Jinja2==3.1.4
jmespath==1.0.1
MarkupSafe==2.1.5
moto==5.0.13
mypy-boto3-cloudformation==1.35.0
mypy-boto3-dynamodb==1.35.0
mypy-boto3-ec2==1.35.3
mypy-boto3-lambda==1.35.3
mypy-boto3-rds==1.35.0
mypy-boto3-s3==1.35.2
mypy-boto3-sns==1.35.0
mypy-boto3-sqs==1.35.0
packaging==24.1
pluggy==1.5.0
pycparser==2.22
pydantic==2.8.2
pydantic_core==2.20.1
pytest==8.3.2
python-dateutil==2.9.0.post0
PyYAML==6.0.2
requests==2.32.3
responses==0.25.3
s3transfer==0.10.2
six==1.16.0
types-awscrt==0.21.2
types-s3transfer==0.10.1
typing_extensions==4.12.2
urllib3==2.2.2
Werkzeug==3.0.4
xmltodict==0.13.0
Binary file added frontend/public/GitHub/github-mark-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/GitHub/github-mark-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/GitHub/github-mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/GitHub/github-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions frontend/public/JetBrainsMono-2.304/AUTHORS.txt

This file was deleted.

93 changes: 0 additions & 93 deletions frontend/public/JetBrainsMono-2.304/OFL.txt

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified frontend/public/resume.pdf
Binary file not shown.
Binary file added frontend/public/room.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/ssbm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/star-select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 64ec8e8

Please sign in to comment.