Hostname support for backup container

オープン
#104 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
docker, docker-compose, python

調査の方向性

src/restic_compose_backup/containers.py の 410 行目付近から始めます。ここでは Docker のメタデータからバックアップコンテナを特定しています。issue に示されているカスタムホスト名で失敗を再現し、その後、デフォルトの ID ベースのセットアップとホスト名ベースのセットアップの両方で、メタデータエラーなしにバックアップコンテナを見つけられることを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug

Hi 👋 ,

currently, stack-back identifies its own container by checking if the container ID starts with the hostname:

if container_data.get("Id").startswith(socket.gethostname()):
    self.this_container = Container(container_data)

This works fine when using Docker's default behavior (hostname = container ID prefix), but fails when a custom hostname is set , for example in docker-compose.yml:

services:
  backup:
    hostname: "${COMPOSE_PROJECT_NAME}-backup"

This results in the error:

ValueError: Cannot find metadata for backup container
Use Case

Setting a custom hostname like ${COMPOSE_PROJECT_NAME}-backup is useful for:

  • Consistent identification across container restarts
  • Better monitoring and metrics (e.g., in Prometheus/Grafana)
  • More readable hostnames in logs and dashboards
Proposed Solution

Extend the container detection logic to support both the original ID-based method and hostname-based detection:

for container_data in all_containers:
    container_id = container_data.get("Id", "")
    container_hostname = container_data.get("Config", {}).get("Hostname", "")
    
    if container_id.startswith(socket.gethostname()) or container_hostname == socket.gethostname():
        self.this_container = Container(container_data)
        break
Benefits
  • Maintains backward compatibility with existing setups
  • Allows users to set custom hostnames for better monitoring
  • No breaking changes to current functionality
主要言語
Python
スター
182
フォーク
16
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lawndoc/stack-back のほかの issue

lawndoc/stack-back の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。