Skip to content

Commit d2c0a84

Browse files
committed
new deploy workflow v0
1 parent b6c2c09 commit d2c0a84

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

.github/workflows/deploy-ec2.yml

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,41 @@ on:
1515
- "start_docker_compose_prod.sh"
1616
- "docker-compose.yml"
1717
- ".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
1826

1927
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+
2048
build-brainrot:
2149
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'
2253
runs-on: ubuntu-latest
2354
environment: production
2455

@@ -98,6 +129,9 @@ jobs:
98129
99130
build-rvc:
100131
name: Build and Push RVC
132+
needs: [changes]
133+
# Only run if rvc files changed
134+
if: needs.changes.outputs.rvc == 'true'
101135
runs-on: ubuntu-latest
102136
environment: production
103137

@@ -130,6 +164,18 @@ jobs:
130164
sudo apt-get purge -y '^ghc-*' '^php*' '^mysql*' mono-complete
131165
sudo apt-get purge -y llvm* powershell ruby-full postgresql*
132166
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+
133179
# Final cleanup
134180
sudo apt-get autoremove -y
135181
sudo apt-get clean -y
@@ -181,11 +227,25 @@ jobs:
181227
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest
182228
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
183229
230+
# Deploy job that runs after any builds that were triggered
184231
deploy:
185232
name: Deploy to EC2
186233
runs-on: ubuntu-latest
187234
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+
189249
steps:
190250
- name: Checkout
191251
uses: actions/checkout@v3
@@ -197,6 +257,7 @@ jobs:
197257
aws-secret-access-key: ${{ secrets.ACTIONS_AWS_SECRET_ACCESS_KEY }}
198258
aws-region: us-east-1
199259

260+
# Copy deployment script to EC2
200261
- name: Copy deployment script
201262
uses: appleboy/scp-action@v0.1.4
202263
with:
@@ -208,6 +269,7 @@ jobs:
208269
target: "/home/ec2-user/"
209270
overwrite: true
210271

272+
# Deploy to EC2 via SSH
211273
- name: Deploy to EC2
212274
uses: appleboy/ssh-action@v1.0.0
213275
env:
@@ -242,6 +304,21 @@ jobs:
242304
# Make sure Docker is running
243305
sudo systemctl start docker
244306
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+
245322
# Configure AWS credentials for ECR access
246323
mkdir -p ~/.aws
247324
cat > ~/.aws/credentials << EOL

rvc/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
FROM nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04
44

5-
EXPOSE 7865
5+
EXPOSE 5555
66
WORKDIR /app
77
COPY . .
88

0 commit comments

Comments
 (0)