fix bugs #50
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 Backend | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- 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_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build and push Docker image | |
run: | | |
docker buildx create --use | |
docker buildx build --platform linux/arm64/v8 -t therealyou322/backend:latest --push . | |
- name: Deploy to server | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # Приватный ключ для SSH, добавленный в Secrets | |
SERVER_USER: root # Имя пользователя на сервере | |
SERVER_HOST: 185.189.167.8 # IP или домен сервера | |
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} # Docker Hub username | |
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} # Docker Hub access token | |
run: | | |
# Сохраните приватный ключ в файл | |
echo "$SSH_PRIVATE_KEY" > id_rsa | |
chmod 600 id_rsa | |
mkdir -p ~/.ssh | |
# Добавьте ключ хоста сервера в known_hosts | |
ssh-keyscan -H 185.189.167.8>> ~/.ssh/known_hosts | |
# Копируйте файлы на сервер | |
scp -i id_rsa docker-compose.yml [email protected]:/path/to/deploy/ | |
# Подключитесь к серверу и выполните команды | |
ssh -i id_rsa [email protected]<< 'EOF' | |
cd /path/to/deploy/ | |
docker-compose pull | |
docker-compose down | |
docker-compose up -d | |
docker system prune -f | |
EOF | |