Merge pull request #61 from GlobeDaBoarder/dependabot/github_actions/… #52
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 to VM | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./dockerfile-app | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/app:${{ github.sha }} | |
- name: Create app deirectory if doesn't exist yet | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VM_HOST }} | |
username: ${{ secrets.VM_USERNAME }} | |
key: ${{ secrets.VM_PRIVATE_KEY }} | |
passphrase: ${{ secrets.VM_SSH_PASSPHRASE }} | |
script: | | |
mkdir -p ~/rivnegray | |
- name: Copy docker-compose file | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.VM_HOST }} | |
username: ${{ secrets.VM_USERNAME }} | |
key: ${{ secrets.VM_PRIVATE_KEY }} | |
passphrase: ${{ secrets.VM_SSH_PASSPHRASE }} | |
source: "docker-compose.app.yml" | |
target: "~/rivnegray/" | |
- name: replace image tag in docker-compose file via SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VM_HOST }} | |
username: ${{ secrets.VM_USERNAME }} | |
key: ${{ secrets.VM_PRIVATE_KEY }} | |
passphrase: ${{ secrets.VM_SSH_PASSPHRASE }} | |
script: | | |
sed -i "s/__TAG__/${{ github.sha }}/g" ~/rivnegray/docker-compose.app.yml | |
cat ~/rivnegray/docker-compose.app.yml | |
- name: Deploy to VM | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VM_HOST }} | |
username: ${{ secrets.VM_USERNAME }} | |
key: ${{ secrets.VM_PRIVATE_KEY }} | |
passphrase: ${{ secrets.VM_SSH_PASSPHRASE }} | |
script: | | |
cd ~/rivnegray/ | |
docker-compose -f docker-compose.app.yml down | |
docker-compose -f docker-compose.app.yml up -d |