Skip to content

Commit dfed7f7

Browse files
committed
Update workflow for strapi prod
1 parent de77dd4 commit dfed7f7

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Build and Push Strapi to ECR (Test)
2+
3+
on:
4+
push:
5+
branches:
6+
- build_strapi_prod_image
7+
8+
jobs:
9+
build-and-push:
10+
name: Build Docker Image and Push to Amazon ECR
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v4
16+
17+
- name: Install Python Dependencies
18+
run: pip install psutil requests
19+
20+
- name: Create Monitor Script
21+
run: |
22+
cat << 'EOF' > cpu_to_openobserve.py
23+
import psutil, requests, json, time, os, socket, signal, sys, base64
24+
25+
OO_URL = "https://introspection.dev.zinclabs.dev/api/default/github_runner/_json"
26+
USERNAME = "introspectionroot@openobserve.ai"
27+
PASSWORD = "1ZRdj1DwiE5d7KIU"
28+
29+
auth_str = f"{USERNAME}:{PASSWORD}"
30+
auth_header = base64.b64encode(auth_str.encode("utf-8")).decode("utf-8")
31+
OO_HEADERS = {
32+
"Content-Type": "application/json",
33+
"Authorization": f"Basic {auth_header}"
34+
}
35+
36+
def collect_metrics():
37+
mem = psutil.virtual_memory()
38+
disk = psutil.disk_usage('/')
39+
return {
40+
"timestamp": int(time.time() * 1000),
41+
"runner": os.getenv("HOSTNAME", socket.gethostname()),
42+
"cpu_percent": psutil.cpu_percent(interval=1),
43+
"cpu_cores": psutil.cpu_count(logical=True),
44+
"memory_percent": mem.percent,
45+
"memory_available_mb": round(mem.available / (1024 * 1024), 2),
46+
"disk_percent": disk.percent,
47+
"disk_free_gb": round(disk.free / (1024 * 1024 * 1024), 2),
48+
"level": "info",
49+
"job": "github-monitor",
50+
"log": "runner resource metrics"
51+
}
52+
53+
def send(payload):
54+
try:
55+
print("Sending:", payload)
56+
resp = requests.post(OO_URL, headers=OO_HEADERS, data=json.dumps([payload]), verify=False)
57+
print("Status:", resp.status_code)
58+
except Exception as e:
59+
print("Error:", e)
60+
61+
def handler(sig, frame):
62+
print("Received stop signal. Exiting monitor.")
63+
sys.exit(0)
64+
65+
signal.signal(signal.SIGTERM, handler)
66+
signal.signal(signal.SIGINT, handler)
67+
68+
while True:
69+
send(collect_metrics())
70+
time.sleep(10)
71+
EOF
72+
73+
- name: Start Continuous Monitor
74+
run: |
75+
python3 cpu_to_openobserve.py &
76+
echo $! > monitor.pid
77+
78+
- name: Check and Install AWS CLI
79+
run: |
80+
if ! command -v aws &> /dev/null
81+
then
82+
echo "AWS CLI not found. Installing..."
83+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
84+
unzip awscliv2.zip
85+
sudo ./aws/install
86+
else
87+
echo "AWS CLI is already installed."
88+
aws --version
89+
fi
90+
91+
- name: Configure AWS credentials
92+
uses: aws-actions/configure-aws-credentials@v4
93+
with:
94+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
95+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
96+
aws-region: us-east-2
97+
98+
- name: Log in to Amazon ECR
99+
run: |
100+
aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 325553860333.dkr.ecr.us-east-2.amazonaws.com
101+
102+
- name: Build Docker Image
103+
run: |
104+
docker build -t openobserve/strapi .
105+
106+
- name: Tag Docker Image
107+
run: |
108+
docker tag openobserve/strapi:latest 325553860333.dkr.ecr.us-east-2.amazonaws.com/openobserve/strapi:latest
109+
110+
- name: Push Docker Image to Amazon ECR
111+
run: |
112+
docker push 325553860333.dkr.ecr.us-east-2.amazonaws.com/openobserve/strapi:latest
113+
114+
- name: Stop Monitor
115+
if: always()
116+
run: |
117+
if [ -f monitor.pid ]; then
118+
kill $(cat monitor.pid) || echo "Monitor already stopped"
119+
fi

0 commit comments

Comments
 (0)