-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1. Updated README 2. added shell script to automate building the image for the frontend 3. Added initial CI/CD GitHubActions file 4. Modified the dockerfile so it uses the necessary environment variables to expose them to the image building process so they are available to the source code when the container is being run * Added comments * Moved github actions file from frontend dir to .github folder under root dir * set the default working directory for the ci/cd pipeline file for all jobs to the frontend directory in the project structure * small change * small change * small change * small change * small change * c
- Loading branch information
1 parent
b085516
commit 8299f7b
Showing
5 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Frontend CI/CD Pipeline | ||
# TODO run unit tests when available | ||
run-name: Triggered by ${{ github.actor }} | ||
on: | ||
push: | ||
# runs action on pushes to develop and master | ||
branches: | ||
- master | ||
- develop | ||
# runs action on PRs to develop | ||
pull_request: | ||
branches: | ||
- develop | ||
paths-ignore: | ||
- "backend/**" | ||
|
||
env: | ||
NODE_VERSION: "20" | ||
|
||
jobs: | ||
linting_and_tests: | ||
name: Linting & Unit Testing Frontend | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
#sets the working directory to the frontend for this job | ||
working-directory: ./frontend | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Check Directory Contents | ||
run: ls -la | ||
|
||
- name: Set up Node ${{env.NODE_VERSION}} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{env.NODE_VERSION}} | ||
cache: 'npm' | ||
cache-dependency-path: './frontend/package-lock.json' | ||
|
||
- name: Install Dependencies | ||
run: npm install | ||
- name: Check prettier version | ||
run: npx prettier --version | ||
- name: Run Linting | ||
run: | | ||
npm run lint | ||
npm run format-check | ||
- name: Run Unit Tests | ||
run: npm run test:unit | ||
|
||
# TODO we need to store env variables needed by the image as secrets in GitHub secrets | ||
# so they can be used when building the image | ||
deploy: | ||
if: ${{github.event_name == 'push' }} | ||
needs: linting_and_tests | ||
name: Deploy Frontend | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
defaults: | ||
run: | ||
#sets the working directory to the frontend dir for this job | ||
working-directory: ./frontend | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- 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: | ||
role-to-assume: arn:aws:iam::${{secrets.AWS_ACCOUNT_ID}}:role/GithHubActionsInformatter | ||
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 -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f frontend.dockerfile . | ||
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | ||
# TODO Use this command instead of the current build one: | ||
#docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG --build-arg VITE_API_SERVER_URL="$VITE_API_SERVER_URL" --build-arg VITE_AUTH0_CALLBACK_URL="$VITE_AUTH0_CALLBACK_URL" --build-arg VITE_AUTH0_DOMAIN="$VITE_AUTH0_DOMAIN" --build-arg VITE_AUTH0_CLIENT_ID="$VITE_AUTH0_CLIENT_ID" -f frontend.dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ docker-compose* | |
.gitignore | ||
README.md | ||
LICENSE | ||
.vscode | ||
.vscode | ||
.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# Export variables from .env file excluding comments | ||
export $(grep -v '^#' ../.env.local | xargs) | ||
|
||
# Substitute variables in frontend.dockerfile and save as frontend.build.dockerfile | ||
envsubst < frontend.dockerfile > frontend.build.dockerfile | ||
|
||
# Build Docker image using frontend.build.dockerfile | ||
docker build -t rag-app:local -f frontend.build.dockerfile . | ||
|
||
rm frontend.build.dockerfile | ||
|
||
# unset exported environment files from the .env.local file | ||
# Iterate through all environment variables to unset them | ||
for var in $(printenv | grep '^VITE_' | cut -d= -f1); do | ||
unset $var | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters