15
15
- " start_docker_compose_prod.sh"
16
16
- " docker-compose.yml"
17
17
- " .github/workflows/deploy-ec2.yml"
18
+ # Add workflow_dispatch to allow manual triggering of just the deploy job
19
+ workflow_dispatch :
20
+ inputs :
21
+ run_deploy :
22
+ description : " Run deploy job"
23
+ required : true
24
+ default : true
25
+ type : boolean
18
26
19
27
jobs :
28
+ # This job determines which build jobs should run based on changed files
29
+ changes :
30
+ name : Detect Changes
31
+ runs-on : ubuntu-latest
32
+ # Skip this job for manual triggers
33
+ if : github.event_name == 'push'
34
+ outputs :
35
+ brainrot : ${{ steps.filter.outputs.generate }}
36
+ rvc : ${{ steps.filter.outputs.rvc }}
37
+ steps :
38
+ - uses : actions/checkout@v3
39
+ - uses : dorny/paths-filter@v2
40
+ id : filter
41
+ with :
42
+ filters : |
43
+ generate:
44
+ - 'generate/**'
45
+ rvc:
46
+ - 'rvc/**'
47
+
20
48
build-brainrot :
21
49
name : Build and Push Brainrot
50
+ needs : [changes]
51
+ # Only run if generate files changed or this is a manual trigger
52
+ if : needs.changes.outputs.brainrot == 'true'
22
53
runs-on : ubuntu-latest
23
54
environment : production
24
55
98
129
99
130
build-rvc :
100
131
name : Build and Push RVC
132
+ needs : [changes]
133
+ # Only run if rvc files changed
134
+ if : needs.changes.outputs.rvc == 'true'
101
135
runs-on : ubuntu-latest
102
136
environment : production
103
137
@@ -130,6 +164,18 @@ jobs:
130
164
sudo apt-get purge -y '^ghc-*' '^php*' '^mysql*' mono-complete
131
165
sudo apt-get purge -y llvm* powershell ruby-full postgresql*
132
166
167
+ # Additional aggressive cleanup
168
+ sudo rm -rf /usr/local/share/boost
169
+ sudo rm -rf /usr/local/lib/node_modules
170
+ sudo rm -rf /usr/local/share/cmake*
171
+ sudo rm -rf /usr/local/share/man
172
+ sudo rm -rf /var/lib/apt/lists/*
173
+
174
+ # Clean Docker images if Docker is installed
175
+ if command -v docker &> /dev/null; then
176
+ docker system prune -a -f --volumes
177
+ fi
178
+
133
179
# Final cleanup
134
180
sudo apt-get autoremove -y
135
181
sudo apt-get clean -y
@@ -181,11 +227,25 @@ jobs:
181
227
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest
182
228
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
183
229
230
+ # Deploy job that runs after any builds that were triggered
184
231
deploy :
185
232
name : Deploy to EC2
186
233
runs-on : ubuntu-latest
187
234
environment : production
188
- needs : [build-brainrot, build-rvc]
235
+ # Only depend on builds that actually ran
236
+ needs :
237
+ - changes
238
+ - build-brainrot
239
+ - build-rvc
240
+ # This special syntax makes the dependencies conditional
241
+ # The job will wait for build-brainrot only if it ran, and for build-rvc only if it ran
242
+ if : |
243
+ (github.event_name == 'workflow_dispatch' && github.event.inputs.run_deploy == 'true') ||
244
+ (github.event_name == 'push' && always() &&
245
+ (needs.changes.result == 'success') &&
246
+ (needs.changes.outputs.brainrot != 'true' || needs.build-brainrot.result == 'success') &&
247
+ (needs.changes.outputs.rvc != 'true' || needs.build-rvc.result == 'success'))
248
+
189
249
steps :
190
250
- name : Checkout
191
251
uses : actions/checkout@v3
@@ -197,6 +257,7 @@ jobs:
197
257
aws-secret-access-key : ${{ secrets.ACTIONS_AWS_SECRET_ACCESS_KEY }}
198
258
aws-region : us-east-1
199
259
260
+ # Copy deployment script to EC2
200
261
- name : Copy deployment script
201
262
uses : appleboy/scp-action@v0.1.4
202
263
with :
@@ -208,6 +269,7 @@ jobs:
208
269
target : " /home/ec2-user/"
209
270
overwrite : true
210
271
272
+ # Deploy to EC2 via SSH
211
273
- name : Deploy to EC2
212
274
uses : appleboy/ssh-action@v1.0.0
213
275
env :
@@ -242,6 +304,21 @@ jobs:
242
304
# Make sure Docker is running
243
305
sudo systemctl start docker
244
306
307
+ # Aggressive disk cleanup before deployment
308
+ echo "Cleaning up disk space..."
309
+ # Remove unused Docker data
310
+ docker system prune -a -f --volumes
311
+ # Remove all stopped containers
312
+ docker rm $(docker ps -a -q) || true
313
+ # Remove all unused images
314
+ docker rmi $(docker images -q) || true
315
+ # Clean package manager cache
316
+ sudo yum clean all
317
+ # Remove temporary files
318
+ sudo rm -rf /tmp/*
319
+ # Show available disk space
320
+ df -h
321
+
245
322
# Configure AWS credentials for ECR access
246
323
mkdir -p ~/.aws
247
324
cat > ~/.aws/credentials << EOL
0 commit comments