import fix #27
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: Build and Deploy | |
on: | |
push: | |
branches: | |
- master | |
env: | |
IMAGE_NAME: muhammadahmed1127/instagram-clone | |
IMAGE_TAG: backend-1.1 | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASS }} | |
- name: Build Docker image | |
run: docker build -t $IMAGE_NAME:$IMAGE_TAG ./ | |
- name: Push Docker image to Docker Hub | |
run: docker push $IMAGE_NAME:$IMAGE_TAG | |
deploy: | |
runs-on: ubuntu-20.04 | |
needs: build | |
steps: | |
- name: SSH into server and deploy Docker image | |
uses: appleboy/ssh-action@master | |
with: | |
host: 64.23.148.21 | |
username: root | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
apt update && apt install docker.io -y | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASS }} | |
docker ps -aq | xargs docker stop | xargs docker rm | |
docker run -d -p 5000:3001 ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} |