-
Notifications
You must be signed in to change notification settings - Fork 10
33 lines (27 loc) · 1.11 KB
/
deploy-on-server.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
name: Deploy on Server
on:
workflow_run:
workflows: ["Build and Push Docker image"]
branches: [main]
types:
- completed
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Login to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Remove all containers using the old image
run: |
docker container ls -q --filter ancestor=oriolegea/passager-backend:latest | xargs -r docker container stop
docker container ls -aq --filter ancestor=oriolegea/passager-backend:latest | xargs -r docker container rm
- name: Remove old images
run: |
docker image prune -af --filter "label=oriolegea/passager-backend"
- name: Pull latest Docker image
run: docker pull oriolegea/passager-backend:latest
- name: Run container with the latest image
run: docker run -d --restart=always --env-file /root/passager-config/.env -p 3001-3002:3001-3002 oriolegea/passager-backend:latest