Skip to content

Commit ea5b830

Browse files
committed
tech: services added in project and scaleway gh action updated
1 parent 2ddd83e commit ea5b830

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

.github/workflows/deploy-to-scaleway.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,46 @@ jobs:
2626
SCW_USER: ${{ secrets.SCW_USER }}
2727
run: |
2828
ssh -o StrictHostKeyChecking=no $SCW_USER@$SCW_HOST << 'EOF'
29-
set -e # This will make the script exit immediately if any command fails
30-
31-
cd /home/${{ secrets.SCW_USER }}/aigle-api || exit 1
32-
33-
# Fetch and reset to remote branch
29+
set -e
30+
31+
cd /home/ubuntu/aigle-api || exit 1
32+
33+
# Fetch latest code
3434
git fetch origin ${{ github.ref_name }} || exit 1
3535
git reset --hard origin/${{ github.ref_name }} || exit 1
36-
37-
set -a # Enable auto-export of variables
36+
37+
# Export env vars
38+
set -a
3839
source .env || exit 1
39-
set +a # Disable auto-export of variables
40-
40+
set +a
41+
42+
# Install packages
4143
xargs -a Aptfile sudo apt install -y || exit 1
42-
44+
45+
# Start Redis
4346
sudo systemctl start redis-server || exit 1
4447
sudo systemctl enable redis-server || exit 1
4548
49+
# Set up services
50+
sudo cp celery.service /etc/systemd/system/ || exit 1
51+
sudo cp gunicorn_aigle.service /etc/systemd/system/ || exit 1
52+
sudo systemctl daemon-reload || exit 1
53+
sudo systemctl enable celery || exit 1
54+
sudo systemctl enable gunicorn_aigle || exit 1
55+
56+
# Activate Python env and apply migrations
4657
source venv/bin/activate || exit 1
4758
python -m pip install -r requirements.txt || exit 1
4859
python manage.py migrate || exit 1
4960
50-
python -m celery -A aigle worker --loglevel=info || exit 1
61+
# Restart services
62+
sudo systemctl restart celery || exit 1
5163
sudo systemctl restart gunicorn_aigle || exit 1
52-
64+
5365
echo "Deployment completed successfully!"
5466
EOF
5567
56-
# Check the exit status of the SSH command
68+
# Check SSH command result
5769
if [ $? -ne 0 ]; then
5870
echo "Deployment failed!"
5971
exit 1

services/celery.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Celery Service
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=ubuntu
8+
Group=ubuntu
9+
WorkingDirectory=/home/ubuntu/aigle-api
10+
EnvironmentFile=/home/ubuntu/aigle-api/.env
11+
ExecStart=/home/ubuntu/aigle-api/venv/bin/celery -A aigle worker --loglevel=info
12+
Restart=always
13+
14+
[Install]
15+
WantedBy=multi-user.target

services/gunicorn_aigle.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=gunicorn daemon for Aigle API
3+
After=network.target
4+
5+
[Service]
6+
EnvironmentFile=/home/ubuntu/aigle-api/.env
7+
User=ubuntu
8+
Group=ubuntu
9+
WorkingDirectory=/home/ubuntu/aigle-api
10+
ExecStart=/home/ubuntu/aigle-api/venv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 aigle.wsgi:application
11+
Restart=on-failure
12+
13+
[Install]
14+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)