Skip to content

Commit 96d4565

Browse files
authored
Update README.md
1 parent ec0cebd commit 96d4565

File tree

1 file changed

+52
-76
lines changed

1 file changed

+52
-76
lines changed

README.md

Lines changed: 52 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,57 @@
11
# Python Anywhere CI/CD pipeline POC
22

3+
# Automating Code Deployment from GitHub to PythonAnywhere
34

4-
5-
I have created CI/CD pipelines to automatically deploy code updates on Github repository to pythonanywhere web application.
6-
7-
Automating Code Deployment from GitHub to PythonAnywhere
8-
9-
Overview
5+
## Overview
106

117
This document provides a step-by-step guide to automatically deploy code updates from a GitHub repository to a PythonAnywhere web application using GitHub Actions and the PythonAnywhere API.
128

13-
1. Prerequisites
9+
## 1. Prerequisites
1410

1511
Before setting up automation, ensure you have:
1612

17-
A PythonAnywhere account (Free or Paid)
18-
19-
A GitHub repository with your project
13+
- A PythonAnywhere account (Free or Paid)
14+
- A GitHub repository with your project
15+
- API access enabled on PythonAnywhere (for Free users)
16+
- A web app running on PythonAnywhere
2017

21-
API access enabled on PythonAnywhere (for Free users)
22-
23-
A web app running on PythonAnywhere
24-
25-
2. Enable API Access on PythonAnywhere
18+
## 2. Enable API Access on PythonAnywhere
2619

2720
To use the PythonAnywhere API:
2821

29-
Go to PythonAnywhere Account Settings
30-
31-
Scroll to API Token and click "Create API Token" (if not already created).
22+
1. Go to **PythonAnywhere Account Settings**
23+
2. Scroll to **API Token** and click **"Create API Token"** (if not already created).
24+
3. Copy the API Token, as it will be needed later.
3225

33-
Copy the API Token, as it will be needed later.
26+
## 3. Clone Your GitHub Repository on PythonAnywhere
3427

35-
3. Clone Your GitHub Repository on PythonAnywhere
36-
37-
Open the Bash console on PythonAnywhere.
38-
39-
Run the following command to clone your repository:
28+
Open the Bash console on PythonAnywhere and run the following commands:
4029

30+
```bash
4131
git clone https://github.com/yourusername/yourrepository.git
42-
43-
Navigate to your project directory:
44-
4532
cd yourrepository
33+
```
4634

47-
4. Automate Deployment Using GitHub Actions
35+
## 4. Automate Deployment Using GitHub Actions
4836

4937
GitHub Actions will automatically update your PythonAnywhere code whenever you push changes.
5038

51-
Step 1: Add API Token as a GitHub Secret
52-
53-
Go to your GitHub repository → Settings → Secrets and variables → Actions
54-
55-
Click "New Repository Secret"
56-
57-
Add the API Token:
39+
### Step 1: Add API Token as a GitHub Secret
5840

59-
Name: PA_API_TOKEN
41+
1. Go to **GitHub repository → Settings → Secrets and variables → Actions**
42+
2. Click **"New Repository Secret"**
43+
3. Add the API Token:
44+
- **Name:** `PA_API_TOKEN`
45+
- **Value:** Paste your PythonAnywhere API token
46+
4. Click **"Save"**.
6047

61-
Value: Paste your PythonAnywhere API token
62-
63-
Click "Save".
64-
65-
Step 2: Create a GitHub Actions Workflow
48+
### Step 2: Create a GitHub Actions Workflow
6649

6750
In your GitHub repository, create a file:
68-
📄 .github/workflows/deploy.yml
6951

52+
📄 `.github/workflows/deploy.yml`
53+
54+
```yaml
7055
name: Deploy to PythonAnywhere
7156

7257
on:
@@ -94,63 +79,54 @@ jobs:
9479
run: |
9580
curl -s -X POST \
9681
"https://www.pythonanywhere.com/api/v0/user/${{ secrets.PA_USERNAME }}/webapps/${{ secrets.PA_USERNAME }}.pythonanywhere.com/reload/" \
97-
-H "Authorization: Token ${{ secrets.PA_API_TOKEN }}"
98-
99-
Step 3: Modify the Workflow File
100-
101-
Replace your_username with your PythonAnywhere username.
102-
103-
Replace yourrepository with your GitHub repository name.
104-
105-
Replace your_console_id (Find it by listing consoles via API: https://www.pythonanywhere.com/api/v0/user/your_username/consoles/).
106-
107-
Ensure the correct branch (main) is specified in the workflow.
82+
-H "Authorization: Token ${{ secrets.PA_API_TOKEN }}"
83+
```
10884
109-
5. Testing the Deployment
85+
### Step 3: Modify the Workflow File
11086
111-
Push a change to your GitHub repository.
87+
- Replace **your_username** with your PythonAnywhere username.
88+
- Replace **yourrepository** with your GitHub repository name.
89+
- Replace **your_console_id** (Find it by listing consoles via API: `https://www.pythonanywhere.com/api/v0/user/your_username/consoles/`).
90+
- Ensure the correct branch (**main** or **master**) is specified in the workflow.
11291

113-
Go to GitHub → Actions and verify the workflow execution.
92+
## 5. Testing the Deployment
11493

115-
If successful, check your PythonAnywhere project for the updated code.
94+
1. Push a change to your GitHub repository.
95+
2. Go to **GitHub → Actions** and verify the workflow execution.
96+
3. If successful, check your PythonAnywhere project for the updated code.
97+
4. The web app will automatically reload after deployment.
11698

117-
The web app will automatically reload after deployment.
118-
119-
6. Manual Deployment (If Needed)
99+
## 6. Manual Deployment (If Needed)
120100

121101
If GitHub Actions is not used, you can manually pull updates:
122102

103+
```bash
123104
cd yourrepository
124105
git pull origin main
106+
```
125107

126108
To reload the web app manually:
127109

110+
```bash
128111
touch /var/www/your_username_pythonanywhere_com_wsgi.py
112+
```
129113

130-
7. Troubleshooting
131-
132-
Issue
133-
134-
Solution
114+
## 7. Troubleshooting
135115

136-
Authentication error
116+
| Issue | Solution |
117+
|--------|----------|
118+
| **Authentication error** | Ensure the API token is correctly added in GitHub Secrets. |
119+
| **Changes not reflecting** | Verify `git pull` works in the PythonAnywhere console. |
120+
| **Console ID issue** | Use API to list active consoles and find the correct `console_id`. |
137121

138-
Ensure the API token is correctly added in GitHub Secrets.
122+
## Conclusion
139123

140-
Changes not reflecting
141-
142-
Verify git pull works in the PythonAnywhere console.
124+
This guide helps automate deployment from GitHub to PythonAnywhere using API calls. Once set up, every push to GitHub updates the PythonAnywhere project automatically and reloads the web app. 🚀
143125

144-
Console ID issue
145126

146-
Use API to list active consoles and find the correct console_id.
147127

148-
Conclusion
149128

150-
This guide helps automate deployment from GitHub to PythonAnywhere using API calls. Once set up, every push to GitHub updates the PythonAnywhere project automatically and reloads the web app. 🚀
151129

152130

153131

154-
This should start the server on http://127.0.0.1:8000/ or http://localhost:8000/.
155132

156-
Nice work

0 commit comments

Comments
 (0)