-
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.
chore: update project settings and dependencies
feat: add dockerization and CI/CD pipeline refactor: improve code quality and error handling docs: update documentation and project description
- Loading branch information
Showing
22 changed files
with
8,395 additions
and
9,921 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,11 @@ | ||
--- | ||
'unai-api': patch | ||
--- | ||
|
||
chore: update project settings and dependencies | ||
|
||
feat: add dockerization and CI/CD pipeline | ||
|
||
refactor: improve code quality and error handling | ||
|
||
docs: update documentation and project description |
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,25 @@ | ||
# Nitro dev/build outputs | ||
.data | ||
.output | ||
.nitro | ||
.cache | ||
dist | ||
|
||
# Node dependencies | ||
node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Misc | ||
.DS_Store | ||
.fleet | ||
.idea | ||
|
||
# Local env files | ||
.env | ||
.env.* | ||
|
||
.dockerignore | ||
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
PORT= | ||
PRESET= | ||
FIREBASE_CONFIG= | ||
STORAGE_BUCKET= | ||
QDRANT_URL= | ||
|
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 |
---|---|---|
@@ -1,60 +1,123 @@ | ||
name: Nitro CD | ||
run-name: ${{ github.ref_name }} | ||
|
||
on: | ||
release: | ||
types: [published] | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
REPO: ${{ github.repository }} | ||
REGISTRY: ${{ vars.REGISTRY }} | ||
USERNAME: ${{ vars.USERNAME }} | ||
PORT: ${{ vars.PORT }} | ||
NODE_ENV: production | ||
NITRO_PRESET: ${{ vars.NITRO_PRESET }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-24.04 | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
outputs: | ||
image_name: ${{ steps.metadata.outputs.image_name }} | ||
image_title: ${{ steps.metadata.outputs.image_title }} | ||
buildtime: ${{ steps.metadata.outputs.buildtime }} | ||
version: ${{ steps.metadata.outputs.version }} | ||
|
||
steps: | ||
- name: Checkout Repo | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
node-version: '20.x' | ||
cache: 'npm' | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ env.USERNAME }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Install Dependencies | ||
run: npm ci | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.REPO }} | ||
tags: | | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=sha,prefix=sha-,format=short | ||
- name: Bulid Artifacts | ||
run: npm run build | ||
- name: Set tags as environment variable | ||
id: metadata | ||
run: | | ||
echo "Setting metadata to env variables" | ||
echo "image_name=${{ fromJSON(steps.meta.outputs.json).tags[0] }}" >> $GITHUB_OUTPUT | ||
echo "image_title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }}" >> $GITHUB_OUTPUT | ||
echo "buildtime=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}" >> $GITHUB_OUTPUT | ||
echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> $GITHUB_OUTPUT | ||
- name: Wrap Inside a artifact folder | ||
run: mkdir artifact && mv .output artifact/.output | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
VERSION=${{ steps.metadata.outputs.version }} | ||
BUILD_TIME=${{ steps.metadata.outputs.buildtime }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
- name: Generate artifact attestation | ||
uses: actions/attest-build-provenance@v1 | ||
with: | ||
name: artifact | ||
path: | | ||
artifact | ||
if-no-files-found: error | ||
subject-name: ${{ env.REGISTRY }}/${{ env.REPO }} | ||
subject-digest: ${{ steps.push.outputs.digest }} | ||
push-to-registry: false | ||
|
||
deploy: | ||
needs: build | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
runs-on: ubuntu-latest | ||
|
||
- name: Upload artifact to VPS | ||
uses: appleboy/scp-action@v0.1.7 | ||
steps: | ||
- name: Deploy to VPS | ||
uses: appleboy/ssh-action@v1.1.0 | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
port: 22 | ||
source: artifact/* | ||
target: ~/api-vision/ | ||
rm: true | ||
overwrite: true | ||
strip_components: 1 | ||
host: ${{ secrets.VPS_HOST }} | ||
username: ${{ secrets.VPS_USERNAME }} | ||
password: ${{ secrets.VPS_PASSWORD }} | ||
script: | | ||
# Pull new image | ||
docker pull ${{ needs.build_web.outputs.image_name }} | ||
# Stop the existing container | ||
docker stop ${{ needs.build_web.outputs.image_title }} || true | ||
docker rm ${{ needs.build_web.outputs.image_title }} || true | ||
# Create and start new container | ||
docker run --detach \ | ||
--name ${{ needs.build_web.outputs.image_title }} \ | ||
--restart unless-stopped \ | ||
--mount type=bind,source=$(pwd)/${{ needs.build_web.outputs.image_title }}/static,target=/app/static,readonly \ | ||
--env-file ~/${{ needs.build_web.outputs.image_title }}/.env.prod \ | ||
-p ${{ env.PORT }}:3000 \ | ||
${{ needs.build_web.outputs.image_name }} | ||
# Clean up unused images | ||
docker image prune -f |
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
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,4 @@ | ||
#!/usr/bin/env sh | ||
|
||
#Lint Commit | ||
pnpm dlx commitlint --edit $1 |
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,20 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Get the list of staged files | ||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') | ||
|
||
# Run gitleaks on each staged file using --no-git | ||
for file in $STAGED_FILES; do | ||
if [[ -f "$file" ]]; then | ||
gitleaks detect --source="$file" --no-git --no-banner --verbose | ||
fi | ||
done | ||
|
||
# Lint the staged files | ||
pnpm lint $STAGED_FILES | ||
|
||
# Format the staged files, ignoring unknown files | ||
pnpm format $STAGED_FILES --ignore-unknown | ||
|
||
# Update the index to mark the changes in the staged files | ||
git update-index --again |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM node:lts-alpine AS builder | ||
|
||
RUN corepack enable | ||
|
||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json pnpm-lock.yaml ./ | ||
|
||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
COPY . . | ||
|
||
RUN pnpm build | ||
|
||
FROM node:lts-alpine AS runner | ||
|
||
ARG VERSION | ||
ARG BUILD_TIME | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/.output ./.output | ||
|
||
ENV NODE_ENV=production | ||
ENV NUXT_APP_VERSION=$VERSION | ||
|
||
EXPOSE 3000 | ||
|
||
ENTRYPOINT ["node", ".output/server/index.mjs"] |
Oops, something went wrong.