Grok 4.1 Fast· xai
Frontier Reasoning Traces
Create a CI/CD pipeline using GitHub Actions and Docker for an Angular application.
- User
Create a CI/CD pipeline using GitHub Actions and Docker for an Angular application.
- Assistant
name: Angular CI/CD with Docker on: push: branches: [ "main" ] tags: [ "v*" ] pull_request: branches: [ "main" ] jobs: build-test-deploy: runs-on: ubuntu-latest permissions: contents: read packages: write # Required for pushing to GHCR steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20 cache: 'npm' - name: Install dependencies run: npm ci - name: Lint run: npm run lint || true # Adjust if you want strict linting failure - name: Setup Chrome for tests uses: browser-actions/setup-chrome@v1 with: chrome-version: stable - name: Run tests run: npm run test -- --no-watch --browsers=ChromeHeadless - name: Generate Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} tags: | type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} type=ref,event=branch type=ref,event=pr,enable=true,suffix=-pr type=semver,pattern={{version}} type=sha - name: Log in to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: ${{ github.event_name != 'pull_request' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/v')) }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=maxSetup Instructions
-
Package.json Scripts (add/update these for Angular CLI):
{ "scripts": { "build": "ng build", "build:prod": "ng build --configuration production", "test": "ng test", "lint": "ng lint" } }- The test command uses
--no-watch --browsers=ChromeHeadlessin the workflow.
- The test command uses
-
angular.json:
- Ensure
"outputPath": "dist/angular-app"underprojects > angular-app > architect > build > configurations > production(replaceangular-appwith your project name).
- Ensure
-
Dockerfile (place in project root):
# Build stage FROM node:20-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build:prod # Production stage FROM nginx:stable-alpine AS production COPY --from=build /app/dist/angular-app /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]- Replace
angular-appin/app/dist/angular-appwith youroutputPath.
- Replace
-
nginx.conf (place in project root, for Angular routing/SPA support):
server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html index.htm; location / { try_files $uri $uri/ /index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } -
Workflow File:
- Save the YAML as
.github/workflows/angular-cicd.yml.
- Save the YAML as
How It Works
- CI (all branches/PRs): Installs deps, lints, runs headless tests, builds Docker image (no push).
- CD (main/tags):
- Pushes image to
ghcr.io/<owner>/<repo>with tags likelatest(main),<version>(tags),<sha>. - PRs get
-prsuffix (no push).
- Pushes image to
- Caching: NPM and Docker layers for speed.
- Permissions: Auto-approved via
GITHUB_TOKEN(no secrets needed).
Run
git pushto test. Deploy by pulling from GHCR:docker pull ghcr.io/<owner>/<repo>:latest. Extend for Kubernetes/VM deployment if needed! -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.