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: Main workflow | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build_and_push: | |
name: Build Docker images and push them to DockerHub | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- image_name: valeevilja/cppbot:v1 | |
dockerfile: Dockerfile | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Login to Docker Hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
deploy: | |
name: Deploy to server | |
runs-on: ubuntu-latest | |
needs: build_and_push | |
steps: | |
- name: Checkout code | |
uses: actions/[email protected] | |
- name: executing remote ssh commands to deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
key: ${{ secrets.SSH_KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
script: | | |
cd ${{ secrets.DEPLOY_PATH }} | |
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" > .env | |
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env | |
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env | |
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env | |
echo POSTGRES_PORT=${{ secrets.POSTGRES_PORT }} >> .env | |
echo POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} >> .env | |
echo ADMIN_CHAT_ID=${{ secrets.ADMIN_CHAT_ID }} >> .env | |
echo NGROK_AUTHTOKEN=${{ secrets.NGROK_AUTHTOKEN }} >> .env | |
echo BASE_WEBHOOK_URL=${{ secrets.BASE_WEBHOOK_URL }} >> .env | |
echo NGROK_URL=${{ secrets.NGROK_URL }} >> .env | |
sudo docker compose down | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/cppbot:v1 | |
sudo docker compose up -d --build | |
sudo docker system prune -af | |
send_message: | |
runs-on: ubuntu-latest | |
needs: deploy | |
steps: | |
- name: send message | |
uses: appleboy/telegram-action@master | |
with: | |
to: ${{ secrets.TELEGRAM_TO }} | |
token: ${{ secrets.TELEGRAM_TOKEN }} | |
message: ${{ github.workflow }} успешно выполнен! | |