Skip to content

Commit

Permalink
first commint
Browse files Browse the repository at this point in the history
first commit

Signed-off-by: tunguyen4585 <n.van.tu0909@gmail.com>
  • Loading branch information
tunguyen4585 committed May 21, 2024
1 parent c38cdd2 commit 67f1602
Show file tree
Hide file tree
Showing 9 changed files with 1,473 additions and 34 deletions.
32 changes: 32 additions & 0 deletions .github/actions/backend/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Backend setup'
description: 'Setup python, caches and installs pip dependencies'

runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: '3.10'
cache: 'pipenv'
- run: echo 'Cache hit ${{ steps.setup_python.outputs.cache-hit }}' # true if cache-hit occurred on the primary key
shell: bash

- name: Install pipenv
working-directory: backend
run: pip install pipenv
shell: bash

# - name: Cache Pipenv dependencies
# uses: actions/cache@v3
# with:
# path: ~/.local/share/virtualenvs
# key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-pipenv-

- name: Install Dependencies
working-directory: backend
run: pipenv install --dev
shell: bash
37 changes: 37 additions & 0 deletions .github/actions/frontend/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Frontend setup'
description: 'Sets up Node.js, caches and installs npm dependencies'

runs:
using: "composite"
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
cache-dependency-path: ./frontend/package-lock.json

# - name: Cache node modules
# id: cache-npm # use later to check if cache hit
# uses: actions/cache@v3
# env:
# cache-name: cache-node-modules
# with:
# # npm cache files are stored in `~/.npm` on Linux/macOS
# path: ~/.npm
# key: ${{ runner.os }}-node-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-node-${{ env.cache-name }}-
# ${{ runner.os }}-node-

# - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
# name: List the state of node modules
# continue-on-error: true
# working-directory: ./frontend
# run: npm list
# shell: bash

- name: Install the dependencies.
working-directory: ./frontend
run: npm ci --loglevel=error --no-fund
shell: bash
98 changes: 98 additions & 0 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Backend Continuous Deployment

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
Linting:
runs-on: ubuntu-latest
environment: Devlopmnet Environment

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Rependencies
working-directory: starter/backend
run: |
python -m pip install --upgrade pip
pip install pipenv
pip install flake8
- name: Checkout Run Lint
run: cd starter/backend && pipenv run lint

Test:
runs-on: ubuntu-latest

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Use Python 3
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Dependencies
working-directory: starter/backend
run: |
python -m pip install --upgrade pip
pip install pipenv
pip install flake8
- name: Test
run: cd starter/backend && pipenv install pytest && pipenv run test


Build:
needs: [Linting, Test]
runs-on: ubuntu-latest

steps:
- name: Check the Repository
uses: actions/checkout@v3



- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{secrets.AWS_SESSION_TOKEN}}
aws-region: us-east-1

- name: Login to Amazon
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build and Push Docker Image
working-directory: starter/backend
env:
IMAGE_TAG: latest
REPO_NAME: backend
run: |
docker build --build-arg=REACT_APP_MOVIE_API_URL=http://localhost:5000 --tag 669172573612.dkr.ecr.us-east-1.amazonaws.com/$REPO_NAME:$IMAGE_TAG .
docker push 669172573612.dkr.ecr.us-east-1.amazonaws.com/$REPO_NAME:$IMAGE_TAG
- name: Update Kubeconfig
run:
aws eks update-kubeconfig --name udacity-project4 --region us-east-1

- name: Deploy Docker Image to Amazon EKS
working-directory: starter/backend/k8s
env:
IMAGE_TAG: latest
REPO_NAME: backend
run: |
aws eks update-kubeconfig --name udacity-project4 --region us-east-1
kustomize edit set image backend=669172573612.dkr.ecr.us-east-1.amazonaws.com/$REPO_NAME:$IMAGE_TAG
kustomize build | kubectl apply -f -
67 changes: 67 additions & 0 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Backend Continuous Integration

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
Linting:
runs-on: ubuntu-latest
environment: Devlopmnet Environment

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Dependencies
working-directory: starter/backend
run: |
python -m pip install --upgrade pip
pip install pipenv
pip install flake8
- name: Checkout Run Lint
run: cd starter/backend && pipenv run lint

Test:
runs-on: ubuntu-latest

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Use Python 3
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Dependencies
working-directory: starter/backend
run: |
python -m pip install --upgrade pip
pip install pipenv
pip install flake8
- name: Test
run: cd starter/backend && pipenv install pytest && pipenv run test


Build:
needs: [Linting, Test]
runs-on: ubuntu-latest

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Build Docker Image
run: |
cd starter/backend
docker build --tag mp-backend:latest .
107 changes: 107 additions & 0 deletions .github/workflows/frontend-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Frontend Continuous Deployment

on:
workflow_dispatch:
push:
branches:
- main

jobs:
Linting:
runs-on: ubuntu-latest
environment: Devlopmnet Environment

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
cache-dependency-path: starter/frontend/package-lock.json

- name: Install Dependencies
working-directory: starter/frontend
run: npm ci

- name: Checkout Run Lint
run: cd starter/frontend && npm run lint

Test:
runs-on: ubuntu-latest

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
cache-dependency-path: starter/frontend/package-lock.json

- name: Install Dependencies
working-directory: starter/frontend
run: npm ci

- name: Test
run: cd starter/frontend && npm run test



Build:
needs: [Linting, Test]
runs-on: ubuntu-latest

steps:
- name: Check the Repository
uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
cache-dependency-path: starter/frontend/package-lock.json

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{secrets.AWS_SESSION_TOKEN}}
aws-region: us-east-1


- name: Login to Amazon
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2



- name: Build and Push Docker Image
working-directory: starter/frontend
env:
IMAGE_TAG: latest
REPO_NAME: frontend
run: |
docker build --build-arg=REACT_APP_MOVIE_API_URL=http://localhost:5000 --tag 669172573612.dkr.ecr.us-east-1.amazonaws.com/$REPO_NAME:$IMAGE_TAG .
docker push 669172573612.dkr.ecr.us-east-1.amazonaws.com/$REPO_NAME:$IMAGE_TAG

- name: Configure Kubeconfig
run:
aws eks update-kubeconfig --name udacity-project4 --region us-east-1


- name: Deploy Docker Image to Amazon EKS
working-directory: starter/frontend/k8s
env:
IMAGE_TAG: latest
REPO_NAME: frontend
run: |
kustomize edit set image frontend=669172573612.dkr.ecr.us-east-1.amazonaws.com/$REPO_NAME:$IMAGE_TAG
kustomize build | kubectl apply -f -
Loading

0 comments on commit 67f1602

Please sign in to comment.