Skip to content

Commit 91a09e3

Browse files
authored
Enhance/production (#199)
* 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
1 parent 690c999 commit 91a09e3

File tree

2 files changed

+79
-7
lines changed

2 files changed

+79
-7
lines changed

.github/workflows/push_release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy Release to ECR
2+
on:
3+
# release:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch: # Allow manual invocation of the workflow
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
with:
21+
persist-credentials: false
22+
23+
- name: Get the tag version
24+
id: get_version
25+
run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//}
26+
27+
- name: Configure AWS credentials
28+
id: aws-credentials
29+
uses: aws-actions/configure-aws-credentials@v4
30+
with:
31+
# role-to-assume: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
32+
aws-region: "us-east-1"
33+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
34+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
35+
36+
- name: Login to Amazon ECR
37+
id: login-ecr
38+
uses: aws-actions/amazon-ecr-login@v2
39+
with:
40+
registry-type: public
41+
42+
- name: Build, tag, and push image to Amazon ECR
43+
id: build-image
44+
env:
45+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
46+
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
47+
IMAGE_TAG: ${{ steps.get_version.outputs.TAG_NAME }} #${{ github.sha }}
48+
run: |
49+
cp infrastructure/backend/Dockerfile ./Dockerfile
50+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
51+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
52+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
53+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
54+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
55+
echo "::set-output name=latest_image::$ECR_REGISTRY/$ECR_REPOSITORY:latest"

settings/prod_settings.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import os, environ
1+
import os
2+
from pathlib import Path
3+
4+
import environ
25

36
env = environ.Env()
47
environ.Env.read_env()
@@ -9,21 +12,35 @@
912
f'https://{os.environ.get("URL")}',
1013
f'https://{os.environ.get("PROXY_IP")}',
1114
]
15+
BASE_DIR = Path(__file__).resolve().parent.parent
16+
17+
DB_TYPE = os.environ.get("DATABASE_TYPE")
18+
DB_TYPE = DB_TYPE.lower() if DB_TYPE else "" # sqlite is disabled for production
19+
20+
DB_TYPE = "mysql" if DB_TYPE in ["mysql", "mariadb"] else DB_TYPE
1221

1322
DATABASES = {
1423
"default": {
15-
"ENGINE": "django.db.backends.mysql",
16-
"NAME": os.environ.get("DATABASE_NAME"),
17-
"USER": os.environ.get("DATABASE_USER"),
18-
"PASSWORD": os.environ.get("DATABASE_PASS"),
19-
"HOST": os.environ.get("DATABASE_HOST"),
20-
"PORT": os.environ.get("DATABASE_PORT") or 3306,
24+
"ENGINE": (
25+
"django.db.backends.postgresql_psycopg2"
26+
if DB_TYPE == "mysql"
27+
else "django.db.backends.postgresql"
28+
),
29+
"NAME": os.environ.get("DATABASE_NAME") or "myfinances_development",
30+
"USER": os.environ.get("DATABASE_USER") or "root",
31+
"PASSWORD": os.environ.get("DATABASE_PASS") or "",
32+
"HOST": os.environ.get("DATABASE_HOST") or "localhost",
33+
"PORT": os.environ.get("DATABASE_PORT")
34+
or (3306 if DB_TYPE == "mysql" else 5432),
2135
"OPTIONS": {
2236
"sql_mode": "traditional",
2337
},
2438
}
2539
}
2640

41+
print(f"[BACKEND] Using {DB_TYPE} database: {os.environ.get('DATABASE_NAME')}")
42+
43+
2744
ALLOWED_HOSTS = [os.environ.get("URL")]
2845

2946

0 commit comments

Comments
 (0)