Skip to content

Build & Deploy

Build & Deploy #25

Workflow file for this run

name: Build & Deploy
on:
workflow_dispatch: # Trigger the workflow manually
push:
branches:
- main # Trigger the workflow on push to the main branch
env:
APP_NAME: rpl-skandakra-bot
CONTAINER_NAME: rpl-skandakra-bot-container
jobs:
build_and_deploy:
runs-on: ubuntu-latest
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 "\n# Server id" > .env
echo "SERVER_ID=${{ secrets.SERVER_ID }}" > .env
echo "\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 "\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 $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 $APP_NAME ${{ secrets.DOCKER_HUB_USERNAME }}/$APP_NAME:latest
- run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/$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 }}/$APP_NAME:latest
# Stop and remove existing container if it's running
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
# Run the new container
docker run -d --name $CONTAINER_NAME --memory="128m" ${{ secrets.DOCKER_HUB_USERNAME }}/$APP_NAME:latest
EOF