Skip to content

Commit

Permalink
containersへのデプロイの準備をした (#18)
Browse files Browse the repository at this point in the history
* †追加† 設定ファイルを環境変数のコンテンツから見るようになった

* †追加† 多分Docker imagesにpushできるようになった

* †追加† Dockerで動くようになった

* †編集† Alpineイメージじゃなくてpython:3.8.5-busterイメージにお世話になるようにした

* †修正† dockerignoreファイルのファイル末改行を修正した

(suggestionより)

Co-authored-by: Naoki Ikeguchi <[email protected]>

Co-authored-by: Naoki Ikeguchi <[email protected]>
  • Loading branch information
loxygenK and siketyan committed Aug 13, 2020
1 parent 4f20bc4 commit 3bf3aa0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
venv/
.git
.github
.gitignore
.idea
36 changes: 36 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

env:
IMAGE_NAME: delitter

jobs:
push:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build an image with a tag
run: docker build -t app .

- name: Log into the registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin

- name: Push the image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "master" ] && VERSION=latest
docker tag app $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.8.5-buster
RUN mkdir /src
COPY . /src
WORKDIR /src
RUN python3 -m pip install -r requirements.txt

ENTRYPOINT ["python3", "main.py"]
6 changes: 3 additions & 3 deletions lib/settings/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def __init__(
self.approve_rate = approve_rate


def create(file: TextIO) -> DiscordSetting:
def create(json_text: str) -> DiscordSetting:
"""
Jsonファイルから設定をパースしてDiscordSettingを生成する
:param file: Jsonファイルを参照しているIO
:param json_text: Jsonで記述された設定
:return: 生成されたDiscordSetting
"""
json_type = Dict[str, Union[None, str, int]]
Expand All @@ -60,7 +60,7 @@ def create(file: TextIO) -> DiscordSetting:
with open("static/scheme/discord_scheme.json") as f:
scheme_json: json_type = json.load(f)

raw_json: json_type = json.load(file)
raw_json: json_type = json.loads(json_text)
validate(raw_json, scheme_json)

raw_json.setdefault("token", None)
Expand Down
6 changes: 3 additions & 3 deletions lib/settings/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(
self.access_secret_token = access_token_secret


def create(file: TextIO) -> TwitterSetting:
def create(json_text: str) -> TwitterSetting:
"""
Jsonファイルから設定をパースしてTwitterSettingを生成する
:param file: Jsonファイルを参照しているIO
:param json_text: Jsonで記述された設定
:return: 生成されたTwitterSetting
"""
json_type = Dict[str, Union[None, str, int]]
Expand All @@ -48,7 +48,7 @@ def create(file: TextIO) -> TwitterSetting:
with open("static/scheme/twitter_scheme.json") as f:
scheme_json: json_type = json.load(f)

raw_json: json_type = json.load(file)
raw_json: json_type = json.loads(json_text)
validate(raw_json, scheme_json)

raw_json.setdefault("token", None)
Expand Down
18 changes: 14 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
------------------------
プログラムのエントリポイント。
"""
import base64
import os

from lib.data.tweet_votes_record import TweetsVoteRecord
from lib.discord.client import MainClient
from lib.discord.op.command.command_register import CommandRegister
Expand All @@ -15,11 +18,18 @@
from lib.twitter.tweeter import Tweeter

if __name__ == '__main__':
with open("settings/discord.json") as f:
discord_setting: discord.DiscordSetting = discord.create(f)

with open("settings/twitter-api.json") as f:
twitter_setting: twitter.TwitterSetting = twitter.create(f)
if "DELITTER_DISCORD_SETTING_JSON_B64" not in os.environ:
raise RuntimeError("DELITTER_DISCORD_SETTING_JSON_B64 is not set!")

if "DELITTER_TWITTER_SETTING_JSON_B64" not in os.environ:
raise RuntimeError("DELITTER_TWITTER_SETTING_JSON_B64 is not set!")

raw_discord_setting = base64.b64decode(os.environ["DELITTER_DISCORD_SETTING_JSON_B64"]).decode("utf-8")
raw_twitter_setting = base64.b64decode(os.environ["DELITTER_TWITTER_SETTING_JSON_B64"]).decode("utf-8")

discord_setting: discord.DiscordSetting = discord.create(raw_discord_setting)
twitter_setting: twitter.TwitterSetting = twitter.create(raw_twitter_setting)

votes_record = TweetsVoteRecord()
command_register = CommandRegister(discord_setting)
Expand Down

0 comments on commit 3bf3aa0

Please sign in to comment.