Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MySQL
DB_HOST=
DB_PORT=3306
DB_NAME=
DB_USER=
DB_PASSWORD=

# MongoDB
MONGO_HOST=
MONGO_PORT=27017
MONGO_DB=
MONGO_USER=
MONGO_PASSWORD=

# Redis
REDIS_HOST=
REDIS_PORT=0
REDIS_DB=
REDIS_PASSWORD=

# Koreatech Portal
PORTAL_ID=
PORTAL_PW=
PORTAL_IP=

# Gmail
GMAIL_ID=
GMAIL_PW=

# Slack
SLACK_WEBHOOK_URL=

# AWS S3
S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
S3_BUCKET=
S3_UPLOAD_DOMAIN=

# Batch API
BATCH_EMAIL=
BATCH_PASSWORD=
BATCH_TOKEN_URL=
BATCH_NOTIFICATION_API_URL=
83 changes: 83 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: KOIN_BATCH CD (develop)

on:
push:
branches:
- develop

jobs:
deploy:
runs-on: ubuntu-latest
environment: development

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Record start time
run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV

- name: Notify Slack - Deploy Start
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \":rocket: *[Develop] KOIN_BATCH 배포 시작*\n• Repo: ${{ github.repository }}\n• Branch: develop\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• <${ACTIONS_URL}|Actions 보기>\"
}"

- name: Create archive
run: tar -cvzf batch.tar.gz --exclude='.git' --exclude='.github' .

- name: Transfer archive to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
source: batch.tar.gz
target: ${{ secrets.DEPLOY_PATH }}

- name: Execute deploy commands
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
source ~/.profile
cd ${{ secrets.DEPLOY_PATH }}
tar -xvzf batch.tar.gz
rm batch.tar.gz
chmod +x run.sh
pip3 install -r requirements.txt

cp -n crawling/config.example.py crawling/config.py
cp -n crawling/koreatech_article/config.example.py crawling/koreatech_article/config.py
cp -n crawling/koreatech_portal/config.example.py crawling/koreatech_portal/config.py
cp -n crawling/city_bus/config.example.py crawling/city_bus/config.py

- name: Notify Slack - Deploy Result
if: always()
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
DURATION_SEC=$(( $(date +%s) - START_TIME ))
DURATION="${DURATION_SEC}초 (약 $(( DURATION_SEC / 60 ))분)"
if [ "${{ job.status }}" = "success" ]; then
ICON=":white_check_mark:"
STATUS="배포 성공"
else
ICON=":x:"
STATUS="배포 실패"
fi
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \"${ICON} *[Develop] KOIN_BATCH ${STATUS}*\n• Repo: ${{ github.repository }}\n• Branch: develop\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• Duration: ${DURATION}\n• <${ACTIONS_URL}|Actions 보기>\"
}"
81 changes: 81 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: KOIN_BATCH CD (production)

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Record start time
run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV

- name: Notify Slack - Deploy Start
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \":rocket: *[Production] KOIN_BATCH 배포 시작*\n• Repo: ${{ github.repository }}\n• Branch: master\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• <${ACTIONS_URL}|Actions 보기>\"
}"

- name: Create archive
run: tar -cvzf batch.tar.gz --exclude='.git' --exclude='.github' .

- name: Transfer archive to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
source: batch.tar.gz
target: ${{ secrets.DEPLOY_PATH }}

- name: Execute deploy commands
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
source ~/.profile
cd ${{ secrets.DEPLOY_PATH }}
tar -xvzf batch.tar.gz
rm batch.tar.gz
chmod +x run.sh
pip3 install -r requirements.txt

cp -n crawling/config.example.py crawling/config.py
cp -n crawling/koreatech_article/config.example.py crawling/koreatech_article/config.py
cp -n crawling/koreatech_portal/config.example.py crawling/koreatech_portal/config.py
cp -n crawling/city_bus/config.example.py crawling/city_bus/config.py

- name: Notify Slack - Deploy Result
if: always()
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
DURATION_SEC=$(( $(date +%s) - START_TIME ))
DURATION="${DURATION_SEC}초 (약 $(( DURATION_SEC / 60 ))분)"
if [ "${{ job.status }}" = "success" ]; then
ICON=":white_check_mark:"
STATUS="배포 성공"
else
ICON=":x:"
STATUS="배포 실패"
fi
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \"${ICON} *[Production] KOIN_BATCH ${STATUS}*\n• Repo: ${{ github.repository }}\n• Branch: master\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• Duration: ${DURATION}\n• <${ACTIONS_URL}|Actions 보기>\"
}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env
!.env.example
.vscode
crawling/__pycache__
crawling/config.py
Expand Down
18 changes: 11 additions & 7 deletions crawling/city_bus/config.example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
MONGO_CONFIG = {
'host': '',
'port': '',
'db': '',
'user': '',
'password': ''
}
import importlib.util
import os

_parent_config = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'config.py')
_spec = importlib.util.spec_from_file_location('_central_config', _parent_config)
_mod = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_mod)

for _name in dir(_mod):
if not _name.startswith('_'):
globals()[_name] = getattr(_mod, _name)
65 changes: 53 additions & 12 deletions crawling/config.example.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
import os
from pathlib import Path

from dotenv import load_dotenv

load_dotenv(Path(__file__).resolve().parent.parent / '.env')

DATABASE_CONFIG = {
'host': '',
'db': '',
'user': '',
'password': '',
'port': 3306
'host': os.getenv('DB_HOST', ''),
'port': int(os.getenv('DB_PORT', '3306')),
'db': os.getenv('DB_NAME', ''),
'user': os.getenv('DB_USER', ''),
'password': os.getenv('DB_PASSWORD', ''),
}

MYSQL_CONFIG = DATABASE_CONFIG

MONGO_CONFIG = {
'host': os.getenv('MONGO_HOST', ''),
'port': int(os.getenv('MONGO_PORT', '27017')),
'db': os.getenv('MONGO_DB', ''),
'user': os.getenv('MONGO_USER', ''),
'password': os.getenv('MONGO_PASSWORD', ''),
}

REDIS_CONFIG = {
'host': os.getenv('REDIS_HOST', ''),
'port': int(os.getenv('REDIS_PORT', '0')),
'db': os.getenv('REDIS_DB', ''),
'password': os.getenv('REDIS_PASSWORD', ''),
}

PORTAL_CONFIG = {
'id': os.getenv('PORTAL_ID', ''),
'pw': os.getenv('PORTAL_PW', ''),
'ip': os.getenv('PORTAL_IP', ''),
}

GMAIL_CONFIG = {
'id': os.getenv('GMAIL_ID', ''),
'pw': os.getenv('GMAIL_PW', ''),
}

SLACK_CONFIG = {
'url': ''
'url': os.getenv('SLACK_WEBHOOK_URL', ''),
}

MONGO_CONFIG = {
'host': '',
'port': '',
'db': '',
'user': '',
'password': ''
S3_CONFIG = {
'aws_access_key_id': os.getenv('S3_ACCESS_KEY_ID', ''),
'aws_secret_access_key': os.getenv('S3_SECRET_ACCESS_KEY', ''),
'bucket': os.getenv('S3_BUCKET', ''),
'upload_domain': os.getenv('S3_UPLOAD_DOMAIN', ''),
}

BATCH_CONFIG = {
'email': os.getenv('BATCH_EMAIL', ''),
'password': os.getenv('BATCH_PASSWORD', ''),
'token_url': os.getenv('BATCH_TOKEN_URL', ''),
'notification_api_url': os.getenv('BATCH_NOTIFICATION_API_URL', ''),
}
Loading