Kishan Takoordyal 0b3918886d
Some checks failed
Run tests, build docker images and deploy / Docker build and push (push) Successful in 11m7s
Run tests, build docker images and deploy / Deploy on server (push) Failing after 21s
Improve build step
2025-08-12 19:03:46 +04:00

68 lines
2.3 KiB
YAML

name: Run tests, build docker images and deploy
run-name: Run tests, build docker images and deploy
on:
push:
branches:
- master
workflow_dispatch:
env:
DOCKER_JOB_ID: mscc-react-app
jobs:
docker-build:
name: Docker build and push
runs-on: ubuntu-latest
defaults:
run:
shell: sh
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker info
run: docker info
- name: Login to Gitea
uses: docker/login-action@v3
with:
registry: https://${{ vars.DOMAIN_NAME_GITEA }}
username: ${{ secrets.CI_REGISTRY_USER_GITEA }}
password: ${{ secrets.CI_BUILD_TOKEN_GITEA }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: '${{ vars.DOMAIN_NAME_GITEA }}/${{ gitea.repository }}:latest'
deploy:
name: Deploy on server
runs-on: ubuntu-latest
needs: docker-build
steps:
- name: Install openssh-client
run: |
apt update -qy
apt install -y openssh-client
- name: Configure SSH
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh
export SSH_PRIVATE_KEY_PATH=~/.ssh/id_rsa
echo "${{ secrets.WORKER_SSH_PRIVATE_KEY }}" > $SSH_PRIVATE_KEY_PATH
chmod 600 $SSH_PRIVATE_KEY_PATH
ssh-keyscan ${{ vars.SERVER_ADDRESS }} >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
eval $(ssh-agent -s)
- name: Checkout
uses: actions/checkout@v4
- name: Rebuild container
run: |
ssh -tt -l ${{ vars.SERVER_USERNAME }} ${{ vars.SERVER_ADDRESS }} "docker stop ${{ env.DOCKER_JOB_ID }} || true"
ssh -tt -l ${{ vars.SERVER_USERNAME }} ${{ vars.SERVER_ADDRESS }} "docker rm ${{ env.DOCKER_JOB_ID }} || true"
scp docker-compose.yml ${{ vars.SERVER_USERNAME }}@${{ vars.SERVER_ADDRESS }}:/tmp/docker-compose.yml
ssh -tt -l ${{ vars.SERVER_USERNAME }} ${{ vars.SERVER_ADDRESS }} "cd /tmp/ && docker compose down && docker compose up -d && rm -f /tmp/docker-compose.yml"