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

レンサバでねっとりとしたプアマンズ継続的デプロイ

uzulla
November 09, 2019

 レンサバでねっとりとしたプアマンズ継続的デプロイ

uzulla

November 09, 2019
Tweet

More Decks by uzulla

Other Decks in Technology

Transcript

  1. ͱ͜ΖͰgitͱ͸ʁ w ϓϩδΣΫτ ΍αΠτ ౳ͷ୯ҐͰ w ϑΝΠϧͷߋ৽ཤྺΛอଘͰ͖ w ͦͷཤྺͷࠩ෼Λݫ֨ʹ؅ཧͰ͖ w

    (JU)VC౳Λ࢖͑͹ߋ৽ΛνʔϜʹڞ༗Ͱ͖Δ w ͱ͍͏ײ͡ͷπʔϧ w ଟ͘ͷ$%Ͱ͸HJUΛ׆༻͠ɺαΠτʹ൓ө͢Δ
  2. ͔͠͠… w 1)1͕ಈ͔ͳ͍ ! ʢ(JU)VCQBHFTɺ/FUMJGZͷ৔߹ʣ w ૉੑ͕-JOVYͰͳ͍ " ʢ"[VSFͷ͍҆ϓϥϯͷ৔߹ʣ w

    ػೳ͸จ۟ແ͍͕ߴ͍ # ʢओ؍ʣʢ)FSPLVɺϚωΫϥͷ ৔߹ʣ w ̍υϝΠϯͳΒແྉͷࣄ΋ଟ͍ w ̍ͭͰ͸ෆศɺԶ͸ؾܰʹ৭ʑͳ΋ͷΛ࡞Γ͍ͨʂ w ʢʜͰ͖Ε͹҆͘ʂʣ
  3. ྫ Domain : http://lop.8oji.tokyo/ DocmentRoot : {ॳظυϝΠϯDir}/lop.8oji.tokyo/public w ެ։σΟϨΫτϦʢ%PD3PPUʣʹ͸ w

    ϓϩδΣΫτ໊ʢ΍ϑϧͳυϝΠϯ໊ʣΛ͚ͭ w ΋͏ҰஈԼ͛Δ public΍webroot΍htdocsʣ͜ͱΛ w ڧ͘ਪ঑͢Δ ͜ͷ͋ͨΓ͸ޙड़
  4. Ωʔੜ੒(࢖͍·Θ͠ෆՄ) $ ssh-keygen -t rsa -b 4096 \ -C "lop.8oji.tokyo"

    -f ~/.ssh/lop.8oji.tokyo.key w ϨϯαόʹTTIͯ͠΍Δͱָ w ੜ੒͞Εͨެ։伴lop.8oji.tokyo.key.pubΛ(JU)VC ͷEFQMPZLFZʹొ࿥ w "MMPXXSJUFBDDFTT͸ෆཁ
  5. ॳճσϓϩΠ # (ʙ/lop.8oji.tokyo/public౳Ͱ͸ͳ͍ʣ $ cd ~/web/ # طଘϑΝΠϧ͕͋Ε͹ফ͢ $ rm

    -ir ~/web/lop.8oji.tokyo # cloneɺlop.8oji.tokyo͕࡞੒͞ΕΔ $ git clone [email protected]:uzulla/lop.8oji.tokyo.git w ޙड़ͷʮయܕతͳηΩϡϦςΟϦεΫʯΛΑΜͰͶ w ϩϦϙͰ͸ɺBHFOUసૹΛ͢Δ͔ɺޙड़ͷ.git/config मਖ਼
  6. CronͰpull͢Δ(͑ͬ) */30 * * * * git -c core.sshCommand="ssh -i

    ~/.ssh/deploy.key" \ -C ~/web/lop.8oji.tokyo/ >> ~/lop.8oji.tokyo.pull.log 2>&1 w ҙ༁ɿ෼ʹҰ౓ɺDSPOͰHJUIVC͔ΒϑΝΠϧΛ%-ͯ͠ ͍Δ w ॳΊͯݟͨࢲͷײ૝ʮʜΊͪΌΊͪΌݡ͍ͳ͜Εʯ w ౜ಥͰ͕͢ɺ্͸ϩϦϙͰ͸ବ໨
  7. # ϩϦϙͰ͸… `~/.ssh/config` Λमਖ਼ Host lop.8oji.tokyo.github.com # ద౰ͳΤΠϦΞεతͳ Hostname github.com

    User git IdentityFile ~/.ssh/lop.8oji.tokyo.key ˞ͦͯ͠ɺHJU࣌͸ҎԼͷΑ͏ʹϗετ໊ΛDPOpHʹࢦఆ͠ ͨ΋ͷʹஔ͖׵͑Δ git clone [email protected]:uzulla/lop.8oji.tokyo.git
  8. ͦͯ͜͠͏ # cron */30 * * * * git --git-dir=${HOME}/web/lop.8oji.tokyo/.git

    \ --work-tree=${HOME}/web/lop.8oji.tokyo/ \ >> ${HOME}/lop.8oji.tokyo.pull.log 2>&1 伴͸ɺ.ssh/config಺Ͱࢦఆͱ͍͏͜ͱʹͳΔ
  9. ༨ஊ $ git -C ~/web/lop.8oji.tokyo/ Unknown option: -C ## ??

    $ git --version git version 1.8.3.1 ## ?????? `-c core.sshCommand`΋͔ͭ͑ͳ͍… $ git --git-dir=<snip> --work-tree=~/web/lop.8oji.tokyo status fatal: Could not switch to '~/web/': ?????????????????????? ## ??????????????????????
  10. CIͱ͸ʁ w ܧଓతΠϯςάͳΜͱ͔ɺΠϚυΩ͸Ͱ͖ͳ͍ͱͩΊΒ͠ ͍ w (JUIVCʹQVTI ౳ ͢ΔͱΫϥ΢υͰ޷͖ͳॲཧ͕Ͱ͖Δ w ྫɿunit

    testɺcomposerɺdeployer w ʢ͕Μ͹Ε͹େମͳΜͰ΋Ͱ͖Δʣ w ʢͭ·Γɺ$%΋౰વͰ͖Δʣ w ࣮ࡍͷॴɺ'51ͰΞοϓϩʔυͩͬͯͰ͖Δ͆
  11. # Github actions ઃఆ(workflow)ྫ name: sample action on: [push] #

    Push͞Εͨͱ͖ʹ jobs: build: runs-on: ubuntu-latest steps: - name: kick git pull.php # ͳΜ͔͢Δ run: curl https://my-server.example.jp/git_pull.php
  12. pull_for_lolipop.bash #!/usr/bin/env bash SCRIPT_DIR=$(cd $(dirname $0); pwd) git \ --git-dir=${SCRIPT_DIR}/.git

    \ --work-tree=${SCRIPT_DIR} \ pull # ͜Ε͸ʮϩϦϙ༻ʯɺଞͳΒ·ͨॻ͖ํ΋͋Δ
  13. # ଓ͖ steps: - uses: actions/checkout@v1 - name: pull from

    deloy target uses: fifsky/ssh-action@master with: command: ~/web/lop.8oji.tokyo/pull_for_lolipop.bash port: ${{ secrets.SSH_PORT }} host: ${{ secrets.SSH_HOST }} user: ${{ secrets.SSH_USER }} key: ${{ secrets.PRIVATE_KEY}}
  14. ผͷߴ౓ͳ༨ஊʢ஫ҙ఺ʣ w ssh-agent͕͏͍͍ͯ͝Δͱɺ-iࢦఆͯ͠΋͕ͦͬͪ༏ ઌ͞ΕͯγΣϧ্͕͕Δ͜ͱ͕͋Δʢςετ࣌ʹϋϚΔʣ w unset SSH_AUTH_SOCK w DPNNBOE͸ʮϩάΠϯγΣϧ্Ͱ࣮ߦ͞ΕΔʯΑʂ w

    ྫ͑͹chsh͢Δͷ͕͜Θͯ͘.***rcͱ͔Ͱbashͱ͔ ΍ͬͯγΣϧ੾Γସ͑ͯ͠ΔͱɺγΣϧʹ΋ͲͬͪΌ͏ ͷͰ஫ҙɻ ͪΌΜͱ੍ݶ͞Ε͍ͯΔ͜ͱ͸֬ೝ͠·͠ΐ͏ʂ