diff --git a/.github/workflows/deploy_aws.yml b/.github/workflows/deploy_aws.yml new file mode 100644 index 0000000..7e531f2 --- /dev/null +++ b/.github/workflows/deploy_aws.yml @@ -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 }}" \ No newline at end of file diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 0000000..ca8b3a6 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -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 diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..a77c83f --- /dev/null +++ b/deploy.sh @@ -0,0 +1,12 @@ +zip -r "chefit-backend-$1.zip" ./backend + +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" diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..f95e4b3 --- /dev/null +++ b/terraform/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.98.0" + hashes = [ + "h1:/RMObGCrfJlVoQCf9h88hFkSyLafDXnw6r0yi4gpO80=", + "zh:23377bd90204b6203b904f48f53edcae3294eb072d8fc18a4531c0cde531a3a1", + "zh:2e55a6ea14cc43b08cf82d43063e96c5c2f58ee953c2628523d0ee918fe3b609", + "zh:4885a817c16fdaaeddc5031edc9594c1f300db0e5b23be7cd76a473e7dcc7b4f", + "zh:6ca7177ad4e5c9d93dee4be1ac0792b37107df04657fddfe0c976f36abdd18b5", + "zh:78bf8eb0a67bae5dede09666676c7a38c9fb8d1b80a90ba06cf36ae268257d6f", + "zh:874b5a99457a3f88e2915df8773120846b63d820868a8f43082193f3dc84adcb", + "zh:95e1e4cf587cde4537ac9dfee9e94270652c812ab31fce3a431778c053abf354", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:a75145b58b241d64570803e6565c72467cd664633df32678755b51871f553e50", + "zh:aa31b13d0b0e8432940d6892a48b6268721fa54a02ed62ee42745186ee32f58d", + "zh:ae4565770f76672ce8e96528cbb66afdade1f91383123c079c7fdeafcb3d2877", + "zh:b99f042c45bf6aa69dd73f3f6d9cbe0b495b30442c526e0b3810089c059ba724", + "zh:bbb38e86d926ef101cefafe8fe090c57f2b1356eac9fc5ec81af310c50375897", + "zh:d03c89988ba4a0bd3cfc8659f951183ae7027aa8018a7ca1e53a300944af59cb", + "zh:d179ef28843fe663fc63169291a211898199009f0d3f63f0a6f65349e77727ec", + ] +} diff --git a/terraform/.terraform/terraform.tfstate b/terraform/.terraform/terraform.tfstate new file mode 100644 index 0000000..3cfcb20 --- /dev/null +++ b/terraform/.terraform/terraform.tfstate @@ -0,0 +1,55 @@ +{ + "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 + } +} \ No newline at end of file diff --git a/terraform/backend.tf b/terraform/backend.tf new file mode 100644 index 0000000..54a383f --- /dev/null +++ b/terraform/backend.tf @@ -0,0 +1,7 @@ +terraform { + backend "s3" { + bucket = "terraform-state-chefit-notprowler" + key = "fastapi/terraform.tfstate" + region = "us-east-1" + } +} diff --git a/terraform/elastic_beanstalk.tf b/terraform/elastic_beanstalk.tf new file mode 100644 index 0000000..f374418 --- /dev/null +++ b/terraform/elastic_beanstalk.tf @@ -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" +# } +# } diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..c125940 --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "us-east-1" +}