From c7649d59b838eabd3fe30b741e50019ed0c3f627 Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:10:44 -0800 Subject: [PATCH 1/8] Deploy frontend --- .../{backend-ci.yml => backend/build.yml} | 24 ++++-- .github/workflows/build.yml | 24 ++++++ .../{frontend-ci.yml => frontend/build.yml} | 11 +-- .github/workflows/release.yml | 36 ++++++++ backend/core/settings.py | 37 ++++---- frontend/src/hooks/.keep | 0 frontend/src/pages/BidderLogInPage.jsx | 85 ------------------- frontend/src/utils/.keep | 0 8 files changed, 102 insertions(+), 115 deletions(-) rename .github/workflows/{backend-ci.yml => backend/build.yml} (74%) create mode 100644 .github/workflows/build.yml rename .github/workflows/{frontend-ci.yml => frontend/build.yml} (76%) create mode 100644 .github/workflows/release.yml delete mode 100644 frontend/src/hooks/.keep delete mode 100644 frontend/src/pages/BidderLogInPage.jsx delete mode 100644 frontend/src/utils/.keep diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend/build.yml similarity index 74% rename from .github/workflows/backend-ci.yml rename to .github/workflows/backend/build.yml index 1dc07c9..2b8e991 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend/build.yml @@ -1,10 +1,22 @@ -name: Build Pipeline for Python and Django +name: Backend Build Pipeline on: - push: - branches: [ main ] - pull_request: - branches: [ main ] + workflow_call: + inputs: + pythonVersion: + required: true + type: string + secrets: + SECRET_KEY: + required: true + AWS_ACCESS_KEY_ID: + required: true + AWS_SECRET_ACCESS_KEY: + required: true + AWS_STORAGE_BUCKET_NAME: + required: true + AWS_S3_REGION_NAME: + required: true jobs: build: @@ -15,7 +27,7 @@ jobs: working-directory: ./backend env: - SECRET_KEY: ${{ secrets.DJANGO_SECRET }} + SECRET_KEY: ${{ secrets.SECRET_KEY }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_STORAGE_BUCKET_NAME: ${{ secrets.AWS_STORAGE_BUCKET_NAME }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3e01ffb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: Build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + call-backend-build: + uses: ./.github/workflows/backend/build.yml + with: + pythonVersion: '3.10' + secrets: + SECRET_KEY: ${{ secrets.DJANGO_SECRET }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_STORAGE_BUCKET_NAME: ${{ secrets.AWS_STORAGE_BUCKET_NAME }} + AWS_S3_REGION_NAME: ${{ secrets.AWS_S3_REGION_NAME }} + + call-frontend-build: + uses: ./.github/workflows/frontend/build.yml + with: + nodeVersion: '20.x' \ No newline at end of file diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend/build.yml similarity index 76% rename from .github/workflows/frontend-ci.yml rename to .github/workflows/frontend/build.yml index bb829e6..32fc49d 100644 --- a/.github/workflows/frontend-ci.yml +++ b/.github/workflows/frontend/build.yml @@ -1,10 +1,11 @@ -name: Build Pipeline for Node and React +name: Frontend Build Pipeline on: - push: - branches: [ main ] - pull_request: - branches: [ main ] + workflow_call: + inputs: + nodeVersion: + required: true + type: string jobs: build: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..49bd3f8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Deploy Frontend + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Install dependencies + run: npm install + + - name: Build app + run: npm run build + + - name: Upload to S3 + uses: jakejarvis/s3-sync-action@master + with: + args: --acl public-read + env: + SOURCE_DIR: build/ + AWS_S3_BUCKET: ${{ secrets.AWS_S3_FRONTEND_BUCKET }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/backend/core/settings.py b/backend/core/settings.py index f00be11..fd197a6 100644 --- a/backend/core/settings.py +++ b/backend/core/settings.py @@ -33,7 +33,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] # Application definition @@ -93,27 +93,26 @@ WSGI_APPLICATION = "core.wsgi.application" - # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases -"""""" -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), - }, -} - -""" - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': env("DB_NAME"), - 'USER': env("DB_USER"), - 'PASSWORD': env("DB_PASSWORD"), - 'HOST': env("DB_HOST"), - 'PORT': env("DB_PORT"), +if env("ENVIRONMENT") == 'prod': + DATABASES = { + "default": { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ.get('RDS_DB_NAME', 'your_database_name'), + 'USER': os.environ.get('RDS_USERNAME', 'your_username'), + 'PASSWORD': os.environ.get('RDS_PASSWORD', 'your_password'), + 'HOST': os.environ.get('RDS_HOSTNAME', 'your_rds_endpoint'), + 'PORT': os.environ.get('RDS_PORT', '5432'), + } + } +else: # Assuming 'dev' or any other value will use SQLite + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + }, } -""" # Password validation # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators diff --git a/frontend/src/hooks/.keep b/frontend/src/hooks/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/frontend/src/pages/BidderLogInPage.jsx b/frontend/src/pages/BidderLogInPage.jsx deleted file mode 100644 index 6817960..0000000 --- a/frontend/src/pages/BidderLogInPage.jsx +++ /dev/null @@ -1,85 +0,0 @@ -import React, { useState } from 'react'; -import { useNavigate } from 'react-router'; -import logo from '../assets/microvan_logo.svg'; -import OnboardingInputField from '../components/inputs/OnboardingInputField'; -import LogInButton from '../components/buttons/LogInButton'; - -export default function BidderLogInPage() { - const navigate = useNavigate(); - - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - - const handleEmailChange = (event) => setEmail(event.target.value); - const handlePasswordChange = (event) => setPassword(event.target.value); - - const handleLogIn = () => { - console.log(`Email: ${email}, Password: ${password}`); // eslint-disable-line no-console - }; - - return ( -
-
- -
- -
- -
- logo -

- Microvan Inc. -

-

Virtual Auctions

-
-

Email

- -
-
-

Password

- -
-
- -
- -
- -
- -
-

- © Microvan Inc. 2024 -

-
-
- ); -} diff --git a/frontend/src/utils/.keep b/frontend/src/utils/.keep deleted file mode 100644 index e69de29..0000000 From 10112db8b2873e8958350e85eb767e533a3a0936 Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:14:06 -0800 Subject: [PATCH 2/8] Fix --- .../{backend/build.yml => backend-build.yml} | 0 .github/workflows/build.yml | 4 +- .../build.yml => frontend-build.yml} | 0 .github/workflows/release.yml | 6 +- frontend/src/hooks/.gitkeep | 0 frontend/src/pages/BidderLogInPage.jsx | 85 +++++++++++++++++++ frontend/src/utils/.gitkeep | 0 7 files changed, 90 insertions(+), 5 deletions(-) rename .github/workflows/{backend/build.yml => backend-build.yml} (100%) rename .github/workflows/{frontend/build.yml => frontend-build.yml} (100%) create mode 100644 frontend/src/hooks/.gitkeep create mode 100644 frontend/src/pages/BidderLogInPage.jsx create mode 100644 frontend/src/utils/.gitkeep diff --git a/.github/workflows/backend/build.yml b/.github/workflows/backend-build.yml similarity index 100% rename from .github/workflows/backend/build.yml rename to .github/workflows/backend-build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e01ffb..e96aaf8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: jobs: call-backend-build: - uses: ./.github/workflows/backend/build.yml + uses: ./.github/workflows/backend-build.yml with: pythonVersion: '3.10' secrets: @@ -19,6 +19,6 @@ jobs: AWS_S3_REGION_NAME: ${{ secrets.AWS_S3_REGION_NAME }} call-frontend-build: - uses: ./.github/workflows/frontend/build.yml + uses: ./.github/workflows/frontend-build.yml with: nodeVersion: '20.x' \ No newline at end of file diff --git a/.github/workflows/frontend/build.yml b/.github/workflows/frontend-build.yml similarity index 100% rename from .github/workflows/frontend/build.yml rename to .github/workflows/frontend-build.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 49bd3f8..360e3cf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,12 +12,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: - node-version: '14' + node-version: '20.x' - name: Install dependencies run: npm install diff --git a/frontend/src/hooks/.gitkeep b/frontend/src/hooks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/pages/BidderLogInPage.jsx b/frontend/src/pages/BidderLogInPage.jsx new file mode 100644 index 0000000..c9c61ff --- /dev/null +++ b/frontend/src/pages/BidderLogInPage.jsx @@ -0,0 +1,85 @@ +import React, { useState } from 'react'; +import { useNavigate } from 'react-router'; +import logo from '../assets/microvan_logo.svg'; +import OnboardingInputField from '../components/inputs/OnboardingInputField'; +import LogInButton from '../components/buttons/LogInButton'; + +export default function BidderLogInPage() { + const navigate = useNavigate(); + + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + + const handleEmailChange = (event) => setEmail(event.target.value); + const handlePasswordChange = (event) => setPassword(event.target.value); + + const handleLogIn = () => { + console.log(`Email: ${email}, Password: ${password}`); // eslint-disable-line no-console + }; + + return ( +
+
+ +
+ +
+ +
+ logo +

+ Microvan Inc. +

+

Virtual Auctions

+
+

Email

+ +
+
+

Password

+ +
+
+ +
+ +
+ +
+ +
+

+ © Microvan Inc. 2024 +

+
+
+ ); +} \ No newline at end of file diff --git a/frontend/src/utils/.gitkeep b/frontend/src/utils/.gitkeep new file mode 100644 index 0000000..e69de29 From 60bd30e36fbebd7f5aca7e7d556a4584108f94cd Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:15:01 -0800 Subject: [PATCH 3/8] Fix path --- .github/workflows/release.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 360e3cf..83876e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,10 @@ on: jobs: build: runs-on: ubuntu-latest + defaults: + run: + shell: bash + working-directory: ./frontend steps: - name: Checkout code From f0f5b15bfc49ff89776ce7664f5b29531622b5ed Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:19:58 -0800 Subject: [PATCH 4/8] Fix environment --- .github/workflows/backend-build.yml | 3 +++ .github/workflows/build.yml | 1 + 2 files changed, 4 insertions(+) diff --git a/.github/workflows/backend-build.yml b/.github/workflows/backend-build.yml index 2b8e991..2db6b93 100644 --- a/.github/workflows/backend-build.yml +++ b/.github/workflows/backend-build.yml @@ -6,6 +6,9 @@ on: pythonVersion: required: true type: string + environment: + required: true + type: string secrets: SECRET_KEY: required: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e96aaf8..e6fbcf7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,7 @@ jobs: uses: ./.github/workflows/backend-build.yml with: pythonVersion: '3.10' + environment: ${{ github.event_name == 'push' && 'prod' || 'dev' }} secrets: SECRET_KEY: ${{ secrets.DJANGO_SECRET }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} From 7734ec4faa50d8e08cdafef37818fa2d07333623 Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:20:37 -0800 Subject: [PATCH 5/8] Fix variables --- .github/workflows/backend-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend-build.yml b/.github/workflows/backend-build.yml index 2db6b93..50e778f 100644 --- a/.github/workflows/backend-build.yml +++ b/.github/workflows/backend-build.yml @@ -35,6 +35,7 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_STORAGE_BUCKET_NAME: ${{ secrets.AWS_STORAGE_BUCKET_NAME }} AWS_S3_REGION_NAME: ${{ secrets.AWS_S3_REGION_NAME }} + ENVIRONMENT: ${{ github.event.inputs.environment }} steps: - uses: actions/checkout@v4 @@ -42,7 +43,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v3 with: - python-version: '3.10' + python-version: ${{ github.event.inputs.pythonVersion }} - name: Install pipenv run: | From d00531719db977fb02976ec4a77dc14e430d38a5 Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:22:27 -0800 Subject: [PATCH 6/8] Fix path --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 83876e1..29d8dc8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: with: args: --acl public-read env: - SOURCE_DIR: build/ + SOURCE_DIR: frontend/build/ AWS_S3_BUCKET: ${{ secrets.AWS_S3_FRONTEND_BUCKET }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From 47953469bd6356a56015a1eb78b7cab9f3862b1b Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 15:27:21 -0800 Subject: [PATCH 7/8] Add button for testing --- frontend/src/pages/HomePage.jsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/pages/HomePage.jsx b/frontend/src/pages/HomePage.jsx index 1af1311..13d4656 100644 --- a/frontend/src/pages/HomePage.jsx +++ b/frontend/src/pages/HomePage.jsx @@ -1,10 +1,14 @@ import React from 'react'; +import { useNavigate } from "react-router"; import NavBar from '../components/nav-bar/NavBar'; export default function HomePage() { + const navigate = useNavigate(); + return (
+
); } From a99978414961149b1bbadd6ad1721dccdc8b93a9 Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Sun, 4 Feb 2024 16:36:36 -0800 Subject: [PATCH 8/8] Add deploy resources --- .github/workflows/release.yml | 68 ++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29d8dc8..d5e3f7d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Deploy Frontend +name: Deploy Resources on: push: @@ -7,7 +7,8 @@ on: branches: [ "main" ] jobs: - build: + deploy-frontend: + name: Deploy Frontend runs-on: ubuntu-latest defaults: run: @@ -22,19 +23,62 @@ jobs: uses: actions/setup-node@v3 with: node-version: '20.x' - + - name: Install dependencies run: npm install - - - name: Build app + + - name: Build the project run: npm run build - - name: Upload to S3 - uses: jakejarvis/s3-sync-action@master + - 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: ap-southeast-1 + + - name: Install AWS Amplify CLI + run: npm install -g @aws-amplify/cli + + - name: Deploy to Amplify + run: | + amplify init --yes + amplify publish --yes + + create-release: + name: Create Release + runs-on: ubuntu-latest + needs: [ deploy-frontend ] + steps: + - name: Checkout code + uses: actions/checkout@v4 with: - args: --acl public-read + fetch-depth: 0 + + - name: Prepare release + id: prep_release + run: | + # Example script to generate tag and release notes, needs to be customized + TAG_NAME=$(git tag --sort=-v:refname | head -n 1 | awk -F '.' '{print $1 "." $2+1}') + if [ -z "$TAG_NAME" ]; then + TAG_NAME="1.0" + fi + RELEASE_NOTES=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline) + if [ -z "$RELEASE_NOTES" ]; then + RELEASE_NOTES="Initial release" + fi + echo "::set-output name=tag_name::$TAG_NAME" + echo "::set-output name=release_notes::$RELEASE_NOTES" + shell: bash + + - name: Create GitHub Release + uses: actions/create-release@v1 env: - SOURCE_DIR: frontend/build/ - AWS_S3_BUCKET: ${{ secrets.AWS_S3_FRONTEND_BUCKET }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.prep_release.outputs.tag_name }} + release_name: Release ${{ steps.prep_release.outputs.tag_name }} + body: ${{ steps.prep_release.outputs.release_notes }} + draft: false + prerelease: false +