This commit is contained in:
@@ -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
|
||||||
|
|
||||||
@@ -20,4 +20,4 @@ MAIL_PORT=587
|
|||||||
|
|
||||||
PMB_DOMAIN=""
|
PMB_DOMAIN=""
|
||||||
PMB_USER=""
|
PMB_USER=""
|
||||||
PMB_PASSWORD=""
|
PMB_PASSWORD=""
|
||||||
|
|||||||
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
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=build /app/notification .
|
COPY --from=build /app/notification .
|
||||||
COPY ./.env /app/
|
|
||||||
|
|
||||||
CMD ["./notification"]
|
CMD ["./notification"]
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
11
stack.yaml
11
stack.yaml
@@ -3,13 +3,10 @@ version: "3.8"
|
|||||||
services:
|
services:
|
||||||
notification:
|
notification:
|
||||||
image: jscorptech/taxi-notification:latest
|
image: jscorptech/taxi-notification:latest
|
||||||
|
env_file:
|
||||||
|
- /opt/env/.notification
|
||||||
networks:
|
networks:
|
||||||
- taxi
|
- taxi
|
||||||
ports:
|
|
||||||
- mode: ingress
|
|
||||||
target: 8000
|
|
||||||
published: ${PORT:?PORT not found}
|
|
||||||
protocol: tcp
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
@@ -17,10 +14,10 @@ services:
|
|||||||
update_config:
|
update_config:
|
||||||
parallelism: 1
|
parallelism: 1
|
||||||
order: start-first
|
order: start-first
|
||||||
failure-action: rollback
|
failure_action: rollback
|
||||||
monitor: 10s
|
monitor: 10s
|
||||||
delay: 10s
|
delay: 10s
|
||||||
max_failure_ration: 0.2
|
max_failure_ratio: 0.2
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpus: "2"
|
cpus: "2"
|
||||||
|
|||||||
Reference in New Issue
Block a user