You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86-11Lines changed: 86 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# 🚀 PythonAnywhere Redeploy Action
2
2
3
-
This GitHub Action automates the redeployment process of a Django application hosted on **PythonAnywhere** using SSH.
3
+
This GitHub Action automates the redeployment process of a Django application hosted on [PythonAnywhere](https://www.pythonanywhere.com) using SSH.
4
4
It simplifies the workflow of pulling the latest code, installing dependencies, running migrations, and restarting the web server with minimal configuration.
5
5
6
6
@@ -27,7 +27,7 @@ Before using this action, make sure that:
| `password` | Your PythonAnywhere password | No | `password` |
79
+
| `ssh_private_key` | SSH private key (optional, but required if `password` is not provided) | No | *contents of your private key* |
62
80
| `working_directory` | Target working directory on PythonAnywhere | Yes | `/home/username/webapp_name` |
63
81
| `venv_directory` | Path to the Python virtual environment | Yes | `/home/username/webapp_name/.venv` |
64
82
| `wsgi_file` | Path to the WSGI file to reload the app | Yes | `/var/www/webapp_name_wsgi.py` |
65
-
83
+
66
84
67
85
## 🔐 Security
68
86
69
-
- **Always** use secrets for:
87
+
Always store sensitive data like credentials and SSH keys as [GitHub Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets):
88
+
89
+
- **Recommended secrets**:
70
90
- `username`
71
91
- `password`
72
-
- any sensitive tokens or credentials
92
+
- `ssh_private_key`
73
93
74
94
These values can expose your account if leaked, even in public forks or workflow logs.
75
95
@@ -80,19 +100,69 @@ These values can expose your account if leaked, even in public forks or workflow
80
100
- They include your username
81
101
- You want to keep the configuration more private or flexible
82
102
103
+
## 📂 Creating GitHub Secrets
104
+
105
+
1. In your GitHub repository, go to **Settings**
106
+
2. Navigate to **Secrets and variables → Actions**
107
+
3. Click **New repository secret**
108
+
4. Name the secret (e.g., `PA_USERNAME`, `PA_SSH_PRIVATE_KEY`, etc.)
109
+
5. Paste the corresponding value
110
+
111
+
Repeat for each required secret.
112
+
113
+
> ⚠️ **Do not commit secrets directly into your repository.** Always use GitHub Secrets to store sensitive information.
114
+
115
+
116
+
## 📋 Using an SSH Key (Recommended)
117
+
118
+
### 1. Generate an SSH key (if you don't have one):
119
+
120
+
If you don’t already have an SSH key pair for authentication, you can generate one using the following command:
121
+
122
+
```bash
123
+
$ ssh-keygen -t ed25519
124
+
```
125
+
- When prompted, press Enter to accept the default file location (`~/.ssh/id_ed25519`).
126
+
127
+
- You may set a passphrase for added security (optional).
128
+
129
+
### 2. Add the **public key** to PythonAnywhere:
130
+
131
+
To add the public key to PythonAnywhere, run the following command:
132
+
133
+
```bash
134
+
$ ssh-copy-id <username>@ssh.pythonanywhere.com
135
+
```
136
+
Enter your PythonAnywhere password when prompted.
137
+
138
+
> 💡 Use `ssh.eu.pythonanywhere.com` for EU-based accounts.
83
139
84
-
## 📁 Repository Structure
140
+
141
+
### 3. Store the **private key** securely:
142
+
To store the private key securely, follow these steps:
143
+
- Copy the contents of the private key file (.ssh/id_ed25519) running the command
144
+
```bash
145
+
cat ~/.ssh/id_ed25519
146
+
```
147
+
- Create a new secret in your GitHub repository following the instructions in the [Creating GitHub Secrets](#-creating-github-secrets) section.
148
+
- Paste the contents of the private key into the secret field.
149
+
150
+
> 💡 Make sure to keep your private key secure and do not share it with anyone.
151
+
152
+
For more information on SSH setup, refer to: [SSH Access on PythonAnywhere](https://help.pythonanywhere.com/pages/SSHAccess/)
153
+
154
+
## ⚠️ Repository Structure
85
155
86
156
This action is composed of:
87
157
88
158
- `action.yml`
89
159
Defines the input interface of the GitHub Action (required inputs) and specifies the execution environment. In this case, it sets up execution in a Docker container that runs the `deploy.sh` script.
90
160
91
161
- `deploy.sh`
92
-
Main script executed inside the container. It uses `sshpass` to connect to PythonAnywhere via SSH, performs `git pull`, installs dependencies, runs migrations, and restarts the web server by touching the `WSGI.py` file.
162
+
Main script executed inside the container. It uses SSH to connect to PythonAnywhere, performs `git pull`, installs dependencies, runs migrations, collects static files and restarts the web server by touching the `WSGI.py` file.
93
163
94
164
- `Dockerfile`
95
-
Defines a custom Docker image based on `ubuntu`, installs `sshpass`, and copies the required scripts. This ensures the environment has all necessary tools to perform the redeploy process without relying on the host runner.
165
+
Defines a custom Docker image based on ubuntu, installs the necessary tools for SSH connections, and copies the required scripts. This ensures the environment has all the necessary tools to perform the redeploy process without relying on the host runner.
96
166
97
167
- `.github/workflows/example.yml`
98
168
Provides an example of how to use the action in a workflow. You can use it as a template or reference when setting up your own deployment workflow.
@@ -101,3 +171,8 @@ Provides an example of how to use the action in a workflow. You can use it as a
101
171
## 📝 License
102
172
103
173
This GitHub Action is distributed under the [MIT License](https://github.com/MiguelRizzi/pythonanywhere-deploy-ssh/blob/main/LICENSE).
174
+
175
+
176
+
---
177
+
178
+
Made with ❤️ to simplify PythonAnywhere deployments.
0 commit comments