Skip to content

Scripts

Scripts #2

name: Build Image and Deploy
on:
push:
branches:
- "devops/ssh"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Add .env
run: |
echo ${{ secrets.ENV }} >> .env
cat .env
- name: Build and push image
uses: mr-smithers-excellent/docker-build-push@v5
with:
image: calebackom/monsters-rolodex
tags: latest
registry: docker.io
dockerfile: Dockerfile
directory: ./
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
deploy:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
docker pull calebackom/monsters-rolodex:latest
docker ps -q --filter ancestor=calebackom/monsters-rolodex | xargs -r docker stop
docker run -d -p 3000:3000 calebackom/monsters-rolodex