-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (56 loc) · 2.6 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Build & Deploy
on:
workflow_dispatch: # Trigger the workflow manually
push:
branches:
- main # Trigger the workflow on push to the main branch
jobs:
build_and_deploy:
runs-on: ubuntu-latest
env:
APP_NAME: rpl-skandakra-bot
CONTAINER_NAME: rpl-skandakra-bot-container
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create .env file
run: |
echo "# Bot credentials" > .env
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" >> .env
echo "BOT_ID=${{ secrets.BOT_ID }}" >> .env
echo -e "\n# Server id" >> .env
echo "SERVER_ID=${{ secrets.SERVER_ID }}" >> .env
echo -e "\n# List channels" >> .env
echo "CH_INTRO_ID=${{ secrets.CH_INTRO_ID }}" >> .env
echo "CH_LEAVE_ID=${{ secrets.CH_LEAVE_ID }}" >> .env
echo "CH_LOBBY_ID=${{ secrets.CH_LOBBY_ID }}" >> .env
echo "CH_LOG_ID=${{ secrets.CH_LOG_ID }}" >> .env
echo "CH_ROLE_ID=${{ secrets.CH_ROLE_ID }}" >> .env
echo "CH_RULES_ID=${{ secrets.CH_RULES_ID }}" >> .env
echo -e "\n# List roles" >> .env
echo "ROLE_ADMIN_ID=${{ secrets.ROLE_ADMIN_ID }}" >> .env
echo "ROLE_MEMBER_ID=${{ secrets.ROLE_MEMBER_ID }}" >> .env
- name: Build the Docker image
run: docker build -t ${{ env.APP_NAME }} .
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Push Docker image
run: docker tag ${{ env.APP_NAME }} ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest
- run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest
- name: Set up SSH agent for deployment
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.VPS_PRIVATE_KEY }}
- name: Deploy to VPS
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF'
# Pull the latest Docker image
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest
# Stop and remove existing container if it's running
docker stop ${{ env.CONTAINER_NAME }} || true
docker rm ${{ env.CONTAINER_NAME }} || true
# Run the new container
docker run -d --name ${{ env.CONTAINER_NAME }} --memory="128m" ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}:latest
# Check Docker container logs
docker logs ${{ env.CONTAINER_NAME }}
EOF