@@ -57,16 +57,17 @@ jobs:
5757 username : ${{ secrets.DOCKER_USERNAME }}
5858 password : ${{ secrets.DOCKER_PASSWORD }}
5959
60- - name : Build and push Docker images with unique tag
61- uses : docker/bake-action@v2.3.0
62- env :
63- IMAGE_TAG : ${{ steps.tag.outputs.tag }}
60+ - name : Build and push server with unique tag
61+ uses : docker/build-push-action@v4
6462 with :
65- files : ./server/docker-bake.hcl
63+ context : ./server
6664 push : true
67- set : |
68- *.cache-from=type=gha
69- *.cache-to=type=gha,mode=max
65+ tags : |
66+ paymesh/server:${{ steps.tag.outputs.tag }}
67+ paymesh/server:latest
68+ cache-from : type=gha
69+ cache-to : type=gha,mode=max
70+ platforms : linux/amd64
7071
7172 - name : Build and push indexer with unique tag
7273 uses : docker/build-push-action@v4
@@ -158,24 +159,48 @@ jobs:
158159 echo "Deployment complete!"
159160 echo "Running containers:"
160161 docker ps
161- # - name: Copy docker-compose.yml to paymesh indexer droplet
162- # run: sshpass -v -p ${{ secrets.PAYMESH_DROPLET_PASSWORD }} scp -o StrictHostKeyChecking=no the_last_indexer/docker-compose.yml root@${{ vars.PAYMESH_DROPLET_IP }}:~
162+
163+ - name : Copy docker-compose.yml to indexer droplet
164+ run : sshpass -v -p ${{ secrets.INDEXER_DROPLET_PASSWORD }} scp -o StrictHostKeyChecking=no server/docker-compose.yml root@${{ vars.INDEXER_DROPLET_IP }}:~
163165
164- # - name: Deploy with environment variables
165- # uses: appleboy/ssh-action@master
166- # with:
167- # host: ${{ vars.PAYMESH_DROPLET_IP }}
168- # username: root
169- # password: ${{ secrets.PAYMESH_DROPLET_PASSWORD }}
170- # script: |
171- # cd ~
172- # cat > .env <<EOL
173- # DNA_TOKEN=${{ secrets.DNA_TOKEN }}
174- # API_URL=${{ secrets.API_URL }}
175- # PAYMESH_API_KEY=${{ secrets.PAYMESH_API_KEY }}
166+ - name : Deploy with environment variables
167+ uses : appleboy/ssh-action@master
168+ env :
169+ IMAGE_TAG : ${{ needs.build.outputs.image_tag }}
170+ with :
171+ host : ${{ vars.INDEXER_DROPLET_IP }}
172+ username : root
173+ password : ${{ secrets.INDEXER_DROPLET_PASSWORD }}
174+ envs : IMAGE_TAG
175+ script : |
176+ cd ~
177+
178+ # Create environment file
179+ cat > .env <<EOL
180+ DNA_TOKEN=${{ secrets.DNA_TOKEN }}
181+ API_URL=${{ secrets.API_URL }}
182+ PAYMESH_API_KEY=${{ secrets.PAYMESH_API_KEY }}
183+ IMAGE_TAG=${IMAGE_TAG}
184+ EOL
185+
186+ echo "Deploying with image tag: ${IMAGE_TAG}"
187+
188+ # Stop, pull new images, and restart
189+ docker compose --env-file .env stop
190+ docker compose --env-file .env pull
191+ docker compose --env-file .env up -d
192+
193+ # Cleanup old images - keep last 5 versions
194+ echo "Cleaning up old images..."
195+ docker images "paymesh/the-last-indexer" --format "{{.Repository}}:{{.Tag}}" | \
196+ grep -v latest | \
197+ sort -r | \
198+ tail -n +6 | \
199+ xargs -r docker rmi || true
176200
177- # EOL
201+ # Remove dangling images
202+ docker image prune -f
178203
179- # docker compose --env-file .env stop
180- # docker compose --env-file .env pull
181- # docker compose --env-file .env up -d
204+ echo "Deployment complete!"
205+ echo "Running containers:"
206+ docker ps
0 commit comments