Skip to content

Commit b878509

Browse files
committed
enablish cicd
1 parent b75503d commit b878509

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
# re-enable trigger for meta ads
3+
4+
on:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
20+
- name: Build image
21+
uses: docker/build-push-action@v6
22+
with:
23+
context: .
24+
push: false
25+
cache-from: type=gha
26+
cache-to: type=gha,mode=max
27+
28+
deploy:
29+
runs-on: ubuntu-latest
30+
needs: build
31+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
32+
permissions:
33+
contents: read
34+
packages: write
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Login to GHCR
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ghcr.io
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Tag previous image for rollback
50+
run: |
51+
docker pull ghcr.io/pmlabs-org/mcp-meta-ads:latest || true
52+
docker tag ghcr.io/pmlabs-org/mcp-meta-ads:latest \
53+
ghcr.io/pmlabs-org/mcp-meta-ads:previous || true
54+
docker push ghcr.io/pmlabs-org/mcp-meta-ads:previous || true
55+
56+
- name: Build and push
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
push: true
61+
tags: |
62+
ghcr.io/pmlabs-org/mcp-meta-ads:latest
63+
ghcr.io/pmlabs-org/mcp-meta-ads:${{ github.sha }}
64+
cache-from: type=gha
65+
cache-to: type=gha,mode=max
66+
67+
- name: Setup SSH agent
68+
uses: webfactory/ssh-agent@v0.9.0
69+
with:
70+
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
71+
72+
- name: Add droplet to known hosts
73+
run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
74+
75+
- name: Deploy to droplet
76+
run: |
77+
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} \
78+
"cd /opt/pmin-mcpinfrastructure \
79+
&& docker compose pull meta-ads \
80+
&& docker compose up -d --force-recreate meta-ads"
81+
82+
- name: Health check
83+
run: |
84+
for i in 1 2 3 4 5; do
85+
if curl -sf https://meta-ads.mcp.pathfindermarketing.com.au/.well-known/oauth-authorization-server > /dev/null; then
86+
echo "Health check passed"; exit 0
87+
fi
88+
echo "Attempt $i/5 — retrying in 15s..."; sleep 15
89+
done
90+
echo "Health check failed"; exit 1

0 commit comments

Comments
 (0)