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 Hostinfo API #5

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
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
## イメージのビルドと実行

```
docker build -t ex1:1.3 .
docker run --name ex1 --publish 9103:9100 --detach ex1:1.3
docker build -t ex1:1.4 .
docker run --name ex1 --publish 9100:9100 --detach ex1:1.4
```

## アクセス

```
curl http://localhost:9103/ping;echo
curl http://localhost:9100/ping;echo
```

## コンテナへ入る
Expand All @@ -25,15 +25,52 @@ docker exec -it ex1 bash
export CR_PAT=YOUR_TOKEN
export USERNAME=YOUR USERID
echo $CR_PAT | docker login ghcr.io -u $USERNAME --password-stdin
docker tag ex1:1.3 ghcr.io/takara9/ex1:1.3
docker push ghcr.io/takara9/ex1:1.3
docker tag ex1:1.4 ghcr.io/takara9/ex1:1.4
docker push ghcr.io/takara9/ex1:1.4
```

## クリーンナップ

```
docker stop ex1
docker rm ex1
docker rmi ghcr.io/takara9/ex1:1.3
docker rmi ex1:1.3
docker rmi ghcr.io/takara9/ex1:1.4
docker rmi ex1:1.4
```


## コードの更新方法

```
$ git clone [email protected]:takara9/ex1.git
$ git checkout -b add_api
$ git branch

# <コードの更新や追加>

$ git add .
$ git status
$ git commit -m "Add new api"
```
CIが成功したら、add_apiブランチをmainブランチへマージする


## GitHubでのリリース方法
メインブランチへ移動してコードを最新化する。そして、ブランチを削除

```
$ git checkout main
$ git pull
$ git branch -d update_branch
'''

リリースするTAGを設定する。
ここで付与するTAGはコンテナイメージのタグになるので、リポジトリを確認して、タグ名を決めること。

```
TAG=1.1
$ git tag -a $TAG -m "version $TAG"
$ git push origin $TAG
```

コンテナのイメージを、タグを選定してリリースする。
17 changes: 15 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import signal
import sys
import time
from flask import Flask
from flask import Flask, request
from socket import gethostname, gethostbyname

# ログ保存
def logger(msg):
Expand All @@ -24,6 +25,18 @@ def handler(signum, frame):
# Webサービス
app = Flask(__name__)
logger("Start Web service\n")

# ping応答
@app.route("/ping")
def webservice1():
def ws_ping():
return "PONG!"

# ホスト情報
@app.route("/info")
def ws_info():
hostname = gethostname()
resp = ""
resp = resp + 'Host Name: %s' % hostname + "\n"
resp = resp + 'Host IP: %s' % gethostbyname(hostname) + "\n"
resp = resp + 'Client IP : %s' % request.remote_addr + "\n"
return resp