diff --git a/.github/workflows/autocomplete-batch-job.yml b/.github/workflows/autocomplete-batch-job.yml new file mode 100644 index 0000000..b31b433 --- /dev/null +++ b/.github/workflows/autocomplete-batch-job.yml @@ -0,0 +1,34 @@ +name: Autocomplete Batch Job + +on: + workflow_dispatch: + push: + branches: + - main + schedule: + - cron: '0 0 * * *' + +jobs: + batch-job: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Docker Build And Push + run: | + docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }} + docker build -t skku-autocomplete-batch . + docker tag skku-autocomplete-batch sinkyoungdeok/skku-autocomplete-batch + docker push sinkyoungdeok/skku-autocomplete-batch + - name: Deploy Prod + uses: appleboy/ssh-action@v0.1.4 + with: + key: ${{ secrets.SSH_KEY }} + host: ${{ secrets.HOST_NAME }} + username: ubuntu + port: 22 + script: | + docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }} + docker pull sinkyoungdeok/skku-autocomplete-batch + + docker run --net ubuntu_default sinkyoungdeok/skku-autocomplete-batch + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..172a647 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.8-slim + +COPY requirements.txt requirements.txt +COPY restaurants.csv restaurants.csv +COPY main.py main.py + +RUN pip install -r requirements.txt + +ENTRYPOINT ["python3", "main.py"] \ No newline at end of file diff --git a/main.py b/main.py index ef4ef0a..8630a3c 100644 --- a/main.py +++ b/main.py @@ -111,9 +111,9 @@ def apply_highlighting(org_data, highlighted_data): else: data[gd] = [json_data] -r = redis.Redis(host='localhost', port=6379, db=0) +r = redis.Redis(host='skku-redis', port=6379, db=0) version = '20240403232030' -r.set('restaurant:v1:version', version) +r.setex('restaurant:v1:version', 3600 * 24 * 2, version) for key, value in data.items(): - r.set('restaurant:v1:' + version + ':' + key, json.dumps(value)) + r.setex('restaurant:v1:' + version + ':' + key, 3600 * 24 * 2, json.dumps(value)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..df2003f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +redis +pandas \ No newline at end of file