Deploy on Server #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |