Compare commits
2 Commits
d8f25ed430
...
2bbe34f703
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bbe34f703 | ||
|
|
4267dec319 |
@@ -1,7 +1,7 @@
|
||||
RABBITMQ_URL=amqp://guest:guest@127.0.0.1:5672/
|
||||
|
||||
|
||||
REDIS_ADDRESS=127.0.0.1:6379
|
||||
REDIS_ADDRESS=redis:6379
|
||||
REDIS_PASSWORD=
|
||||
REDIS_DB=0
|
||||
|
||||
|
||||
98
.github/workflows/deploy.yaml
vendored
Normal file
98
.github/workflows/deploy.yaml
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
|
||||
name: Deploy to Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
PROJECT_NAME: 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: ./docker/Dockerfile.web
|
||||
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 }}
|
||||
|
||||
@@ -15,6 +15,5 @@ FROM alpine
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=build /app/notification .
|
||||
COPY ./.env /app/
|
||||
|
||||
CMD ["./notification"]
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/JscorpTech/notification/internal/consumer"
|
||||
"github.com/JscorpTech/notification/internal/redis"
|
||||
@@ -12,7 +13,7 @@ var ctx = context.Background()
|
||||
|
||||
func main() {
|
||||
if err := godotenv.Load(); err != nil {
|
||||
panic(err)
|
||||
log.Println(".env not load")
|
||||
}
|
||||
redis.InitRedis()
|
||||
notification := consumer.NewNotificationConsumer(ctx)
|
||||
|
||||
35
stack.yaml
Normal file
35
stack.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
notification:
|
||||
image: jscorptech/taxi-notification:latest
|
||||
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
|
||||
Reference in New Issue
Block a user