diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index a0cb60102e27..0e827eb3523d 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -1,147 +1,265 @@ -Here's an updated `cmake-single-platform.yml` workflow that builds your CMake project with SLSA Level 3 provenance and enhanced security: +We'll set up a GitHub Actions workflow to deploy your Nuxt application to GitHub Pages. The example below uses the official `github_pages` preset for optimal compatibility. + +### 📁 Workflow file: `.github/workflows/deploy.yml` ```yaml -name: CMake Build (Single Platform) with SLSA L3 +name: Deploy Nuxt to GitHub Pages on: push: - branches: [main] - pull_request: - release: - types: [published] - workflow_dispatch: - -permissions: - id-token: write # OIDC token for Sigstore signing - contents: read # Minimal read-only access - packages: write # Only needed if publishing packages + branches: [main] # Trigger on pushes to main branch + workflow_dispatch: # Allow manual trigger jobs: - cmake-build: + build: runs-on: ubuntu-latest - outputs: - base64-subjects: ${{ steps.hashes.outputs.base64_subjects }} - artifacts-name: artifacts-${{ github.run_id }} - steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - run: corepack enable # Ensures pnpm/yarn are available if needed + - uses: actions/setup-node@v4 with: - fetch-depth: 0 # Required for full commit history in provenance - - - name: Install dependencies - run: sudo apt-get update && sudo apt-get install -y build-essential cmake - - - name: Configure CMake - run: cmake -B build -DCMAKE_BUILD_TYPE=Release - - - name: Build project - run: cmake --build build --config Release --parallel 4 - - - name: Create artifacts directory - run: mkdir -p artifacts - - - name: Collect binaries - run: | - find build -type f -executable -exec cp {} artifacts/ \; - # Add other artifacts as needed (libraries, config files, etc.) - - - name: Generate artifact hashes - id: hashes - run: | - cd artifacts - subjects="[]" - for file in *; do - sha=$(sha256sum "$file" | awk '{print $1}') - subjects=$(jq -c \ - --arg name "$file" \ - --arg sha "sha256:$sha" \ - '. += [{"name": $name, "digest": $sha}]' \ - <<< "$subjects") - done - echo "base64_subjects=$(echo -n "$subjects" | base64 -w0)" >> $GITHUB_OUTPUT - - - name: Upload artifacts - uses: actions/upload-artifact@v4 + node-version: 20 + - run: npm ci # Clean install (use `npm install` if you prefer) + - run: npx nuxt build --preset github_pages + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 with: - name: ${{ steps.hashes.outputs.artifacts-name }} - path: artifacts/ - retention-days: 5 # Auto-clean old artifacts + path: ./.output/public - provenance: - needs: [cmake-build] - uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0 + deploy: + needs: build permissions: - id-token: write # For Sigstore signing - contents: write # For release assets - actions: read # For reusable workflow - with: - base64-subjects: ${{ needs.cmake-build.outputs.base64-subjects }} - upload-artifacts-name: ${{ needs.cmake-build.outputs.artifacts-name }} - upload-assets: ${{ github.event_name == 'release' && github.event.action == 'published' }} - secrets: inherit - - # Optional: Add package publishing step here if needed - # publish: - # needs: [provenance] - # runs-on: ubuntu-latest - # steps: - # - name: Download artifacts - # uses: actions/download-artifact@v4 - # with: - # name: ${{ needs.cmake-build.outputs.artifacts-name }} - # - # # Add your package publishing commands here + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 +``` + +### ⚙️ Required Nuxt configuration + +In your `nuxt.config.ts` (or `.js`), set the `baseURL` to match your repository name. Also avoid underscores in the build assets directory to prevent issues with GitHub Pages' Jekyll processing. + +```ts +export default defineNuxtConfig({ + app: { + baseURL: '/your-repo-name/', // Replace with your repository name + buildAssetsDir: 'assets' // Do NOT start with '_' + } +}) +``` + +### ✅ Prerequisites + +1. **Enable GitHub Pages** with **GitHub Actions** as the source: + Go to your repository **Settings → Pages → Build and deployment → Source** and select **GitHub Actions**. + +2. Ensure your default branch name matches the trigger (`main` in the example). Adjust if your branch is `master` or something else. + +3. Commit and push the workflow file and the updated `nuxt.config`. The next push to `main` will trigger a deployment. + +> If you were looking for a CMake workflow (you mentioned `cmake-single-platform.yml`), please clarify – but for Nuxt deployment to GitHub Pages, the above should work perfectly. +It looks like you're asking about setting up a **large database** in the context of your Nuxt project and GitHub Actions. I'll cover two common scenarios: + +1. **Using a database during CI/CD** (e.g., running tests that need a real database). +2. **Connecting your deployed Nuxt app to a production database** (a “big” managed database). + +--- + +## 1. Database in GitHub Actions (for testing/CI) + +If you need a database to run tests or seed data during your workflow, you can use GitHub Actions **service containers**. Below is an example that adds a PostgreSQL service to the `build` job of the Nuxt deployment workflow. + +### Example workflow with PostgreSQL + +```yaml +name: Deploy Nuxt + DB tests + +on: + push: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: testuser + POSTGRES_PASSWORD: testpass + POSTGRES_DB: testdb + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v4 + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm ci + # Run database migrations / seeding + - run: npx prisma migrate deploy # if using Prisma + - run: npm run test # tests that use the DB + - run: npx nuxt build --preset github_pages + - uses: actions/upload-pages-artifact@v3 + with: + path: ./.output/public + + deploy: # same as before + # ... ``` -### Key Features: - -1. **Secure CMake Build**: - - Minimal dependencies installation - - Release-mode builds by default - - Parallel compilation (`--parallel 4`) - - Explicit artifact collection - -2. **SLSA L3 Provenance**: - - Uses official SLSA generator v1.9.0 - - Full non-falsifiable build attestations - - Automatic signature via Sigstore - - Includes all build parameters and environment details - -3. **Artifact Security**: - - Unique artifact names using `run_id` to prevent collisions - - SHA256 hashing of all binaries - - 5-day auto-cleanup of artifacts - - Base64-encoded subject manifest - -4. **Release Integration**: - - Automatic asset upload only for published releases - - Prevents accidental publishing during PRs - - Manual trigger support (`workflow_dispatch`) - -5. **Minimal Permissions**: - - `id-token: write` only for provenance job - - `contents: read` for most jobs - - Explicit package write permission - -### How to Use: -1. Place this file in `.github/workflows/cmake-single-platform.yml` -2. Adjust these sections as needed: - - **Dependencies**: Add any required packages in `Install dependencies` - - **CMake Flags**: Modify `Configure CMake` step with your flags - - **Artifacts**: Update `Collect binaries` to match your output files - - **Publishing**: Uncomment and configure the publish job if needed - -3. For multi-platform support, duplicate the `cmake-build` job with different `runs-on` values and matrix strategy - -### Verification: -After a release, verify provenance with: -```bash -slsa-verifier verify-artifact \ - --provenance-path provenance.json \ - --source-uri github.com/$YOUR_REPO \ - --builder-id https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0 \ - YOUR_BINARY +**Environment variables** for your app (e.g., `DATABASE_URL`) can be set via the `env` context in the step that runs your app/tests. + +--- + +## 2. Production Database for Your Nuxt App + +If by “big database” you mean a production‑ready database (PostgreSQL, MySQL, MongoDB, etc.) that your deployed Nuxt app will use, you have several options: + +- **Managed cloud databases**: + - [Supabase](https://supabase.com/) (PostgreSQL, easy integration with Nuxt) + - [AWS RDS](https://aws.amazon.com/rds/) + - [Google Cloud SQL](https://cloud.google.com/sql) + - [MongoDB Atlas](https://www.mongodb.com/atlas) + +- **Database as a service with generous free tiers** (good for starting “big”): + - [Neon](https://neon.tech/) (serverless Postgres) + - [PlanetScale](https://planetscale.com/) (MySQL) + - [Supabase](https://supabase.com/) + +### Connecting to a production database from GitHub Pages + +GitHub Pages hosts **static files only**. If your Nuxt app is **static** (`npm run generate`), it cannot connect directly to a database on the client side. You have two approaches: + +1. **Use a serverless backend** (e.g., Supabase, Firebase, or your own API on a platform like Vercel/Railway) and call it from your static Nuxt app via `fetch`. +2. **Use Nuxt's server routes** (if you deploy on a Node.js environment like Vercel, Netlify, or a VPS). But GitHub Pages only serves static files, so server routes won't work there. + +If you need a **hybrid** or **server‑side rendered** app with a database, consider deploying to: +- [Vercel](https://vercel.com) (excellent Nuxt support) +- [Netlify](https://netlify.com) +- [Cloudflare Pages](https://pages.cloudflare.com) +- A VPS (DigitalOcean, Hetzner) with a Node.js server. + +Then, in your GitHub Actions, you can: +- Set the production `DATABASE_URL` as a [repository secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions). +- Pass it to the build step if needed (e.g., for prerendering dynamic routes). +- Or use it only when running migrations before deploying. + +### Example: Using a production database secret in GitHub Actions + +```yaml +- name: Run migrations on production DB + env: + DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }} + run: npx prisma migrate deploy ``` -This workflow provides cryptographic guarantees of build integrity while maintaining build performance and flexibility. +--- + +## 3. Need More Specifics? + +If you can clarify what you mean by “set all big database,” I can give more tailored guidance. For instance: + +- Are you looking to **run database migrations** as part of your GitHub Actions workflow? +- Do you want to **set up a database service** for testing? +- Are you trying to **connect your Nuxt app to a cloud database** in production? + +Just let me know! +I understand you'd like more specific guidance on integrating a database with your Nuxt app and GitHub Actions. To give you the most helpful answer, I need a bit more context. Could you clarify: + +1. **Where do you plan to deploy your Nuxt app?** + - GitHub Pages (static only) + - Vercel / Netlify (supports serverless functions) + - A VPS or Node.js hosting (full server) + +2. **What kind of database?** + - PostgreSQL, MySQL, MongoDB, SQLite, etc. + +3. **What do you mean by “set all big database”?** + - Do you want to **spin up a database during CI** (for testing)? + - Do you want to **connect your production app to a cloud database**? + - Do you need help with **migrations** or **seeding** in the workflow? + +4. **Are you using an ORM like Prisma, Drizzle, or direct database drivers?** + +Once I know these details, I can provide a **tailored, step-by-step guide**. + +In the meantime, here’s a **common, concrete scenario** (many Nuxt developers use this): + +--- + +### 🔥 Scenario: Static Nuxt app on GitHub Pages + Supabase (PostgreSQL) as backend + +**Goal:** +- Deploy static Nuxt site to GitHub Pages. +- Use Supabase as the “big database” (PostgreSQL with REST API). +- Fetch data client‑side or via Supabase client. + +**Why this works:** +- GitHub Pages serves static files. +- Supabase provides a database and an API – no server needed. +- You can manage schema and data through Supabase dashboard or migrations. + +#### Step‑by‑step: + +1. **Create a Supabase project** at [supabase.com](https://supabase.com). + - Get your project URL and anon/public key from **Settings → API**. + +2. **Install Supabase client** in your Nuxt app: + ```bash + npm install @supabase/supabase-js + ``` + +3. **Create a Supabase plugin** (e.g., `plugins/supabase.client.ts`): + ```ts + import { createClient } from '@supabase/supabase-js' + + export default defineNuxtPlugin(() => { + const supabase = createClient( + process.env.SUPABASE_URL, + process.env.SUPABASE_ANON_KEY + ) + return { + provide: { supabase } + } + }) + ``` + +4. **Set environment variables** locally (`.env`) and in GitHub Actions (secrets). + For local dev: + ``` + SUPABASE_URL=https://yourproject.supabase.co + SUPABASE_ANON_KEY=your-anon-key + ``` + In GitHub repo: add these as secrets (`SUPABASE_URL`, `SUPABASE_ANON_KEY`). + +5. **Use Supabase in your pages/components**: + ```vue + + ``` + +6. **GitHub Actions workflow** (from previous answer) – just ensure the secrets are passed if needed at build time. If you only fetch client‑side, you don't need them at build time. If you need to prerender dynamic routes with data, you would pass them to the build step. + +7. **Deploy**: The workflow builds the static site and uploads to GitHub Pages. The app will talk to Supabase directly from the browser. + +--- + +If this matches your needs, I can expand on any part. If not, please provide more specifics so I can tailor the solution.