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
60 changes: 60 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker

on: [push, pull_request]

env:
IMAGE_NAME: crobot

jobs:
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Docker Login
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
echo "${DOCKER_PASSWORD}" | docker login -u ${DOCKER_USERNAME} --password-stdin

- name: Build image
run: |
IMAGE_ID=${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

docker pull $IMAGE_ID:build || true
docker pull $IMAGE_ID:latest || true
docker build --target build \
--cache-from=$IMAGE_ID:build \
--tag $IMAGE_NAME:build .
docker build --target runtime \
--cache-from=$IMAGE_ID:build \
--cache-from=$IMAGE_ID:latest \
--tag $IMAGE_NAME .

- name: Push image
run: |
IMAGE_ID=${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')

# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME:build $IMAGE_ID:build
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:build
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM python:alpine AS build
LABEL git="https://github.com/Aeriqu/CroBot"
ARG KYTEA_VERSION=0.4.7

WORKDIR /app

RUN apk add --no-cache build-base libffi-dev && \
wget http://www.phontron.com/kytea/download/kytea-${KYTEA_VERSION}.tar.gz && \
tar xf kytea-${KYTEA_VERSION}.tar.gz && \
cd kytea-${KYTEA_VERSION} && ./configure && make && \
mkdir /app/kytea && make install prefix=/app/kytea

RUN pip install virtualenv && python -m virtualenv venv
COPY /requirements.txt requirements.txt
RUN ./venv/bin/pip install \
--global-option=build_ext \
--global-option="-L/app/kytea/lib/" \
--global-option="-I/app/kytea/include/" \
-r requirements.txt


FROM python:alpine AS runtime
RUN apk add --no-cache libstdc++
WORKDIR /app
COPY --from=build /app/venv venv
# we copy kytea/{bin,include,lib,share}
COPY --from=build /app/kytea/ /usr/local/
ENV PATH="/app/venv/bin:$PATH"
RUN ln -s /usr/local/share/kytea/model.bin

COPY . .
RUN ./db_init.py
CMD ./run.py
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ To properly use kytea, a model file is required. You can obtain one from the [ky
source](http://www.phontron.com/kytea/#download).


### Set up
## Set up

### Docker setup

1. Install [Docker](https://docs.docker.com/get-docker/)
2. Set up a settings.ini file using [the one in the repo](https://github.com/Aeriqu/CroBot/blob/master/settings.ini) as a template.
3. Run ``docker run -d -v /path/to/anywhere/sdvxCharts.db:/app/sdvxCharts.db -v /path/to/your/settings.ini:/app/settings.ini aeriqu/crobot``

### Traditional setup

#### General setup

Expand All @@ -34,8 +42,9 @@ source](http://www.phontron.com/kytea/#download).
sdvxin:

1. Obtain a kytea model, name it ``model.bin``, and place it in the same directory as ``run.py``
2. Run ``db_init.py`` to initialize the database and download the metadata from sdvx.in
3. Edit the configuration file for an api key for azure's cognitive translation features
2. Run ``db_init.py`` to initialize the database
3. Execute ``!sdvxin update`` in a channel with the bot to download the metadata from sdvx.in (this will take a while)
4. Edit the configuration file for an api key for azure's cognitive translation features


## License
Expand Down
2 changes: 0 additions & 2 deletions db_init.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env python3
import asyncio
import CroBot.features.sdvxin.sdvx
import CroBot.features.sdvxin.database

async def upd():
await CroBot.features.sdvxin.database.recreate_db()
await CroBot.features.sdvxin.sdvx.update()

def main():
loop = asyncio.new_event_loop()
Expand Down
1 change: 1 addition & 0 deletions run.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import configparser
import discord
from discord.utils import get
Expand Down