Skip to content

update stage

update stage #112

Workflow file for this run

name: CI-CD
on:
push:
branches: [main, dev]
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.branch.outputs.value }}
is_production: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Extract branch name
id: branch
run: echo "value=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
build-and-push:
needs: prepare
if: github.repository_owner == 'Endpool'
strategy:
matrix:
component: ['backend', 'frontend']
runs-on: ubuntu-latest
steps:
- name: Checkout root repository
uses: actions/checkout@v4
with:
submodules: false
- name: Clone submodules directly
run: |
BRANCH="${{ needs.prepare.outputs.branch_name }}"
git clone -b $BRANCH --depth 1 \
https://github.com/Endpool/CookCookhNya-backend Backend || \
git clone -b main --depth 1 \
https://github.com/Endpool/CookCookhNya-backend Backend
git clone -b $BRANCH --depth 1 \
https://github.com/Endpool/CookCookhNya-frontend Frontend || \
git clone -b main --depth 1 \
https://github.com/Endpool/CookCookhNya-frontend Frontend
- name: Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Buildx
if: matrix.component == 'frontend'
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.component == 'backend' && 'Backend' || 'Frontend' }}
push: true
tags: j0cos/cookcookhny-${{ matrix.component }}:${{ github.sha }}
cache-from: ${{ matrix.component == 'frontend' && 'type=gha' || '' }}
cache-to: ${{ matrix.component == 'frontend' && 'type=gha,mode=max' || '' }}
deploy:
needs: [prepare, build-and-push]
if: github.repository_owner == 'Endpool'
runs-on: ubuntu-latest
steps:
- name: Deploy to target environment
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
# Set environment variables
IS_PROD=${{ needs.prepare.outputs.is_production }}
ENV_DIR="/home/rash/$([ "$IS_PROD" = "true" ] && echo "app" || echo "app-stage")"
cd $ENV_DIR
echo "BACKEND_TAG=${{ github.sha }}
FRONTEND_TAG=${{ github.sha }}
BOT_TOKEN=$([ "$IS_PROD" = "true" ] && echo "${{ secrets.BOT_TOKEN }}" || echo "${{ secrets.BOT_TOKEN_STAGE }}")
API_URL=http://backend:8080
DB_NAME=${{ secrets.DB_NAME }}
DB_USER=${{ secrets.DB_USER }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
INVITATIONS_SECRET_KEY=${{ secrets.INVITATIONS_SECRET_KEY }}
WEBHOOK_PORT=8443
WEBHOOK_HOST=${{ secrets.WEBHOOK_HOST }}
WEBHOOK_SECRET=${{ secrets.WEBHOOK_SECRET }}" > .env
docker compose down
docker compose up -d