Skip to content

Instantly share code, notes, and snippets.

@Dostonlv
Created December 2, 2024 16:51
Show Gist options
  • Save Dostonlv/a13116ae0e9b310a350e1d44c1069adf to your computer and use it in GitHub Desktop.
Save Dostonlv/a13116ae0e9b310a350e1d44c1069adf to your computer and use it in GitHub Desktop.
name: CI/CD Pipeline
on:
push:
branches:
- feat/cd
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
# 1. Repositoryni checkout qilish
- name: Checkout the repository
uses: actions/checkout@v3
# 2. Go modullarini keshlash
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# 3. Go muhitini sozlash
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.23.1'
# 4. Serverga ulanish va joylashtirish
- name: Deploy to Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: 22
script: |
echo "📦 Kodni yangilayapman..."
cd /root/sphere_ci_cd_backend
git pull ${{secrets.GIT_REPO}} feat/cd
echo "🔍 go.mod fayllarini qidiryapman..."
find ./sphere_ci_cd_backend -name "go.mod" -execdir go mod tidy \;
echo "🔄 Docker build keshlarini tozalayapman..."
docker builder prune -af
echo "🛑 Ishlayotgan xizmatlarni to'xtatish..."
# docker-compose -f docker-compose.yml down
echo "🚀 Docker image’larni yaratish va xizmatlarni ishga tushirish..."
# docker-compose -f docker-compose.yml up --build -d --remove-orphans
docker-compose up --build -d
echo "🧹 Eskirgan konteyner va imijlarni tozalayapman..."
docker system prune -af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment