Upgrade to Pro — share decks privately, control downloads, hide ads and more …

社内パッケージの再利用にSatisを使っている話.pdf

kin29
April 11, 2022

 社内パッケージの再利用にSatisを使っている話.pdf

PHPerKaigi2022

kin29

April 11, 2022
Tweet

More Decks by kin29

Other Decks in Programming

Transcript

  1. 社内パッケージの再利用に
    satisを使っている話

    志賀 彩乃


    View Slide

  2. 自己紹介󰢧

    ● 林(旧:志賀) 彩乃

    ● PHPer 6年

    ● Symfony 3年

    ● カルテットコミュニケーションズ 3年(産休育休1年含む)

    ● 子育て中(1歳半息子)

    Twitter: @kin29ma_n / GitHub: @kin29


    View Slide

  3. 本題に入ります


    View Slide

  4. PHPerのみなさんに質問です󰢛

    プライベートな社内パッケージを再利用したい時、

    どうやってますか?


    View Slide

  5. プライベートな社内パッケージの例

    プライベートな社内パッケージ
    (秘伝のタレ)
    サービスA
    (秘伝のタレを使ったうなぎ )
    サービスB
    (秘伝のタレを使った焼き鳥 )

    View Slide

  6. (packagistに未登録)
    quartetcom/repository
    composer requireできない
    packagistに登録していないリポジトリは再利用することはできない

    packagist
    symfony/symfony

    $ composer require symfony/symfony
    $ composer require quartetcom/repository

    View Slide

  7. しかし


    View Slide

  8. quartetcom/repository
    を使いたい人
    composer requireできる
    + "repositories": {
    + "quartetcom/repository": {
    + "type": "vcs",
    + "url": "https://github.com/quartetcom/repository.git"
    + }
    + }
    composer.json
    composer.jsonのrepositoriesに追加すればcomposer requireできる!


    $ composer require quartetcom/repository
    quartetcom/repository
    (packagistに未登録)

    View Slide

  9. ただし、以下のデメリットがある🥺

    ● 再利用したいリポジトリが複数ある場合、

    そのリポジトリの数だけcomposer.jsonに追記する必要がある。


    View Slide

  10. quartetcom/repo1~3
    を使いたい人
    "repositories": {
    "quartetcom/repo1": {
    "type": "vcs",
    "url": "https://github.com/quartetcom/repo1.git"
    }
    }
    composer.json
    quartetcom/repo1
    (packagistに未登録)
    $ composer require

    View Slide

  11. quartetcom/repo1~3
    を使いたい人
    "repositories": {
    "quartetcom/repo1": {
    "type": "vcs",
    "url": "https://github.com/quartetcom/repo1.git"
    },
    + "quartetcom/repo2": {
    + "type": "vcs",
    + "url": "https://github.com/quartetcom/repo2.git"
    + },
    }
    composer.json
    quartetcom/repo1
    (packagistに未登録)
    quartetcom/repo2
    $ composer require
    $ composer require

    View Slide

  12. quartetcom/repo1~3
    を使いたい人
    "repositories": {
    "quartetcom/repo1": {
    "type": "vcs",
    "url": "https://github.com/quartetcom/repo1.git"
    },
    + "quartetcom/repo2": {
    + "type": "vcs",
    + "url": "https://github.com/quartetcom/repo2.git"
    + },
    + "quartetcom/repo3": {
    + "type": "vcs",
    + "url": "https://github.com/quartetcom/repo3.git"
    + }
    }
    composer.json
    quartetcom/repo1
    (packagistに未登録)
    quartetcom/repo2
    quartetcom/repo3
    $ composer require

    View Slide

  13. quartetcom/repo1~3
    を使いたい人
    quartetcom/repo1
    (packagistに未登録)
    quartetcom/repo2
    quartetcom/repo3
    $ composer require
    "repositories": {
    "quartetcom/repo1": {
    "type": "vcs",
    "url": "https://github.com/quartetcom/repo1.git"
    },
    + "quartetcom/repo2": {
    + "type": "vcs",
    + "url": "https://github.com/quartetcom/repo2.git"
    + },
    + "quartetcom/repo3": {
    + "type": "vcs",
    + "url": "https://github.com/quartetcom/repo3.git"
    + }
    }
    composer.json
    めんどう😓

    View Slide

  14. その問題、Satisで解決できるかも


    View Slide

  15. {
    "name": "quartetcom.composer",
    "homepage": "https://quartetcom/composer",
    "repositories": [
    { "type": "vcs", "url": "https://github.com/quartetcom/repo1" },
    { "type": "vcs", "url": "https://github.com/quartetcom/repo2" },
    { "type": "vcs", "url": "https://github.com/quartetcom/repo3" }
    ],
    "require-all": true
    }
    satis.json
    quartetcom/repo1~3
    を使いたい人
    再利用したいリポジトリ
    quartetcom/repo1
    quartetcom/repo2
    quartetcom/repo3 $ composer require
    + "repositories": {
    + "quartetcom": {
    + "type": "composer",
    + "url":
    "https://quartetcom/composer"
    + }
    + },
    composer.json
    $ vendor/bin/satis build satis.json web/
    Scanning packages
    Wrote packages to docs/p2/quartetcom/repo1.json
    Wrote packages to docs/p2/quartetcom/repo1~dev.json

    Writing packages.json
    Pruning include directories
    Writing web view

    View Slide

  16. メリット💡

    ● satis.jsonに再利用対象のリポジトリを追加→buildするだけでok󰢏

    ● 複数パッケージを一括管理しやすい

    ● 一覧画面もいい感じにできる👉

    ● Basic認証で制限も可能

    ● ビルドインwebサーバで無料で簡単にできる

    $ php -S localhost:8888 -t web 

    ● GitHub Pagesでも作れました🎉 

    https://kin29.github.io/composer-repository/


    View Slide

  17. kin29/repo1
    - v0.0.1
    - v0.0.2🆕
    POST
    (おまけ)GitHub Actionsでsatis buildを自動化してみた!

    on:
    release:
    types: [published]
    jobs:
    run: |
    curl --request POST
    'https://api.github.com/repos/kin29/coposer-repository/dispatches' \
    --header 'Authorization: Bearer ${{secrets.MY_TOKEN}}' \
    --header 'Content-Type: application/json' \
    --data-raw '{"event_type": "repository-updated"}'
    kin29/composer-repository
    on:
    repository_dispatch:
    types: [repository-updated]
    jobs:
    - name: satis build
    run: |
    composer config --global github-oauth.github.com ${{secrets.MY_TOKEN}}
    vendor/bin/satis build satis.json docs
    - name: Push build files
    run: |
    git remote set-url origin
    https://github-actions:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPO}
    git config --global user.name "${GITHUB_ACTOR}"
    git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
    if (git diff --shortstat | grep '[0-9]'); then \
    git add .; \
    git commit -m "👕 Fixed satis build files by github-actions"; \
    git push origin HEAD:${GITHUB_REF}; \
    fi

    View Slide

  18. private packagistというサービスもあります󰡇

    ● https://packagist.com/

    ● 無料トライアルあり(その後は課金制)


    View Slide

  19. ところで


    View Slide

  20. 実はComposer、

    Symfonyコミュニティから生まれました!


    View Slide

  21. カルテットはSymfonyで開発をしています!

    エンジニア・デザイナー大募集中です。

    私のようにフルリモートで働くことができたり、

    子育て中でも働きやすい環境です^^


    ご興味がある方はこちらからどうぞ👇

    https://quartetcom.co.jp/recruit/engineer/


    View Slide

  22. ご清聴ありがとうございました󰢛

    参考:
    https://getcomposer.org/doc/articles/handling-private-packages.md

    https://github.com/composer/satis


    View Slide