Discord Bot을 Oracle Cloud Infrastructure (OCI)에 배포하는 방법입니다.
-
OCI 인스턴스 생성 완료
- Shape:
VM.Standard.E2.1.Micro(Always Free) - OS: Ubuntu 22.04 (또는 Oracle Linux)
- Public IP 할당 완료
- Shape:
-
GitHub Secrets 설정
- 저장소 Settings → Secrets and variables → Actions에서 다음 추가:
ORACLE_HOST: OCI 인스턴스 공인 IP 주소ORACLE_USER:ubuntu(Ubuntu 이미지) 또는opc(Oracle Linux)ORACLE_SSH_PRIVATE_KEY: SSH 개인키 전체 내용 (.pem파일 내용)
- 저장소 Settings → Secrets and variables → Actions에서 다음 추가:
ssh -i <다운받은-키>.pem ubuntu@<공인IP>Ubuntu:
sudo apt update
sudo apt install -y python3 python3-pip python3-venv gitOracle Linux:
sudo yum update -y
sudo yum install -y python39 python39-pip gitcd ~
git clone https://github.com/<your-username>/<your-repo>.git discord-bot
cd discord-bot
# 가상환경 생성
python3 -m venv venv
source venv/bin/activate
# 의존성 설치
pip install --upgrade pip
pip install -r requirements.txt# .env 파일 생성
nano .env다음 내용 추가:
DISCORD_BOT_TOKEN=your_bot_token_here
Ubuntu 사용자:
sudo tee /etc/systemd/system/discord-bot.service > /dev/null <<EOF
[Unit]
Description=Discord Bot
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/discord-bot
Environment="PATH=/home/ubuntu/discord-bot/venv/bin"
ExecStart=/home/ubuntu/discord-bot/venv/bin/python main.py
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOFOracle Linux (opc 사용자):
sudo tee /etc/systemd/system/discord-bot.service > /dev/null <<EOF
[Unit]
Description=Discord Bot
After=network.target
[Service]
Type=simple
User=opc
WorkingDirectory=/home/opc/discord-bot
Environment="PATH=/home/opc/discord-bot/venv/bin"
ExecStart=/home/opc/discord-bot/venv/bin/python main.py
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF서비스 활성화:
sudo systemctl daemon-reload
sudo systemctl enable discord-bot
sudo systemctl start discord-botchmod +x deploy.sh-
Secrets 설정 확인
ORACLE_HOST,ORACLE_USER,ORACLE_SSH_PRIVATE_KEY모두 설정되어 있는지 확인
-
자동 배포 동작
main브랜치에 푸시하면 자동으로 배포됩니다- GitHub Actions 탭에서 배포 상태 확인 가능
-
수동 배포
- GitHub Actions 탭 → "Deploy Discord Bot to Oracle Cloud" → "Run workflow" 클릭
서버에 SSH 접속 후:
cd ~/discord-bot
./deploy.sh또는 GitHub Actions 워크플로우를 사용하지 않고 직접:
cd ~/discord-bot
git pull origin main
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart discord-bot# 실시간 로그
sudo journalctl -u discord-bot -f
# 최근 50줄
sudo journalctl -u discord-bot -n 50
# 서비스 상태 확인
sudo systemctl status discord-bottail -f ~/discord-bot/bot.log- GitHub Actions 로그 확인
- 서버에 SSH 접속하여 수동으로
./deploy.sh실행 - 로그 확인하여 에러 원인 파악
# 서비스 상태 확인
sudo systemctl status discord-bot
# 로그 확인
sudo journalctl -u discord-bot -n 100
# 수동 실행 테스트
cd ~/discord-bot
source venv/bin/activate
python main.pycd ~/discord-bot
git status
git fetch origin
git reset --hard origin/mainOCI 콘솔에서:
- Billing → Cost Analysis에서 실제 비용 확인
- Always Free 범위 내에서 사용하면 $0.00으로 표시됩니다
- Always Free 인스턴스는 월 2개까지 생성 가능
- Block Volume 총합 200GB까지 무료
- 네트워크 트래픽은 월 10TB까지 무료