-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (92 loc) · 3.67 KB
/
frontend_ci_cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
paths-ignore:
- "backend/**"
# 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 .