All checks were successful
PR Build Check / build (pull_request) Successful in 2m11s
60 lines
1.6 KiB
YAML
60 lines
1.6 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Extract Tag Name
|
|
id: extract_tag
|
|
run: |
|
|
TAG_NAME=${GITHUB_REF#refs/tags/}
|
|
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
|
|
|
- name: Build and Push Docker Image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
tags: |
|
|
rooftopenergy/rooftop_dpmdashboard:${{ steps.extract_tag.outputs.tag }}
|
|
|
|
- name: Install sshpass
|
|
run: sudo apt-get update && sudo apt-get install -y sshpass
|
|
|
|
- name: Deploy to VPS
|
|
env:
|
|
SSHPASS: ${{ secrets.VPS_PASSWORD }}
|
|
run: |
|
|
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << EOF
|
|
set -e
|
|
|
|
echo "Using tag: ${{ steps.extract_tag.outputs.tag }}"
|
|
|
|
cd /root/UserDashboard
|
|
|
|
sed -i "s|rooftopenergy/rooftop_dpmdashboard:.*|rooftopenergy/rooftop_dpmdashboard:${{ steps.extract_tag.outputs.tag }}|g" docker-compose.yml
|
|
|
|
docker compose down
|
|
docker compose pull
|
|
docker compose up -d
|
|
EOF
|