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 | |
dockerfile: Dockerfile | |
steps: | |
- 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: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ matrix.image_name }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
platforms: linux/amd64 | |
file: ${{ matrix.dockerfile }} | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy: | |
name: Deploy to server | |
runs-on: ubuntu-latest | |
needs: build_and_push | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Copy infra files to server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.SERVER }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "cppinfra/docker-compose.yml,cppinfra/swag_nginx.conf" | |
target: ${{ secrets.DEPLOY_PATH }} | |
overwrite: true | |
strip_components: 1 | |
- 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 BASE_WEBHOOK_URL=${{ secrets.BASE_WEBHOOK_URL }} >> .env | |
sudo docker-compose down | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/cppbot | |
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 }} успешно выполнен! |