|
| 1 | +# Name of the workflow |
| 2 | +name: Deploy AugmentOS Cloud ☁️ Dev environment |
| 3 | + |
| 4 | +# Trigger on pushes to isaiah/cloud branch |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [ "isaiah/cloud" ] |
| 8 | + # Optionally, filter paths if you only want to deploy on changes to augmentos_cloud |
| 9 | + # paths: |
| 10 | + # - 'augmentos_cloud/**' |
| 11 | + |
| 12 | +# We use two jobs: build and deploy, for modularity and future scalability |
| 13 | +jobs: |
| 14 | + build_and_test: |
| 15 | + name: Build & Test |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + # (Optional) Specify Node environment, could also set BUN_ENV if needed. |
| 19 | + NODE_ENV: development |
| 20 | + # If Bun version is to be pinned, we can specify it here. |
| 21 | + BUN_VERSION: # e.g. "1.2.0" or leave blank for latest |
| 22 | + steps: |
| 23 | + # 1. Checkout the repository |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + # Fetch only the last commit for efficiency |
| 28 | + fetch-depth: 1 |
| 29 | + |
| 30 | + # 2. Set up Bun runtime on the CI runner |
| 31 | + - name: Setup Bun |
| 32 | + uses: oven-sh/setup-bun@v2 |
| 33 | + with: |
| 34 | + bun-version: ${{ env.BUN_VERSION || 'latest' }} |
| 35 | + # ^ This installs Bun on the runner, allowing us to use the `bun` command​:contentReference[oaicite:15]{index=15}. |
| 36 | + |
| 37 | + # 3. Restore cached dependencies to speed up build if possible |
| 38 | + - name: Cache Bun dependencies |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + # Path to Bun's global package cache on the runner |
| 42 | + path: ~/.bun/install/cache |
| 43 | + # Key includes OS and lockfile hash. If bun.lockb (lockfile) hasn't changed, cache hits. |
| 44 | + key: ${{ runner.os }}-bun-${{ hashFiles('augmentos_cloud/bun.lockb') }} |
| 45 | + # In case of partial match, allow restore with just OS identifier (fallback). |
| 46 | + restore-keys: | |
| 47 | + ${{ runner.os }}-bun- |
| 48 | + # ^ Uses GitHub cache to store Bun's package cache for faster installs​:contentReference[oaicite:16]{index=16}. |
| 49 | + |
| 50 | + # 4. Install project dependencies using Bun |
| 51 | + - name: Install Dependencies |
| 52 | + working-directory: augmentos_cloud |
| 53 | + run: bun install |
| 54 | + # ^ Installs NPM packages. Bun uses its lockfile to ensure deterministic installs. |
| 55 | + # If cache was restored, this will be fast as packages are already downloaded. |
| 56 | + |
| 57 | + # 5. Run linter to ensure code quality |
| 58 | + - name: Lint code |
| 59 | + working-directory: augmentos_cloud |
| 60 | + run: bun run lint |
| 61 | + # ^ Runs the lint script (assumes package.json has a "lint" script or use bunx directly for ESLint). |
| 62 | + # Linting is done before tests to fail fast on syntax/style issues​:contentReference[oaicite:17]{index=17}. |
| 63 | + |
| 64 | + # 6. Run tests to verify functionality |
| 65 | + - name: Run tests |
| 66 | + working-directory: augmentos_cloud |
| 67 | + run: bun run test |
| 68 | + # ^ Executes the test suite (e.g., via Jest, Bun's built-in test runner, or another framework). |
| 69 | + # If any tests fail, the job (and workflow) will fail, preventing deployment. |
| 70 | + |
| 71 | + # 7. (Optional) Build step for production |
| 72 | + - name: Build project |
| 73 | + working-directory: augmentos_cloud |
| 74 | + run: bun run build |
| 75 | + # ^ If the server requires a build (e.g., TypeScript compilation or bundling), do it here. |
| 76 | + # If not needed, this step can be removed or left as a no-op. |
| 77 | + |
| 78 | + # (Optional) You could add a step to upload build artifacts if you plan to use them in deploy job. |
| 79 | + # - name: Upload artifact |
| 80 | + # uses: actions/upload-artifact@v3 |
| 81 | + # with: |
| 82 | + # name: augmentos_build |
| 83 | + # path: augmentos_cloud/** |
| 84 | + |
| 85 | + deploy: |
| 86 | + name: Deploy to Azure VM |
| 87 | + needs: build_and_test # Only run if build_and_test job succeeded |
| 88 | + runs-on: ubuntu-latest |
| 89 | + # We don't set env here to avoid exposing secrets via env. We'll pass secrets directly. |
| 90 | + steps: |
| 91 | + # 1. (Optional) Checkout code again, if we need the files in this job |
| 92 | + - name: Checkout code |
| 93 | + uses: actions/checkout@v4 |
| 94 | + with: |
| 95 | + fetch-depth: 1 |
| 96 | + # We could also use the artifact from previous job instead of checking out again. |
| 97 | + # In a monorepo, checkout ensures we have the latest from main for this job. |
| 98 | + |
| 99 | + # 2. Copy files to Azure VM via SCP (Secure Copy over SSH) |
| 100 | + - name: Copy files to VM |
| 101 | + |
| 102 | + with: |
| 103 | + host: ${{ secrets.AZURE_HOST }} # Azure VM IP or hostname |
| 104 | + username: ${{ secrets.AZURE_USERNAME }} # SSH username on Azure VM |
| 105 | + key: ${{ secrets.AZURE_DEV_RSA_KEY}} # Private SSH key for the VM (from secrets) |
| 106 | + port: 22 # SSH port (default 22) |
| 107 | + source: "augmentos_cloud/*" # What to copy (all files in server folder) |
| 108 | + target: "~/augmentos_cloud/" # Where to copy on the VM (adjust path as needed) |
| 109 | + rm: "true" |
| 110 | + # ^ This uses a community action to securely copy the latest build files to the VM​:contentReference[oaicite:18]{index=18}. |
| 111 | + # It removes existing files in target (rm: true) to ensure old files are cleaned up. |
| 112 | + # Ensure the target directory exists on the VM. You might want to exclude certain files (like .env). |
| 113 | + |
| 114 | + # 3. Run remote commands on the VM via SSH |
| 115 | + - name: Install and Restart Server on VM |
| 116 | + |
| 117 | + with: |
| 118 | + host: ${{ secrets.AZURE_HOST }} |
| 119 | + username: ${{ secrets.AZURE_USERNAME }} |
| 120 | + key: ${{ secrets.AZURE_DEV_RSA_KEY }} |
| 121 | + script: | |
| 122 | + set -e # stop on error |
| 123 | + cd ~/augmentos_cloud/ |
| 124 | + # Install production dependencies on VM (if needed, e.g., in case node_modules was not copied) |
| 125 | + bun install --production |
| 126 | + # (If using a package manager other than bun for install on VM, adjust accordingly, e.g., npm ci --only=production) |
| 127 | + # Restart the Bun server process |
| 128 | + # If managed by PM2: |
| 129 | + pm2 restart augmentos-cloud || pm2 start index.js --name augmentos-cloud |
| 130 | + # If managed by systemd: |
| 131 | + # sudo systemctl restart augmentos.service |
| 132 | + # If no manager (not recommended for prod), run in background: |
| 133 | + # pkill -f \"bun run start\" || true # ignore if not running |
| 134 | + # nohup bun run start &>/dev/null & |
| 135 | + # ^ Logs into the VM via SSH and runs the commands​:contentReference[oaicite:19]{index=19}: |
| 136 | + # - Navigates to the app directory on the VM. |
| 137 | + # - Installs dependencies (using bun) in production mode. |
| 138 | + # - Restarts the application. (The example shows placeholders for PM2 or systemd; adapt to your setup.) |
| 139 | + # Ensure your VM user has permission to restart the service (if using sudo, the user must be in sudoers). |
| 140 | + # The bun server will be back up and running with the new code after this step. |
| 141 | + |
| 142 | + # 4. (Optional) Post-deployment verification or notifications |
| 143 | + # - name: Health check |
| 144 | + # run: curl -f http://your-app-url/health || exit 1 |
| 145 | + # - name: Notify Slack |
| 146 | + # uses: slackapi/[email protected] |
| 147 | + # with: |
| 148 | + # channel-id: C12345678 |
| 149 | + # slack-message: "Deployed Bun server to Azure VM successfully." |
| 150 | + # slack-bot-token: ${{ secrets.SLACK_TOKEN }} |
| 151 | + |
0 commit comments