51 lines
1.6 KiB
YAML
51 lines
1.6 KiB
YAML
name: Deploy Next.js with Docker
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_URL }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile.production
|
|
push: true
|
|
tags: |
|
|
${{ secrets.REGISTRY_URL }}/portal-dias-rota:latest
|
|
${{ secrets.REGISTRY_URL }}/portal-dias-rota:${{ github.sha }}
|
|
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/portal-dias-rota:buildcache
|
|
cache-to: type=registry,ref=${{ secrets.REGISTRY_URL }}/portal-dias-rota:buildcache,mode=max
|
|
|
|
- name: Deploy to server
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
username: ${{ secrets.DEPLOY_USER }}
|
|
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
port: ${{ secrets.DEPLOY_PORT || 22 }}
|
|
script: |
|
|
cd ${{ secrets.DEPLOY_PATH }}
|
|
docker pull ${{ secrets.REGISTRY_URL }}/portal-dias-rota:latest
|
|
docker-compose down
|
|
docker-compose up -d
|
|
docker image prune -f
|