Compare commits

..

5 Commits

Author SHA1 Message Date
github-actions[bot]
8c18978460 🔄 Update image to 3 [CI SKIP] 2025-11-05 14:49:03 +00:00
A'zamov Samandar
9fd19b8f7c fix typo
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 1m6s
2025-11-05 19:48:04 +05:00
A'zamov Samandar
b69a128a76 fix typo
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 1m5s
2025-11-05 19:43:16 +05:00
A'zamov Samandar
2bbe34f703 feat(devops)
Some checks failed
Deploy to Production / build-and-deploy (push) Failing after 15s
2025-11-05 19:41:57 +05:00
A'zamov Samandar
4267dec319 feat(devops): stack file created 2025-11-05 19:25:42 +05:00
5 changed files with 137 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
RABBITMQ_URL=amqp://guest:guest@127.0.0.1:5672/ RABBITMQ_URL=amqp://guest:guest@127.0.0.1:5672/
REDIS_ADDRESS=127.0.0.1:6379 REDIS_ADDRESS=redis:6379
REDIS_PASSWORD= REDIS_PASSWORD=
REDIS_DB=0 REDIS_DB=0

98
.github/workflows/deploy.yaml vendored Normal file
View File

@@ -0,0 +1,98 @@
name: Deploy to Production
on:
push:
branches:
- main
env:
PROJECT_NAME: taxi-notification
permissions:
contents: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Copy env
run: |
cp .env.example .env
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: false
load: true
tags: ${{ env.PROJECT_NAME }}:test
no-cache: true
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Tag and push to Docker Hub
run: |
docker tag ${{ env.PROJECT_NAME }}:test ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:latest
docker tag ${{ env.PROJECT_NAME }}:test ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ github.run_number }}
docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:latest
docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ github.run_number }}
echo "SUCCESS TAGS: latest, ${{ github.run_number }}"
- name: Update stack.yaml and version
run: |
sed -i 's|image: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:.*|image: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ github.run_number }}|' stack.yaml
- name: Commit and push updated version
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "🔄 Update image to ${{ github.run_number }} [CI SKIP]" || echo "No changes"
git pull origin main --rebase
git push origin main
- name: Deploy to server via SSH
uses: appleboy/ssh-action@v1.2.2
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
# key: ${{ secrets.KEY }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
PROJECTS=/opt/projects/
DIR=/opt/projects/${{ env.PROJECT_NAME }}/
if [ -d "$PROJECTS" ]; then
echo "projects papkasi mavjud"
else
mkdir -p $PROJECTS
echo "projects papkasi yaratildi"
fi
if [ -d "$DIR" ]; then
echo "loyiha mavjud"
else
cd $PROJECTS
git clone git@gitea.felixits.uz:${{ github.repository }}.git ${{ env.PROJECT_NAME }}
echo "Clone qilindi";
fi
cd $DIR
git fetch origin main
git reset --hard origin/main
docker stack deploy -c stack.yaml ${{ env.PROJECT_NAME }}

View File

@@ -15,6 +15,5 @@ FROM alpine
WORKDIR /app WORKDIR /app
COPY --from=build /app/notification . COPY --from=build /app/notification .
COPY ./.env /app/
CMD ["./notification"] CMD ["./notification"]

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"log"
"github.com/JscorpTech/notification/internal/consumer" "github.com/JscorpTech/notification/internal/consumer"
"github.com/JscorpTech/notification/internal/redis" "github.com/JscorpTech/notification/internal/redis"
@@ -12,7 +13,7 @@ var ctx = context.Background()
func main() { func main() {
if err := godotenv.Load(); err != nil { if err := godotenv.Load(); err != nil {
panic(err) log.Println(".env not load")
} }
redis.InitRedis() redis.InitRedis()
notification := consumer.NewNotificationConsumer(ctx) notification := consumer.NewNotificationConsumer(ctx)

35
stack.yaml Normal file
View File

@@ -0,0 +1,35 @@
version: "3.8"
services:
notification:
image: jscorptech/taxi-notification:3
env_file:
- /opt/env/.notification
networks:
- taxi
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
failure_action: rollback
monitor: 10s
delay: 10s
max_failure_ratio: 0.2
resources:
limits:
cpus: "2"
memory: 1024M
logging:
driver: json-file
options:
max-size: "10m"
max-file: 10
networks:
taxi:
driver: overlay
external: true
attachable: true