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
46 changes: 46 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
workflow_call:
inputs:
image_name:
required: true
type: string
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get sources
uses: actions/checkout@v4
- name: Container meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ inputs.image_name }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
26 changes: 26 additions & 0 deletions .github/workflows/deploy-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
branches:
- master

jobs:
build:
uses: ./.github/workflows/build-image.yml
with:
image_name: zinstack625/iscraweb-ttbot

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. here could be something like

      image_name: ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.CONTAINER_NAME }}

secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to bleeding edge
uses: grebois/kube-tools@v1.5.2
env:
KUBECONFIG_FILE: ${{ secrets.KUBECONFIG }}
with:
kubectl: 1.18.2
command: |
echo -n "$KUBECONFIG_FILE" > .kubeconfig
export KUBECONFIG=$(pwd)/.kubeconfig
kubectl rollout restart -n iscrawebtt deployment ttbot-bleed

@Fe-Ti Fe-Ti Sep 22, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for line 26:

kubectl rollout restart -n $NAMESPACE $RESOURCE_TYPE $RESOURCE

25 changes: 25 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
workflow_dispatch

jobs:
build:
uses: ./.github/workflows/build-image.yml
with:
image_name: zinstack625/iscraweb-ttbot
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to stable
uses: grebois/kube-tools@v1.5.2
env:
KUBECONFIG_FILE: ${{ secrets.KUBECONFIG }}
with:
kubectl: 1.18.2
command: |
echo -n "$KUBECONFIG_FILE" > .kubeconfig
export KUBECONFIG=$(pwd)/.kubeconfig
kubectl rollout restart -n iscrawebtt deployment ttbot
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ FROM python:3-alpine

WORKDIR /usr/src/app

COPY requirements.txt ./
COPY ./bot ./
COPY config.json ./
RUN apk add envsubst

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY ./bot ./
COPY iscrawebttbot_run.sh /usr/local/bin/

ENTRYPOINT [ "/usr/local/bin/iscrawebttbot_run.sh" ]
12 changes: 12 additions & 0 deletions config.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"refresh_period" : $REFRESH_PERIOD,
"sleep_timeout" : $SLEEP_TIMEOUT,
"notify_period" : $NOTIFY_PERIOD,

@Fe-Ti Fe-Ti Sep 28, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line (4) should be removed if we're going to rely on cron (I suppose it's better).

Or it should look like this (if we rely on internal implementation):

    "notify_schedule"       : ["09:00", "21:00"],

"use_https" : $HTTPS,
"redmine_root_url" : "$REDMINE_URL",
"user_db_path" : "./udb/localbase.json",
"scenery_path" : "./scenery.json",
"allowed_api_functions" : [],
"address" : "0.0.0.0",
"port" : 43210
}
12 changes: 12 additions & 0 deletions docker_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

[ -z "$CONTAINER_NAME" ] && CONTAINER_NAME=docker.io/Fe-Ti/iscraweb-ttbot:latest

@Fe-Ti Fe-Ti Sep 22, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to stop execution with error instead of hardcoding a link*:

die() {
    echo "$1"; exit 1
}
[ -z "$CONTAINER_NAME" ] && die 'CONTAINER_NAME is not set! Set envvar $CONTAINER_NAME'

  • Fun note: I've tried to create account with dash, but docker hub said that it's prohibited :-)


runner_args=(run --rm -v $(git rev-parse --show-toplevel)/config.json.tmpl:/config.json.tmpl -e REDMINE_URL=$REDMINE_URL -e CFG=/config.json.tmpl -e K=$K -e T=$T "$CONTAINER_NAME")

case "$CONTAINER_RUNTIME" in
podman)
podman ${runner_args[@]};;
*)
docker ${runner_args[@]};;
esac
21 changes: 18 additions & 3 deletions iscrawebttbot_run.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
#!/usr/bin/env sh
# Define cleanup procedure
cleanup() {
/usr/bin/env python ./bot_control.py -c $CFG shutdown
/usr/bin/env python ./bot_control.py -c $CFG exit
/usr/bin/env python ./bot_control.py -c ./config.json shutdown
/usr/bin/env python ./bot_control.py -c ./config.json exit
ls -la
}

die() {
echo "$1"; exit 1
}

# Trap SIGTERM
trap 'cleanup' SIGTERM

/usr/bin/env python ./bot.py -k $K -t $T -c $CFG -s
[ -z "$REFRESH_PERIOD" ] && export REFRESH_PERIOD=1000
[ -z "$SLEEP_TIMEOUT" ] && export SLEEP_TIMEOUT=10
[ -z "$NOTIFY_PERIOD" ] && export NOTIFY_PERIOD=43200
[ -z "$HTTPS" ] && export HTTPS="true"
[ -z "$REDMINE_URL" ] && die 'Redmine root URL unset! Set envvar $REDMINE_URL'
[ -z "$K" ] && die 'Telegram token unset! Set envvar $K'
[ -z "$T" ] && die 'Redmine user key unset! Set envvar $T'

envsubst < "$CFG" > ./config.json
cat ./config.json

/usr/bin/env python ./bot.py -k "$T" -t "$K" -c ./config.json -s

# Wait
wait $!
Expand Down