Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions .github/workflows/deploy_aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# name: deploy-fastapi

# on:
# pull_request:
# branches:
# - main

# jobs:
# deploy:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: 3.11

# - name: Install dependencies
# run: |
# pip install -r backend/requirements.txt

# - name: Zip application
# run: |
# zip -r fastapi_deploy_${{ github.sha }}.zip backend -x "*/__pycache__/*" "*.pyc"

# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v2
# with:
# aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
# aws-region: us-east-1

# - name: Upload to S3
# run: |
# aws s3 cp fastapi_deploy_${{ github.sha }}.zip s3://terraform-state-chefit-notprowler/fastapi/fastapi_deploy_${{ github.sha }}.zip

# - name: Create new application version
# run: |
# aws elasticbeanstalk create-application-version \
# --application-name chefit-backend \
# --source-bundle S3Bucket="terraform-state-chefit-notprowler",S3Key=fastapi/fastapi_deploy_${{ github.sha }}.zip \
# --version-label "ver-${{ github.sha }}" \
# --description "FastAPI deploy at commit ${{ github.sha }}"

# - name: Deploy to environment
# run: |
# aws elasticbeanstalk update-environment \
# --environment-name fastapi-env \
# --version-label "ver-${{ github.sha }}"
88 changes: 88 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# # This workflow will provision the infrastructure necessary to deploy.

# name: terraform

# on:
# push:
# branches: [ main ]
# paths:
# - 'terraform/*'
# - '.github/workflows/terraform.yml'
# pull_request:
# branches: [ main ]
# paths:
# - 'terraform/*'
# - '.github/workflows/terraform.yml'
# jobs:
# format:
# permissions:
# contents: write
# runs-on: ubuntu-latest

# name: Format

# steps:
# # Clone the repository.
# - uses: actions/checkout@v4
# with:
# # This is required or we end up in detached head state & thus cannot push any changes.
# ref: ${{ github.head_ref }}
# # Download & set up the terraform CLI.
# - name: Set up terraform CLI
# uses: hashicorp/setup-terraform@v3

# - run: terraform fmt -check
# working-directory: ./terraform
# id: fmt
# continue-on-error: ${{ github.event_name == 'pull_request' }}

# - name: update pr
# if: ${{ steps.fmt.outcome == 'failure' && github.event_name == 'pull_request' }}
# run: |
# terraform fmt
# git config --global user.name "terraform-fmt"
# git config --global user.email "noreply@corise.com"
# git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
# git commit -am "fixup: terraform fmt"
# git push
# working-directory: ./terraform
# terraform:

# runs-on: ubuntu-latest

# name: Validate, Plan, and Apply
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}

# steps:
# - uses: actions/checkout@v4
# # Download & set up the terraform CLI.
# - name: Set up terraform CLI
# uses: hashicorp/setup-terraform@v3
# # Initialize terraform.
# - name: terraform init
# working-directory: ./terraform
# id: init
# run: terraform init -input=false
# - name: terraform validate
# working-directory: ./terraform
# if: ${{ github.event_name == 'pull_request' }}
# run: terraform validate -no-color
# - name: terraform plan
# working-directory: ./terraform
# id: plan
# if: ${{ github.event_name == 'pull_request' }}
# run: terraform plan -no-color -input=false
# continue-on-error: true
# - name: pass or fail
# uses: actions/github-script@v6
# if: ${{ steps.plan.outcome == 'failure' }}
# with:
# script: |
# core.setFailed('Plan failed!')
# - name: terraform apply
# id: apply
# working-directory: ./terraform
# if: github.event_name == 'pull_request'
# run: terraform apply -auto-approve -input=false
12 changes: 12 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
zip -r "chefit-backend-$1.zip" ./backend

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a copy and paste and definitely doesn't work since you don't have permissions to the flaskbbapp

this file actually has no role in deployment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @navteniev This file is not being used in the workflow.


aws s3 cp "flaskbb_deploy-$1.zip" s3://flaskbbapp

aws elasticbeanstalk create-application-version \
--application-name chefit-backend \
--version-label "ver-$1" \
--source-bundle S3Bucket=terraform-state-chefit-notprowler,S3Key=fastapi/fastapi-app.zip

aws elasticbeanstalk update-environment \
--environment-name fastapi-env \
--version-label "ver-$1"
24 changes: 24 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions terraform/.terraform/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be stored on aws.

"version": 3,
"terraform_version": "1.12.0",
"backend": {
"type": "s3",
"config": {
"access_key": null,
"acl": null,
"allowed_account_ids": null,
"assume_role": null,
"assume_role_with_web_identity": null,
"bucket": "terraform-state-chefit-notprowler",
"custom_ca_bundle": null,
"dynamodb_endpoint": null,
"dynamodb_table": null,
"ec2_metadata_service_endpoint": null,
"ec2_metadata_service_endpoint_mode": null,
"encrypt": null,
"endpoint": null,
"endpoints": null,
"forbidden_account_ids": null,
"force_path_style": null,
"http_proxy": null,
"https_proxy": null,
"iam_endpoint": null,
"insecure": null,
"key": "fastapi/terraform.tfstate",
"kms_key_id": null,
"max_retries": null,
"no_proxy": null,
"profile": null,
"region": "us-east-1",
"retry_mode": null,
"secret_key": null,
"shared_config_files": null,
"shared_credentials_file": null,
"shared_credentials_files": null,
"skip_credentials_validation": null,
"skip_metadata_api_check": null,
"skip_region_validation": null,
"skip_requesting_account_id": null,
"skip_s3_checksum": null,
"sse_customer_key": null,
"sts_endpoint": null,
"sts_region": null,
"token": null,
"use_dualstack_endpoint": null,
"use_fips_endpoint": null,
"use_lockfile": null,
"use_path_style": null,
"workspace_key_prefix": null
},
"hash": 1465801253
}
}
7 changes: 7 additions & 0 deletions terraform/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
backend "s3" {
bucket = "terraform-state-chefit-notprowler"
key = "fastapi/terraform.tfstate"
region = "us-east-1"
}
}
22 changes: 22 additions & 0 deletions terraform/elastic_beanstalk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# resource "aws_elastic_beanstalk_application" "application" {
# name = "chefit-backend"
# }

# resource "aws_elastic_beanstalk_environment" "environment" {
# name = "fastapi-env"
# cname_prefix = "notprowlerfastapi"
# application = aws_elastic_beanstalk_application.application.name
# solution_stack_name = "64bit Amazon Linux 2023 v4.5.1 running Python 3.11"

# setting {
# namespace = "aws:autoscaling:launchconfiguration"
# name = "IamInstanceProfile"
# value = "aws-elasticbeanstalk-ec2-role"
# }

# setting {
# namespace = "aws:elasticbeanstalk:container:python"
# name = "WSGIPath"
# value = "main:app"
# }
# }
3 changes: 3 additions & 0 deletions terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "us-east-1"
}