Skip to content

Commit 1327ae4

Browse files
authored
Merge pull request #57 from jaseci-labs/56-littlex-deployment-in-jaseci-cloud
56 littlex deployment in jaseci cloud
2 parents 774b3b7 + 84be251 commit 1327ae4

File tree

6 files changed

+301
-0
lines changed

6 files changed

+301
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
name: Build and Deploy littleX
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions:
9+
id-token: write
10+
contents: read
11+
12+
jobs:
13+
deploy-littleX: # TODO: need to change the tags below
14+
if: startsWith(github.ref, 'refs/tags/littleX-') || startsWith(github.ref, 'refs/tags/v')
15+
runs-on: ubuntu-latest
16+
outputs:
17+
tag: ${{ steps.tag.outputs.tag }}
18+
19+
permissions:
20+
id-token: write
21+
contents: read
22+
23+
steps:
24+
# Checkout the repository
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
# Set up QEMU for multi-architecture builds
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
# Set up Docker Buildx for multi-architecture builds
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
# Configure AWS credentials
37+
- name: Configure AWS Credentials
38+
uses: aws-actions/[email protected]
39+
with:
40+
aws-region: us-east-2
41+
role-to-assume: arn:aws:iam::776241927220:role/GitHubActionsSharedECRRole
42+
role-session-name: GitHubActions
43+
audience: sts.amazonaws.com
44+
45+
- name: Debug AWS Credentials
46+
run: |
47+
aws sts get-caller-identity
48+
49+
- name: Debug OIDC Token
50+
run: |
51+
echo "OIDC_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
52+
curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com"
53+
54+
# Login to AWS ECR
55+
- name: Login to Amazon ECR
56+
id: login-ecr
57+
uses: aws-actions/amazon-ecr-login@v2
58+
59+
# Extract tag name from GitHub ref
60+
- name: Get tag name
61+
id: tag
62+
run: |
63+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
64+
# Manual dispatch - use timestamp
65+
TAG="manual-$(date +%Y%m%d-%H%M%S)"
66+
elif [[ "${{ github.event_name }}" == "release" ]]; then
67+
# Release event - clean tag name
68+
TAG_NAME=${GITHUB_REF#refs/tags/}
69+
70+
# Remove prefixes: littleX-v1.2.3 -> v1.2.3 or littleX-1.2.3 -> 1.2.3
71+
if [[ $TAG_NAME =~ ^littleX-(.+)$ ]]; then
72+
TAG="${BASH_REMATCH[1]}"
73+
elif [[ $TAG_NAME =~ ^v(.+)$ ]]; then
74+
TAG="$TAG_NAME"
75+
else
76+
# Use tag as-is if no prefix
77+
TAG="$TAG_NAME"
78+
fi
79+
else
80+
# Fallback
81+
TAG="latest"
82+
fi
83+
84+
echo "Tag: $TAG"
85+
echo "Event: ${{ github.event_name }}"
86+
echo "Original Tag Name: ${TAG_NAME:-N/A}"
87+
echo "tag=$TAG" >> $GITHUB_OUTPUT
88+
89+
# Build and push Docker image
90+
- name: Build and push Docker image
91+
env:
92+
ECR_REGISTRY: 776241927220.dkr.ecr.us-east-2.amazonaws.com
93+
ECR_REPOSITORY: littleX/jac
94+
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
95+
run: |
96+
echo "Building and pushing to: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
97+
98+
# Build and push multi-architecture image
99+
docker buildx build \
100+
--platform linux/amd64 \
101+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
102+
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
103+
--push \
104+
.
105+
working-directory: littleX_BE
106+
107+
deploy-littleX-webapp: # TODO: need to change the tags below
108+
if: startsWith(github.ref, 'refs/tags/littleX-') || startsWith(github.ref, 'refs/tags/v')
109+
runs-on: ubuntu-latest
110+
outputs:
111+
tag: ${{ steps.tag.outputs.tag }}
112+
113+
permissions:
114+
id-token: write
115+
contents: read
116+
117+
steps:
118+
# Checkout the repository
119+
- name: Checkout code
120+
uses: actions/checkout@v4
121+
122+
# Set up QEMU for multi-architecture builds
123+
- name: Set up QEMU
124+
uses: docker/setup-qemu-action@v3
125+
126+
# Set up Docker Buildx for multi-architecture builds
127+
- name: Set up Docker Buildx
128+
uses: docker/setup-buildx-action@v3
129+
130+
# Configure AWS credentials
131+
- name: Configure AWS Credentials
132+
uses: aws-actions/[email protected]
133+
with:
134+
aws-region: us-east-2
135+
role-to-assume: arn:aws:iam::776241927220:role/GitHubActionsSharedECRRole
136+
role-session-name: GitHubActions
137+
audience: sts.amazonaws.com
138+
139+
- name: Debug AWS Credentials
140+
run: |
141+
aws sts get-caller-identity
142+
143+
- name: Debug OIDC Token
144+
run: |
145+
echo "OIDC_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
146+
curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com"
147+
148+
# Login to AWS ECR
149+
- name: Login to Amazon ECR
150+
id: login-ecr
151+
uses: aws-actions/amazon-ecr-login@v2
152+
153+
# Extract tag name from GitHub ref
154+
- name: Get tag name
155+
id: tag
156+
run: |
157+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
158+
# Manual dispatch - use timestamp
159+
TAG="manual-$(date +%Y%m%d-%H%M%S)"
160+
elif [[ "${{ github.event_name }}" == "release" ]]; then
161+
# Release event - clean tag name
162+
TAG_NAME=${GITHUB_REF#refs/tags/}
163+
164+
# Remove prefixes: littleX-v1.2.3 -> v1.2.3 or littleX-1.2.3 -> 1.2.3
165+
if [[ $TAG_NAME =~ ^littleX-(.+)$ ]]; then
166+
TAG="${BASH_REMATCH[1]}"
167+
elif [[ $TAG_NAME =~ ^v(.+)$ ]]; then
168+
TAG="$TAG_NAME"
169+
else
170+
# Use tag as-is if no prefix
171+
TAG="$TAG_NAME"
172+
fi
173+
else
174+
# Fallback
175+
TAG="latest"
176+
fi
177+
178+
echo "Tag: $TAG"
179+
echo "Event: ${{ github.event_name }}"
180+
echo "Original Tag Name: ${TAG_NAME:-N/A}"
181+
echo "tag=$TAG" >> $GITHUB_OUTPUT
182+
183+
# Build and push webapp Docker image
184+
- name: Build and push webapp Docker image
185+
env:
186+
ECR_REGISTRY: 776241927220.dkr.ecr.us-east-2.amazonaws.com
187+
ECR_REPOSITORY: littleX/webapp
188+
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
189+
run: | #TODO: this is not a vite application but next based frontend
190+
echo "Building and pushing webapp to: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
191+
# Build and push AMD64-only image (following deployment template)
192+
docker buildx build \
193+
--platform linux/amd64 \
194+
--build-arg VITE_API_URL=https://littleX-api.jaseci.org \
195+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
196+
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
197+
--push \
198+
.
199+
working-directory: littleX_BE
200+
201+
summary:
202+
needs: [deploy-littleX, deploy-littleX-webapp]
203+
runs-on: ubuntu-latest
204+
if: always()
205+
steps:
206+
- name: Build and Push Summary
207+
run: |
208+
echo "## littleX Build and Push Summary" >> $GITHUB_STEP_SUMMARY
209+
echo "### Backend (JAC Server)" >> $GITHUB_STEP_SUMMARY
210+
echo "- **Image Tag**: ${{ needs.deploy-littleX.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
211+
echo "- **ECR Repository**: 776241927220.dkr.ecr.us-east-2.amazonaws.com/littleX/jac" >> $GITHUB_STEP_SUMMARY
212+
echo "- **Status**: ${{ needs.deploy-littleX.result }}" >> $GITHUB_STEP_SUMMARY
213+
echo "- **API Endpoint**: https://littleX-api.jaseci.org" >> $GITHUB_STEP_SUMMARY
214+
echo "" >> $GITHUB_STEP_SUMMARY
215+
echo "### Frontend (Webapp)" >> $GITHUB_STEP_SUMMARY
216+
echo "- **Image Tag**: ${{ needs.deploy-littleX-webapp.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
217+
echo "- **ECR Repository**: 776241927220.dkr.ecr.us-east-2.amazonaws.com/littleX/webapp" >> $GITHUB_STEP_SUMMARY
218+
echo "- **Status**: ${{ needs.deploy-littleX-webapp.result }}" >> $GITHUB_STEP_SUMMARY
219+
echo "- **Frontend URL**: https://X.jaseci.org" >> $GITHUB_STEP_SUMMARY
220+
echo "" >> $GITHUB_STEP_SUMMARY
221+
echo "**Note**: Deployment will be handled automatically by Flux in the infrastructure repository." >> $GITHUB_STEP_SUMMARY

littleX_BE/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEMINI_API_KEY

littleX_BE/dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use Python 3.12 slim image as base
2+
FROM python:3.12-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
build-essential \
10+
curl \
11+
git \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Copy requirements file
15+
COPY requirements.txt .
16+
17+
# Install Python dependencies
18+
RUN pip install --no-cache-dir --upgrade pip && \
19+
pip install --no-cache-dir -r requirements.txt
20+
21+
# Copy the application code
22+
COPY . .
23+
24+
# Expose port 8000 (default for jac serve)
25+
EXPOSE 8000
26+
27+
# Set the default command to serve the jac application
28+
CMD ["jac", "serve", "littleX.jac", "--host", "0.0.0.0", "--port", "8000"]

littleX_BE/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
byllm
2+
jaclang
23
jac-cloud
34
# openai
45
#ollama
56
pillow
67
scikit-learn
78
numpy
89
# sentence_transformers
10+
python-dotenv
11+
requests

littleX_FE/dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#TODO: need to include a dockerfile for littleXFE

littleX_FE/nginx.conf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
include /etc/nginx/mime.types;
7+
default_type application/octet-stream;
8+
9+
# Enable gzip compression
10+
gzip on;
11+
gzip_vary on;
12+
gzip_min_length 1024;
13+
gzip_types
14+
text/plain
15+
text/css
16+
text/xml
17+
text/javascript
18+
application/javascript
19+
application/xml+rss
20+
application/json;
21+
22+
server {
23+
listen 80;
24+
server_name localhost;
25+
26+
root /usr/share/nginx/html;
27+
index index.html;
28+
29+
# Handle client-side routing
30+
location / {
31+
try_files $uri $uri/ /index.html;
32+
}
33+
34+
# Cache static assets
35+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
36+
expires 1y;
37+
add_header Cache-Control "public, immutable";
38+
}
39+
40+
# Security headers
41+
add_header X-Frame-Options "SAMEORIGIN" always;
42+
add_header X-XSS-Protection "1; mode=block" always;
43+
add_header X-Content-Type-Options "nosniff" always;
44+
add_header Referrer-Policy "no-referrer-when-downgrade" always;
45+
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
46+
}
47+
}

0 commit comments

Comments
 (0)