imshota / system_development_project_application_1

講義用
0 stars 0 forks source link

デプロイと冪等性 #9

Open imshota opened 3 years ago

imshota commented 3 years ago

演習1 授業で作ったリポジトリの中に適当なブランチを作り、GitHub Pagesとして公開してみよ

作業記録 作業リポジトリ

ローカルリポジトリでghp-deployブランチを作成し、foo.txtファイルをを作り、リモートリポジトリにプッシュ

% git branch ghp-deploy
% cat foo.txt
pages test
% git push --set-upstream origin ghp-deploy

リポジトリのSettings > Optionで Sourceの部分のBranchに、ghp-deployブランチを設定

GitHub Pageseとして公開された https://imshota.github.io/class_pro/foo.txt

imshota commented 3 years ago

演習2 授業で作ったリポジトリのCircleCIでGitHub Pagesへデプロイせよ

作業記録 演習1と同じリポジトリで行っている。

CircleCI→GitHubのSSH用鍵の設定が必要 今回はスライド通りに作るが他にも環境によって方法がある。 参考ページ https://circleci.com/docs/ja/2.0/add-ssh-key/

  1. 鍵ペアの生成(Public Key と Private Key)
    % ssh-keygen -m PEM -t rsa -C "imshotaseo@icloud.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/shota/.ssh/id_rsa): .id_rsa
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in .id_rsa.
    Your public key has been saved in .id_rsa.pub.
    The key fingerprint is:
    SHA256:9cwRRzGX/YX8S/oT+B5Iol7iYM9ZT1GYPnsUCmmxlls imshotaseo@icloud.com

オプション -m PEM ・・・PEM形式で保存 -t rsa ・・・RSAアルゴリズム(他にもdsa,ecdsa,ed25519,rsa1がある) -C "comment" ・・・ 鍵につけるコメント

  1. 鍵ペアを登録(CircleCIにPrivateを、GitHubにPublicを登録)

あとは、config.ymlにfingerprintsを設定し、好きな処理を書く。

今回は ターゲットブランチ(ghp-deploy)において、deploy.shで func.cをコンパイルしたdeploy_test.outを実行し、その結果をdeploy_test.txtに書き込む処理を設定した。

しかしエラー・・・

Branch 'ghp-deploy' set up to track remote branch 'ghp-deploy' from 'origin'.
Switched to a new branch 'ghp-deploy'
HEAD is now at 2f37244 Update deploy.sh
[ghp-deploy 3c83bac] [skip ci] updates GitGub Pages
 2 files changed, 1 insertion(+)
 create mode 100755 deploy_test.out
 create mode 100644 deploy_test.txt
class@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Exited with code exit status 128

public keyが悪いと言われているっぽいので、GitHubのdeploy keyの設定を見てみると、なぜか新しい鍵が作られて、そっちが使われていることが判明

とりあえず、作られた新しい鍵を消す。 CircleCIの方も新しい鍵が作られていたので消す。 そして、urlが間違っていることにも気づき、直す。

Branch 'ghp-deploy' set up to track remote branch 'ghp-deploy' from 'origin'.
Switched to a new branch 'ghp-deploy'
HEAD is now at 067778a Update deploy.sh
[ghp-deploy 8620b3f] [skip ci] updates GitGub Pages
 2 files changed, 1 insertion(+)
 create mode 100755 deploy_test.out
 create mode 100644 deploy_test.txt
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 36 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 2.89 KiB | 2.89 MiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.        
To ssh://github.com/imshota/class_pro.git
 + aa6fc1d...8620b3f ghp-deploy -> ghp-deploy (forced update)

できた! https://github.com/imshota/class_pro/blob/ghp-deploy/deploy_test.txt https://imshota.github.io/class_pro/deploy_test.txt

imshota commented 3 years ago

演習3 冪等でない操作をいくつか挙げ、それが冪等にならない場合を説明せよ

作業記録 ・fooファイルに"hello"を追加 を試してみる

% echo hello >> foo
% cat foo
hello
% echo hello >> foo
% echo hello >> foo
% echo hello >> foo
% cat foo          
hello
hello
hello
hello

コマンドを繰り返すと、中身が変わっていることがわかる。

・gitでブランチfunc1に移動 を試してみる

% git checkout func1
error: pathspec 'func1' did not match any file(s) known to git
% git branch func1
% git checkout func1
Switched to branch 'func1'

ブランチfunc1の有無で状態が変わることがわかる。

・シェル変数RANDOMを表示 を試してみる

% echo $RANDOM
953
% echo $RANDOM
6975
% echo $RANDOM
765
% echo $RANDOM
26373

実行する度に、違う値が表示されるのがわかる 参考サイトによると、 シェル変数RANDOMには0から32767までの整数が格納されているらしい