Week 5 Summery Task – CI CD Pipeline with GitHub Actions - snir1551/DevOps-Linux GitHub Wiki
Backend (https://week5-ci-cd-jjqo.onrender.com)
Frontend (https://frontend-smoky-iota-15.vercel.app)
-
Requirement: Create a GitHub repository named
week5-ci-cd
with a README.md. -
Implementation:
- This repository is named
week5-ci-cd
and contains this README file.
- This repository is named
- Requirement: The project must include a simple frontend and backend.
-
Implementation:
-
frontend/
contains a React app. -
backend/
contains a Node.js Express app.
-
- Requirement: Set up GitHub Actions to run tests for both parts when pushing code.
-
Implementation:
- In
.github/workflows/ci-cd.yml
, thetest
job runs backend tests on every push and pull request:test: runs-on: ubuntu-latest strategy: matrix: node-version: [18, 20] steps: - name: Checkout Code uses: actions/checkout@v4 - name: Setup Node.js ${matrix.node-version} uses: actions/setup-node@v4 with: node-version: ${{matrix.node-version}} - name: Test Backend run: | cd backend npm install npm test
- In
- Requirement: Use job matrix to test across multiple versions of Node.js.
-
Implementation:
-
The
matrix.node-version: [18, 20]
in bothtest
andbuild
jobs:strategy: matrix: node-version: [18, 20]
-
- Requirement: Configure artifact upload at the end of the build process.
-
Implementation:
-
In the
build
job, artifacts are uploaded:- name: Upload Backend Build Artifact uses: actions/upload-artifact@v4 with: name: backend-build-${{ matrix.node-version }} path: backend/ - name: Upload Frontend Build Artifact uses: actions/upload-artifact@v4 with: name: frontend-build-${{ matrix.node-version }} path: frontend/build
-
- Requirement: Use GitHub Secrets to handle sensitive values (e.g., deployment keys, tokens).
-
Implementation:
-
Secrets are used for deployment and notifications:
- name: Deploy Backend to Render run: curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_URL }} - name: Deploy Frontend to Vercel env: VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} run: | cd frontend vercel --prod --token $VERCEL_TOKEN --yes - name: Notify Discord on Success env: DISCORD_WEBHOOK: ${{ secrets.DISCORDBOT }}
-
- Requirement: Add Slack or Discord notifications in case of pipeline failure or success.
-
Implementation:
- The
notify
job sends a message to Discord on both success and failure:- name: Notify Discord on Success if: needs.deploy.result == 'success' env: DISCORD_WEBHOOK: ${{ secrets.DISCORDBOT }} run: | # ...payload and curl command... - name: Notify Discord on Failure if: needs.deploy.result == 'failure' env: DISCORD_WEBHOOK: ${{ secrets.DISCORDBOT }} run: | # ...payload and curl command...
- The
- We learned how the product lifecycle looks—what happens when we write code and deploy it to production.
- We also learned that using automation tools helps save time and prevents future problems.
- Understanding how to deploy and choose the right tools for the frontend app and backend server.
- Create separate YAML files for small deployment jobs and combine them into one file for full deployment.
This way, I can choose to deploy only the backend, only the frontend, or both.