👇前回の記事はこちら
Gitを使ってローカルリポのユーザー設定とリモートリポの登録
👇まずは、Gitのホームページ()へ行き、リモートリポを作成する。Gitの登録ができていない人は、
光の速さで登録しよう☆



👇次にローカルリポの登録、先ほど作成したリモートリポに登録をし,コードをpushする
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[~/Desktop/product-register] $ ls -a . .ruby-version README.md config lib storage .. Dockerfile Rakefile config.ru log test .git Gemfile app db package.json tmp .gitignore Gemfile.lock bin docker-compose.yml public vendor =========ローカルリポへユーザー登録=========== [~/Desktop/product-register] $ git config user.name "<username>" [~/Desktop/product-register] $ git config user.email "<email>" [~/Desktop/product-register] $ git config user.name <username> [~/Desktop/product-register] $ git config user.email <email> ============リモートリポに登録============== [~/Desktop/product-register] $ git remote add origin <repo_url> [~/Desktop/product-register] $ git remote -v origin <repo_url> (fetch) origin <repo_url> (push) ==========コードをリモートリポジトリにpush=============== [~/Desktop/product-register] $ git add . [~/Desktop/product-register] $ git commit -m 'fitst commit' [~/Desktop/product-register] $ git push origin master |
Travis CIをセットアップ&product-registerをテスト




続いて、.travis.ymlファイルを作成しVScodeで編集していきます。
👇書き方の流れは以下のようになります。
①権限の設定
②Dockerを使うことを宣言
③コンテナを起動する
④DB(データベース)準備&migrate
⑤テスト実行
1 2 |
<Command> [~/desktop/product-register] $ code .travis.yml |
1 2 3 4 5 6 7 8 9 |
<~/Desktop/product-register/.travis.yml> sudo: required services: docker before_install: - docker-compose up --build -d script: - docker-compose exec --env 'RAILS_ENV=test' web rails db:create - docker-compose exec --env 'RAILS_ENV=test' web rails df:migrate - docker-compose exec --env 'RAILS_ENV=test' web rails test |
👇追加になりますが、docker-compose.ymlのdb:に追記が必要です。
これはTravisCIなどlocalhost以外でPostgresを動かす場合に必要な記述になります。
1 2 3 4 5 6 7 8 9 10 11 |
<~/Desktop/product-register/docker-compose.yml> db: image: postgres volumes: - 'db-data:/var/lib/postgresql/data' environment: - 'POSTGRES_USER=postgres' - 'POSTGRES_PASSWORD=postgres' ===============追加した箇所================ - 'POSTGRES_HOST_AUTH_METHOD=trust' ========================================== |
👇これでGitにプッシュしていこう
1 2 3 4 |
<Command> [~/desktop/product-register] $ git add . [~/desktop/product-register] $ git commit -m 'update travis and conpose' [~/desktop/product-register] $ git push origin master |
👇TravisCIのページを見てみましょう

👇下にスクロールし、赤枠のようになっていれば問題なくテスト完了です

ここまでで、開発〜テスト環境の構築(CI)〜テストの実行までできました。
次は本番環境(CD)にHerokuを使ってデプロイするところまでやっていきたいと思います。
今回はこの辺で、ばいばい👋
コメントを残す