-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCICD Pipeline.txt
73 lines (61 loc) · 2.73 KB
/
CICD Pipeline.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
CI/CD Pipeline
1. Setting up the Workflow Directory
First, ensure you have a .github/workflows directory in your project root. Inside this directory, you will create YAML files that define your CI/CD workflows.
2. Defining the CI Workflow
Create a file named ci.yml inside the .github/workflows directory. This file will define the steps for Continuous Integration (CI), including code checkout, dependency installation, and running tests.
yaml
Copy code
name: CI Workflow
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
This workflow triggers on push or pull requests to the main branch, checks out the code, sets up a Node.js environment, installs dependencies, and runs tests.
3. Defining the CD Workflow
For Continuous Deployment (CD), you might want to deploy your application to a cloud service like Heroku, AWS, or Azure. Below is an example of deploying to Heroku.
Create a file named cd.yml inside the .github/workflows directory.
yaml
Copy code
name: CD Workflow
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: '14'
- name: Build project
run: npm run build
- name: Deploy to Heroku
uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: "your-app-name"
heroku_email: "[email protected]"
usedocker: true
This workflow triggers on push to the main branch, sets up Node.js, builds the project, and deploys it to Heroku. You need to add your Heroku API key to GitHub Secrets (HEROKU_API_KEY) and update your-app-name and [email protected] accordingly.
4. Managing Secrets and Environment Variables
For both workflows, if you have sensitive information or environment-specific configurations, use GitHub Secrets to store them and refer to these secrets in your workflow files.
5. Customization Based on Specific Needs
If your project uses databases or other services, you might need to set up services containers in your workflow or use external services.
For a multi-environment setup (e.g., staging and production), you could create separate branches and workflows for each environment.
Adapt the build and deployment steps according to the technology stack and the hosting platform you are using.