Skip to content

Commit 538fc8f

Browse files
committed
2 parents d9516f9 + 5fd06c2 commit 538fc8f

File tree

6 files changed

+72
-17
lines changed

6 files changed

+72
-17
lines changed

.github/workflows/prod.yml

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build, Test and Deploy to Prod
22

33
on:
4-
push:
4+
push:
55
branches:
66
- main
77

@@ -11,11 +11,22 @@ env:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
outputs:
15+
image_tag: ${{ steps.tag.outputs.tag }}
1416

1517
steps:
1618
- name: Checkout code
1719
uses: actions/checkout@v2
1820

21+
# Create unique tag from git commit + build number
22+
- name: Generate unique tag
23+
id: tag
24+
run: |
25+
SHORT_SHA=$(git rev-parse --short HEAD)
26+
TAG="build-${{ github.run_number }}-${SHORT_SHA}"
27+
echo "tag=$TAG" >> $GITHUB_OUTPUT
28+
echo "Generated tag: $TAG"
29+
1930
- name: Cache dependencies
2031
uses: actions/cache@v3
2132
with:
@@ -46,21 +57,25 @@ jobs:
4657
username: ${{ secrets.DOCKER_USERNAME }}
4758
password: ${{ secrets.DOCKER_PASSWORD }}
4859

49-
- name: Build and push Docker images
60+
- name: Build and push Docker images with unique tag
5061
uses: docker/bake-action@v2.3.0
62+
env:
63+
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
5164
with:
5265
files: ./server/docker-bake.hcl
5366
push: true
5467
set: |
5568
*.cache-from=type=gha
5669
*.cache-to=type=gha,mode=max
5770
58-
# - name: Build and push indexer
59-
# uses: docker/build-push-action@v4
60-
# with:
61-
# context: ./the_last_indexer
62-
# push: true
63-
# tags: akshola00/paymesh-indexer:latest
71+
- name: Build and push indexer with unique tag
72+
uses: docker/build-push-action@v4
73+
with:
74+
context: ./the_last_indexer
75+
push: true
76+
tags: |
77+
paymesh/the-last-indexer:${{ steps.tag.outputs.tag }}
78+
paymesh/the-last-indexer:latest
6479
6580
deploy:
6681
needs: build
@@ -84,12 +99,17 @@ jobs:
8499

85100
- name: Deploy with environment variables
86101
uses: appleboy/ssh-action@master
102+
env:
103+
IMAGE_TAG: ${{ needs.build.outputs.image_tag }}
87104
with:
88105
host: ${{ vars.DROPLET_IP }}
89106
username: root
90107
password: ${{ secrets.DROPLET_PASSWORD }}
108+
envs: IMAGE_TAG
91109
script: |
92110
cd ~
111+
112+
# Create environment file
93113
cat > .env <<EOL
94114
RPC_URL=${{ secrets.RPC_URL }}
95115
PRIVATE_KEY=${{ secrets.PRIVATE_KEY }}
@@ -108,12 +128,31 @@ jobs:
108128
JWT_EXPIRED_IN=${{ secrets.JWT_EXPIRED_IN }}
109129
JWT_MAXAGE=${{ secrets.JWT_MAXAGE }}
110130
PAYMESH_API_KEY=${{ secrets.PAYMESH_API_KEY }}
131+
IMAGE_TAG=${IMAGE_TAG}
111132
EOL
112133
134+
echo "Deploying with image tag: ${IMAGE_TAG}"
135+
136+
# Stop, pull new images, and restart
113137
docker compose --env-file .env stop
114138
docker compose --env-file .env pull
115139
docker compose --env-file .env up -d
116-
140+
141+
# Cleanup old images - keep last 5 versions
142+
echo "Cleaning up old images..."
143+
docker images "paymesh/server" --format "{{.Repository}}:{{.Tag}}" | \
144+
grep -v latest | \
145+
sort -r | \
146+
tail -n +6 | \
147+
xargs -r docker rmi || true
148+
149+
150+
# Remove dangling images
151+
docker image prune -f
152+
153+
echo "Deployment complete!"
154+
echo "Running containers:"
155+
docker ps
117156
# - name: Copy docker-compose.yml to paymesh indexer droplet
118157
# run: sshpass -v -p ${{ secrets.PAYMESH_DROPLET_PASSWORD }} scp -o StrictHostKeyChecking=no the_last_indexer/docker-compose.yml root@${{ vars.PAYMESH_DROPLET_IP }}:~
119158

server/docker-bake.hcl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
variable "IMAGE_TAG" {
2+
default = "latest"
3+
}
4+
15
target "default" {
26
dockerfile = "Dockerfile"
37
context = "./server"
4-
tags = ["akshola00/server:latest"]
8+
tags = [
9+
"paymesh/server:${IMAGE_TAG}",
10+
"paymesh/server:latest"
11+
]
512
platforms = ["linux/amd64"]
6-
}
13+
}

server/docker-compose.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.9'
22
services:
33
api:
4-
image: akshola00/server:latest
4+
image: paymesh/server:${IMAGE_TAG:-latest}
55
platform: linux/amd64
66
restart: always
77
environment:
@@ -30,6 +30,15 @@ services:
3030
POSTGRES_DB: "${DATABASE_URL_DB}"
3131
volumes:
3232
- pgdata:/var/lib/postgresql/data
33+
34+
# indexer:
35+
# image: paymesh/the-last-indexer:${IMAGE_TAG:-latest}
36+
# restart: always
37+
# environment:
38+
# DNA_TOKEN: "${DNA_TOKEN}"
39+
# API_URL: "${API_URL}"
40+
# PAYMESH_API_KEY: "${PAYMESH_API_KEY}"
41+
3342

3443
volumes:
35-
pgdata:
44+
pgdata:

server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async fn main() {
4848
.expect("Failed to create genesis admin");
4949

5050
let listener = TcpListener::bind("0.0.0.0:8080").await.unwrap();
51-
tracing::info!("listening on {}", listener.local_addr().unwrap());
51+
tracing::info!("listening on port{}", listener.local_addr().unwrap());
5252

5353
let router = router(config);
5454

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
22
indexer:
3-
image: akshola00/paymesh-indexer:latest
3+
image: paymesh/the-last-indexer:${IMAGE_TAG:-latest}
44
restart: always
55
environment:
66
DNA_TOKEN: "${DNA_TOKEN}"
77
API_URL: "${API_URL}"
8-
PAYMESH_API_KEY: "${PAYMESH_API_KEY}"
8+
PAYMESH_API_KEY: "${PAYMESH_API_KEY}"

the_last_indexer/indexers/paymesh-starknet.indexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,4 @@ const subsciption_topped = (group_address: string, usage_count: number) => {
429429
}).catch((err) => {
430430
console.error(`Subscription top up error for ${group_address}:`, err);
431431
});
432-
};
432+
};

0 commit comments

Comments
 (0)