Skip to content

Commit

Permalink
Enhance/production (#199)
Browse files Browse the repository at this point in the history
* Updated prod_settings databases

* Testing GH Actions

* Testing GH Actions

* Testing GH Actions

* Testing GH Actions

* Testing GH Actions

* Testing GH Actions

* Testing GH Actions

* Changed to "release"

* Ran black formatter

* Setting to "latest" for now

* Now only on tags (not just releases), and push two versions (latest and version)

* ran black formatter
  • Loading branch information
TreyWW authored Feb 11, 2024
1 parent 690c999 commit 91a09e3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 7 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/push_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy Release to ECR
on:
# release:
push:
tags:
- '*'
workflow_dispatch: # Allow manual invocation of the workflow

jobs:
deploy:
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Get the tag version
id: get_version
run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//}

- name: Configure AWS credentials
id: aws-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
# role-to-assume: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
aws-region: "us-east-1"
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ steps.get_version.outputs.TAG_NAME }} #${{ github.sha }}
run: |
cp infrastructure/backend/Dockerfile ./Dockerfile
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "::set-output name=latest_image::$ECR_REGISTRY/$ECR_REPOSITORY:latest"
31 changes: 24 additions & 7 deletions settings/prod_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os, environ
import os
from pathlib import Path

import environ

env = environ.Env()
environ.Env.read_env()
Expand All @@ -9,21 +12,35 @@
f'https://{os.environ.get("URL")}',
f'https://{os.environ.get("PROXY_IP")}',
]
BASE_DIR = Path(__file__).resolve().parent.parent

DB_TYPE = os.environ.get("DATABASE_TYPE")
DB_TYPE = DB_TYPE.lower() if DB_TYPE else "" # sqlite is disabled for production

DB_TYPE = "mysql" if DB_TYPE in ["mysql", "mariadb"] else DB_TYPE

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": os.environ.get("DATABASE_NAME"),
"USER": os.environ.get("DATABASE_USER"),
"PASSWORD": os.environ.get("DATABASE_PASS"),
"HOST": os.environ.get("DATABASE_HOST"),
"PORT": os.environ.get("DATABASE_PORT") or 3306,
"ENGINE": (
"django.db.backends.postgresql_psycopg2"
if DB_TYPE == "mysql"
else "django.db.backends.postgresql"
),
"NAME": os.environ.get("DATABASE_NAME") or "myfinances_development",
"USER": os.environ.get("DATABASE_USER") or "root",
"PASSWORD": os.environ.get("DATABASE_PASS") or "",
"HOST": os.environ.get("DATABASE_HOST") or "localhost",
"PORT": os.environ.get("DATABASE_PORT")
or (3306 if DB_TYPE == "mysql" else 5432),
"OPTIONS": {
"sql_mode": "traditional",
},
}
}

print(f"[BACKEND] Using {DB_TYPE} database: {os.environ.get('DATABASE_NAME')}")


ALLOWED_HOSTS = [os.environ.get("URL")]


Expand Down

0 comments on commit 91a09e3

Please sign in to comment.