Skip to content

Merge branch 'lc3' into dev #56

Merge branch 'lc3' into dev

Merge branch 'lc3' into dev #56

Workflow file for this run

# Name of the workflow
name: DEV | Deploy AugmentOS Cloud 🚀☁️
# Trigger on pushes to dev branch
on:
push:
branches: [ "dev" ]
# Optionally, filter paths if you only want to deploy on changes to augmentos_cloud
paths:
- 'augmentos_cloud/**'
# We use two jobs: build and deploy, for modularity and future scalability
jobs:
build_and_test:
name: Build & Test
runs-on: ubuntu-latest
env:
# (Optional) Specify Node environment, could also set BUN_ENV if needed.
NODE_ENV: development
# If Bun version is to be pinned, we can specify it here.
BUN_VERSION: # e.g. "1.2.0" or leave blank for latest
steps:
# 1. Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch only the last commit for efficiency
fetch-depth: 1
# 2. Set up Bun runtime on the CI runner
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION || 'latest' }}
# ^ This installs Bun on the runner, allowing us to use the `bun` command​:contentReference[oaicite:15]{index=15}.
# 3. Restore cached dependencies to speed up build if possible
- name: Cache Bun dependencies
uses: actions/cache@v4
with:
# Path to Bun's global package cache on the runner
path: ~/.bun/install/cache
# Key includes OS and lockfile hash. If bun.lockb (lockfile) hasn't changed, cache hits.
key: ${{ runner.os }}-bun-${{ hashFiles('augmentos_cloud/bun.lockb') }}
# In case of partial match, allow restore with just OS identifier (fallback).
restore-keys: |
${{ runner.os }}-bun-
# ^ Uses GitHub cache to store Bun's package cache for faster installs​:contentReference[oaicite:16]{index=16}.
# 4. Install project dependencies using Bun
- name: Install Dependencies
working-directory: augmentos_cloud
run: bun install
# ^ Installs NPM packages. Bun uses its lockfile to ensure deterministic installs.
# If cache was restored, this will be fast as packages are already downloaded.
# 5. Run linter to ensure code quality
# - name: Lint code
# working-directory: augmentos_cloud
# run: bun run lint
# ^ Runs the lint script (assumes package.json has a "lint" script or use bunx directly for ESLint).
# Linting is done before tests to fail fast on syntax/style issues​:contentReference[oaicite:17]{index=17}.
# 6. Run tests to verify functionality
# - name: Run tests
# working-directory: augmentos_cloud
# run: bun run test
# ^ Executes the test suite (e.g., via Jest, Bun's built-in test runner, or another framework).
# If any tests fail, the job (and workflow) will fail, preventing deployment.
# 7. (Optional) Build step for production
# - name: Build project
# working-directory: augmentos_cloud
# run: bun run dev
# ^ If the server requires a build (e.g., TypeScript compilation or bundling), do it here.
# If not needed, this step can be removed or left as a no-op.
# (Optional) You could add a step to upload build artifacts if you plan to use them in deploy job.
# - name: Upload artifact
# uses: actions/upload-artifact@v3
# with:
# name: augmentos_build
# path: augmentos_cloud/**
deploy:
name: Deploy to Azure VM
needs: build_and_test # Only run if build_and_test job succeeded
runs-on: ubuntu-latest
# We don't set env here to avoid exposing secrets via env. We'll pass secrets directly.
steps:
# 1. (Optional) Checkout code again, if we need the files in this job
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
# We could also use the artifact from previous job instead of checking out again.
# In a monorepo, checkout ensures we have the latest from main for this job.
# 2. Copy files to Azure VM via SCP (Secure Copy over SSH)
- name: Copy files to VM
uses: appleboy/[email protected]
with:
host: ${{ secrets.AZURE_HOST }} # Azure VM IP or hostname
username: ${{ secrets.AZURE_USERNAME }} # SSH username on Azure VM
key: ${{ secrets.AZURE_DEV_RSA_KEY}} # Private SSH key for the VM (from secrets)
port: 22 # SSH port (default 22)
source: "augmentos_cloud/*" # What to copy (all files in server folder)
target: "~/augmentos_cloud/" # Where to copy on the VM (adjust path as needed)
rm: "true"
# ^ This uses a community action to securely copy the latest build files to the VM​:contentReference[oaicite:18]{index=18}.
# It removes existing files in target (rm: true) to ensure old files are cleaned up.
# Ensure the target directory exists on the VM. You might want to exclude certain files (like .env).
# 3. Run remote commands on the VM via SSH
- name: Install and Restart Server on VM
uses: appleboy/[email protected]
with:
host: ${{ secrets.AZURE_HOST }}
username: ${{ secrets.AZURE_USERNAME }}
key: ${{ secrets.AZURE_DEV_RSA_KEY }}
script: |
set -e # stop on error
cd ~/augmentos_cloud/
# Install production dependencies on VM (if needed, e.g., in case node_modules was not copied)
bun install --production
# (If using a package manager other than bun for install on VM, adjust accordingly, e.g., npm ci --only=production)
# Restart the Bun server process
# If managed by PM2:
bun run dev
# pm2 restart augmentos-cloud || pm2 start index.js --name augmentos-cloud
# If managed by systemd:
# sudo systemctl restart augmentos.service
# If no manager (not recommended for prod), run in background:
# pkill -f \"bun run start\" || true # ignore if not running
# nohup bun run start &>/dev/null &
# ^ Logs into the VM via SSH and runs the commands​:contentReference[oaicite:19]{index=19}:
# - Navigates to the app directory on the VM.
# - Installs dependencies (using bun) in production mode.
# - Restarts the application. (The example shows placeholders for PM2 or systemd; adapt to your setup.)
# Ensure your VM user has permission to restart the service (if using sudo, the user must be in sudoers).
# The bun server will be back up and running with the new code after this step.
# 4. (Optional) Post-deployment verification or notifications
- name: Slack Trigger
run: curl -f ${{ secrets.SLACK_DEV_DEPLOY_WEBHOOK }} || exit 1
# - name: Health check
# run: curl -f http://your-app-url/health || exit 1
# - name: Notify Slack
# uses: slackapi/[email protected]
# with:
# channel-id: C12345678
# slack-message: "Deployed Bun server to Azure VM successfully."
# slack-bot-token: ${{ secrets.SLACK_TOKEN }}