add ci
This commit is contained in:
46
.github/workflows/ci.yml
vendored
Normal file
46
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Deploy to Docker Swarm (Worker Node)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
docker build -t ghcr.io/serverussnap/imagegenerator:latest .
|
||||||
|
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u serverussnap --password-stdin
|
||||||
|
docker push ghcr.io/serverussnap/imagegenerator:latest
|
||||||
|
|
||||||
|
- name: Deploy to Swarm Worker Node
|
||||||
|
uses: appleboy/ssh-action@v1.0.0
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.VM_HOST }}
|
||||||
|
username: ${{ secrets.VM_USER }}
|
||||||
|
key: ${{ secrets.VM_SSH_KEY }}
|
||||||
|
script: |
|
||||||
|
docker login ghcr.io -u serverussnap -p ${{ secrets.GHCR_TOKEN }}
|
||||||
|
|
||||||
|
if docker service inspect imagegenerator_service >/dev/null 2>&1; then
|
||||||
|
docker service update \
|
||||||
|
--image ghcr.io/serverussnap/imagegenerator:latest \
|
||||||
|
--publish-add published=3050,target=3000,mode=host \
|
||||||
|
--constraint node.hostname==worker \
|
||||||
|
--with-registry-auth \
|
||||||
|
imagegenerator_service
|
||||||
|
else
|
||||||
|
docker service create \
|
||||||
|
--name imagegenerator_service \
|
||||||
|
--publish published=3050,target=3000,mode=host \
|
||||||
|
--constraint node.hostname==worker \
|
||||||
|
--with-registry-auth \
|
||||||
|
ghcr.io/serverussnap/imagegenerator:latest
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker image prune -a -f
|
||||||
Reference in New Issue
Block a user