* call jan api * fix lint * ci: add jan server web * chore: add Dockerfile * clean up ui ux and support for reasoning fields, make app spa * add logo * chore: update tag for preview image * chore: update k8s service name * chore: update image tag and image name * fixed test --------- Co-authored-by: Minh141120 <minh.itptit@gmail.com> Co-authored-by: Nguyen Ngoc Minh <91668012+Minh141120@users.noreply.github.com>
118 lines
4.6 KiB
YAML
118 lines
4.6 KiB
YAML
name: Jan Web Server build image and push to Harbor Registry
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- dev
|
|
pull_request:
|
|
branches:
|
|
- dev
|
|
|
|
jobs:
|
|
build-and-preview:
|
|
runs-on: [ubuntu-24-04-docker]
|
|
permissions:
|
|
pull-requests: write
|
|
contents: write
|
|
steps:
|
|
- name: Checkout source repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to Harbor Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: registry.menlo.ai
|
|
username: ${{ secrets.HARBOR_USERNAME }}
|
|
password: ${{ secrets.HARBOR_PASSWORD }}
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
|
|
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
|
|
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
|
|
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
|
|
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
|
|
&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \
|
|
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
|
|
&& sudo apt update \
|
|
&& sudo apt install gh -y
|
|
sudo apt-get update
|
|
sudo apt-get install -y jq gettext
|
|
|
|
- name: Set image tag and service name
|
|
id: vars
|
|
run: |
|
|
SERVICE_NAME=jan-server-web
|
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
IMAGE_TAG="web:preview-${{ github.sha }}"
|
|
else
|
|
IMAGE_TAG="web:dev-${{ github.sha }}"
|
|
fi
|
|
echo "SERVICE_NAME=${SERVICE_NAME}" >> $GITHUB_OUTPUT
|
|
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
echo "FULL_IMAGE=registry.menlo.ai/jan-server/${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build docker image
|
|
run: |
|
|
docker build -t ${{ steps.vars.outputs.FULL_IMAGE }} .
|
|
|
|
- name: Push docker image
|
|
run: |
|
|
docker push ${{ steps.vars.outputs.FULL_IMAGE }}
|
|
|
|
- name: Checkout preview URL repo
|
|
if: github.event_name == 'pull_request'
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: menloresearch/infra-domains
|
|
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
|
|
path: preview-repo
|
|
|
|
- name: Generate preview manifest
|
|
if: github.event_name == 'pull_request'
|
|
run: |
|
|
cd preview-repo/kubernetes
|
|
bash template/generate.sh \
|
|
template/preview-url-template.yaml \
|
|
preview-url/pr-${{ github.sha }}-${{ steps.vars.outputs.SERVICE_NAME }}.yaml \
|
|
${{ github.sha }} \
|
|
${{ steps.vars.outputs.SERVICE_NAME }} \
|
|
${{ steps.vars.outputs.FULL_IMAGE }} \
|
|
80
|
|
|
|
- name: Commit and push preview manifest
|
|
if: github.event_name == 'pull_request'
|
|
run: |
|
|
cd preview-repo
|
|
git config user.name "preview-bot"
|
|
git config user.email "preview-bot@users.noreply.github.com"
|
|
git add kubernetes/preview-url/pr-${{ github.sha }}-${{ steps.vars.outputs.SERVICE_NAME }}.yaml
|
|
git commit -m "feat(preview): add pr-${{ github.sha }}-${{ steps.vars.outputs.SERVICE_NAME }}.yaml"
|
|
git push origin main
|
|
sleep 180
|
|
|
|
- name: Comment preview URL on PR
|
|
if: github.event_name == 'pull_request'
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
DOMAIN="https://pr-${{ github.sha }}-${{ steps.vars.outputs.SERVICE_NAME }}.menlo.ai"
|
|
COMMENT_BODY="🌐 Preview available: [${DOMAIN}](${DOMAIN})"
|
|
|
|
echo "🔍 Looking for existing preview comment..."
|
|
|
|
COMMENT_ID=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
|
|
--jq '.[] | select(.user.login=="github-actions[bot]") | select(.body | contains("<!-- preview-url -->")) | .id')
|
|
|
|
if [[ -n "$COMMENT_ID" ]]; then
|
|
echo "✏️ Updating existing comment ID $COMMENT_ID"
|
|
gh api repos/${{ github.repository }}/issues/comments/${COMMENT_ID} \
|
|
--method PATCH \
|
|
--field "body=${COMMENT_BODY}"
|
|
else
|
|
echo "💬 Creating new comment"
|
|
gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
|
|
--method POST \
|
|
--field "body=${COMMENT_BODY}"
|
|
fi
|