Skip to content

Merge pull request #4 from leonidgrishenkov/dev-sqlite #18

Merge pull request #4 from leonidgrishenkov/dev-sqlite

Merge pull request #4 from leonidgrishenkov/dev-sqlite #18

Workflow file for this run

---
# yamllint disable rule:line-length
name: Deploy the bot
on:
push:
tags:
- "*"
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Extract Git Tag
id: extract_tag
run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Generate .env file
run: |
echo "YC_S3_ADMIN_SA_ACCESS_KEY=${{ secrets.YC_S3_ADMIN_SA_ACCESS_KEY }}" >> .env
echo "YC_S3_ADMIN_SA_SECRET_KEY=${{ secrets.YC_S3_ADMIN_SA_SECRET_KEY }}" >> .env
echo "TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }}" >> .env
echo "S3_BUCKET_NAME=${{ vars.S3_BUCKET_NAME }}" >> .env
echo "APP_LOG_LEVEL=${{ vars.APP_LOG_LEVEL }}" >> .env
- name: Log docker in to the Yandex Cloud Registry
run: echo "${{ secrets.YC_OAUTH_TOKEN }}" | docker login --username oauth --password-stdin cr.yandex
- name: Build Docker image
run: docker build --quiet -t cr.yandex/${{ secrets.YC_REGISTRY_ID }}/${{ github.event.repository.name }}:${{ env.TAG }} .
- name: Push Docker image to the Registry
run: docker push --quiet cr.yandex/${{ secrets.YC_REGISTRY_ID }}/${{ github.event.repository.name }}:${{ env.TAG }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.YC_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "Host target-compute-intance" >> ~/.ssh/config
echo " HostName ${{ vars.YC_COMPUTE_EXT_IP }}" >> ~/.ssh/config
echo " User ${{ vars.YC_COMPUTE_USER }}" >> ~/.ssh/config
echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
echo " StrictHostKeyChecking no" >> ~/.ssh/config
- name: Run new Docker image
run: |
ssh target-compute-intance 'if [ "$(docker ps -q -f name=${{ github.event.repository.name }})" ]; then docker stop ${{ github.event.repository.name }}; fi'
ssh target-compute-intance 'docker run -d -q --rm --name=${{ github.event.repository.name }} cr.yandex/${{ secrets.YC_REGISTRY_ID }}/${{ github.event.repository.name }}:${{ env.TAG }}'