Skip to content

Commit

Permalink
realize service for prod and stage
Browse files Browse the repository at this point in the history
  • Loading branch information
elenashovtyuk committed Aug 31, 2023
1 parent 66050f2 commit 560adb4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/deploy-bot-on-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
name: prod_deploy
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: copy service file
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
password: ${{ secrets.VM_PASSWORD }}
source: "infra/prod/spread_wings_bot.service"
target: /home/deploy/spread_wings_bot/infra/prod/
- name: ssh pull and start
uses: appleboy/ssh-action@master
with:
Expand Down Expand Up @@ -61,6 +69,13 @@ jobs:
# Cleaning unused containers, images, networks
docker system prune --force
# Installing defend service for app
# Шаг с копированием в строках 16-23 можно заменить командой ниже - нужно тестировать
# scp infra/prod/spread_wings_bot.service .
cp -f /home/deploy/spread_wings_bot/infra/prod/spread_wings_bot.service /etc/systemd/system/spread_wings_bot.service
systemctl daemon-reload
systemctl restart spread_wings_bot.service
# Installing the app
docker-compose -f docker-compose.stage.yaml stop
docker-compose -f docker-compose.stage.yaml pull
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/deploy-bot-on-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
name: stage_deploy
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: copy service file
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
password: ${{ secrets.VM_PASSWORD }}
source: "infra/dev/spread_wings_bot.service"
target: /home/deploy/spread_wings_bot/infra/dev/
- name: ssh pull and start
uses: appleboy/ssh-action@master
with:
Expand Down Expand Up @@ -61,6 +69,13 @@ jobs:
# Cleaning unused containers, images, networks
docker system prune --force
# Installing defend service for app
# Шаг с копированием в строках 16-23 можно заменить командой ниже - нужно тестировать
# scp infra/dev/spread_wings_bot.service .
cp -f /home/deploy/spread_wings_bot/infra/dev/spread_wings_bot.service /etc/systemd/system/spread_wings_bot.service
systemctl daemon-reload
systemctl restart spread_wings_bot.service
# Installing the app
docker-compose -f docker-compose.stage.yaml stop
docker-compose -f docker-compose.stage.yaml pull
Expand Down
29 changes: 29 additions & 0 deletions infra/dev/spread_wings_bot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[Unit]

Description=spread_wings_bot
Requires=docker.service
After=docker.service

[Service]

Restart=always
RestartSec=5
TimeOutStartSec=1200
User=root

WorkingDirectory=/home/deploy/spread_wings_bot/infra/dev/

ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull bot
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull db
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull redis
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull nginx
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env down

# compose up
ExecStart=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env up

# compose down
ExecStop=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env down

[Install]
WantedBy=multi-user.target
29 changes: 29 additions & 0 deletions infra/prod/spread_wings_bot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[Unit]

Description=spread_wings_bot
Requires=docker.service
After=docker.service

[Service]

Restart=always
RestartSec=5
TimeOutStartSec=1200
User=root

WorkingDirectory=/home/deploy/spread_wings_bot/infra/prod/

ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull bot
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull db
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull redis
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull nginx
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env down

# compose up
ExecStart=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env up

# compose down
ExecStop=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env down

[Install]
WantedBy=multi-user.target

0 comments on commit 560adb4

Please sign in to comment.