Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signal handler #3

Merged
merged 1 commit into from
May 20, 2024
Merged
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
42 changes: 13 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
# 3.5.1 Pythonで開発するREST-APIサーバー
## イメージのビルドと実行

## イメージのビルド
docker build -t ex1:1.3 .
docker run --name ex1 --publish 9103:9100 --detach ex1:1.3

~~~
$ ls
Dockerfile README.md app.py

$ docker build -t ex1:1.0 .
~~~

## イメージの実行


~~~
docker run --name ex1 --publish 9100:9100 --detach ex1:1.0
~~~

## アクセス

~~~
curl http://localhost:9100/ping;echo
~~~
curl http://localhost:9102/ping;echo


## コンテナへ入る

~~~
docker exec -it ex1 bash
~~~


## イメージをレジストリへ登録

~~~
export CR_PAT=YOUR_TOKEN
export USERNAME=YOUR USERID
export USERNAME=YOUR USERID
echo $CR_PAT | docker login ghcr.io -u $USERNAME --password-stdin
docker tag ex1:1.0 ghcr.io/takara9/ex1:1.0
docker push ghcr.io/takara9/ex1:1.0
~~~
docker tag ex1:1.1 ghcr.io/takara9/ex1:1.1
docker push ghcr.io/takara9/ex1:1.1


## クリーンナップ

~~~
docker stop ex1
docker rm ex1
docker rmi ghcr.io/takara9/ex1:1.0
docker rmi ex1:1.0
~~~
docker rmi ghcr.io/takara9/ex1:1.1
docker rmi ex1:1.1



16 changes: 14 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import signal
import sys
from flask import Flask

app = Flask(__name__)
# シグナルを受けた時の処理
def handler(signum, frame):
# ここにアプリケーションの終了処理を書く
#
# コンテナ終了
sys.exit()

# シグナルSIGTERMを受けた時の処理先関数を定義
signal.signal(signal.SIGTERM, handler)

# Webサービス
app = Flask(__name__)
@app.route("/ping")
def hello_world():
def webservice1():
return "PONG!"