Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/f/ci cd v2 #3

Merged
merged 25 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a8c194c
Added initial flow to build and push image to ECR
informatter Mar 14, 2024
c5a0e7d
Made deploy backend job dependent on linting
informatter Mar 14, 2024
5fd019c
changed configure-aws-credential to v1 from v4
informatter Mar 14, 2024
93ad7d7
modified the deploy_backend job so the working dir is set to the back…
informatter Mar 14, 2024
bbb524b
c
informatter Mar 14, 2024
e27cd47
c
informatter Mar 14, 2024
1d6feb6
updates to ci/cd file
informatter Mar 15, 2024
e5f9370
updates to ci/cd file
informatter Mar 15, 2024
f260132
updates to ci/cd file
informatter Mar 15, 2024
960403c
updates to ci/cd file
informatter Mar 15, 2024
5fab7a7
updates to ci/cd file
informatter Mar 15, 2024
539ac2b
updates to ci/cd file
informatter Mar 15, 2024
27c46fc
updates to ci/cd file
informatter Mar 15, 2024
28a7475
updates to ci/cd file
informatter Mar 15, 2024
938ebad
updates to ci/cd file
informatter Mar 15, 2024
e56c2ae
updates to ci/cd file
informatter Mar 15, 2024
9b81b70
updates to ci/cd file
informatter Mar 15, 2024
4b904b7
updates to ci/cd file
informatter Mar 15, 2024
5187b50
updates to ci/cd file
informatter Mar 15, 2024
6933a9a
updates to ci/cd file
informatter Mar 15, 2024
356593b
updates to ci/cd file
informatter Mar 15, 2024
8e2faea
updates to ci/cd file
informatter Mar 15, 2024
af39809
updates to ci/cd file
informatter Mar 15, 2024
32e2ea6
The deploy_backend job will only run un push events
informatter Mar 15, 2024
91071b5
Finalized v2 of CI/CD pipeline for the backend, uses GitHub's Open ID…
informatter Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 66 additions & 19 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
branches:
- develop

env:
PYTHON_VERSION: "3.11.7"
POETRY_VERSION: "1.8.2"

jobs:
lint_backend:
name: Lint Backend
Expand All @@ -22,34 +26,77 @@ jobs:
#sets the working directory to the backend dir for all the lint_backend job
working-directory: ./backend
steps:
- name: Checkout Repository
uses: actions/checkout@v4
#- name: Checkout Repository
- uses: actions/checkout@v4
- name: Install poetry
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
poetry --version

- name: Set up Python
uses: actions/setup-python@v4
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: "3.11.7" # Use the appropriate Python version
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry' # caching poetry dependencies note: poetry.lock file needs to be present before running poetry install. i.e do not ignore it in the .gitignore file

- name: Display Python version
run: python --version

- name: Install Poetry
run: |
ls -la .
pip install poetry

- name: Print Poetry Version
run: poetry --version
- name: Install Poetry Dependencies
run: |
poetry install

- name: Install Dependencies
run: poetry install --without dev --no-root
- name: Run Linting
id: backend_linting_step
run: |
poetry run ruff check .
poetry run pyright .
poetry run bandit -r .

deploy_backend:
needs: lint_backend
if: ${{github.event_name == 'push' }}
name: Deploy Backend
runs-on: ubuntu-latest
permissions:
id-token: write
#contents: read
defaults:
run:
#sets the working directory to the backend dir for all the lint_backend job
working-directory: ./backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check Directory Contents
run: ls -la
- name: Branch used
id: extract_branch_name
run: |
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
echo "::set-output name=branch::$(echo ${GITHUB_REF##*/})"
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
echo "::set-output name=branch::$(echo $GITHUB_BASE_REF)"
else
echo "::set-output name=branch::INVALID_EVENT_BRANCH_UNKNOWN"
fi

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
#arn:aws:iam::${{secrets.AWS_ACCOUNT_ID}}:user/github-actions-image-push
role-to-assume: arn:aws:iam::${{secrets.AWS_ACCOUNT_ID}}:role/GithHubActionsInformatter
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build And Push Image to AWS ECR
env:
IMAGE_TAG: ${{ steps.extract_branch_name.outputs.branch }}
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: sample-ai-rag-app
run: |
docker build --build-arg="POETRY_VERSION=${{env.POETRY_VERSION}}" -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f backend.dockerfile .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG


# TODO
# lint_frontend:
Expand Down
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**/__pycache__/
__pycache__
.env*
poetry.lock
#poetry.lock
tests/
.github/
.venv/
Expand Down
1 change: 1 addition & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@




4 changes: 3 additions & 1 deletion backend/backend.dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM python:3.11-buster as builder

ARG POETRY_VERSION=1.7.1

ENV POETRY_NO_INTERACTION=1 \
POETRY_VERSION=1.7.1 \
POETRY_VERSION=${POETRY_VERSION} \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR=/tmp/poetry_cache \
Expand Down
Loading