main
This commit is contained in:
69
.gitea/workflows/deploy.yaml
Normal file
69
.gitea/workflows/deploy.yaml
Normal file
@@ -0,0 +1,69 @@
|
||||
name: Build and Deploy Backend
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ secrets.DOCKER_USERNAME }}/skript-be:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
deploy:
|
||||
needs: build-and-push
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy via SSH
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: |
|
||||
# Pull latest image
|
||||
docker pull ${{ secrets.DOCKER_USERNAME }}/skript-be:latest
|
||||
|
||||
# Stop existing container
|
||||
docker stop skript-be || true
|
||||
docker rm skript-be || true
|
||||
|
||||
# Run new container
|
||||
docker run -d \
|
||||
--name skript-be \
|
||||
--restart always \
|
||||
--network gitea \
|
||||
-p 1502:3000 \
|
||||
-e DATABASE_URL='${{ secrets.DATABASE_URL }}' \
|
||||
-e REDIS_HOST='${{ secrets.REDIS_HOST }}' \
|
||||
-e JWT_SECRET='${{ secrets.JWT_SECRET }}' \
|
||||
-e GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}' \
|
||||
${{ secrets.DOCKER_USERNAME }}/skript-be:latest
|
||||
|
||||
# Prune unused images to save space
|
||||
docker image prune -f
|
||||
Reference in New Issue
Block a user