3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCIのMachineでdocker-compose使いつつpytest走らせるよ

Posted at

前提

  • Docker Executorとdocker-composeを組み合わせると想定外の動きをする可能性があるので、Machine Executorsを利用する
  • ただし将来的に追加料金がかかる可能性があるらしいのでこちらを要チェック

コメント

  • imageはcircleci/classic系統を使おうとしたが、pyenvのインストール時にOpenSSLのエラー?が出たり、pytestを動かすうえで必要なライブラリが入らなかったので ubuntu-1604:201903-01 を指定しました。

    • ほかに指定できるimageはこちらで一覧になってます
  • CircleCI特有の便利環境変数が結構いろいろ設定されているので(例えばCIや)pytestはそれを考慮して動かすと便利かも!

試行錯誤した結果のconfig.yml

  • !!キャッシュは全く設定していないので必要に応じて設定してください!!
version: 2
jobs:
  build:
    machine:
      image: ubuntu-1604:201903-01
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: Install Docker Compose
          command: |
            curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
            chmod +x ~/docker-compose
            sudo mv ~/docker-compose /usr/local/bin/docker-compose
      - run:
          name: docker-compose up
          command: |
            set -x
            docker-compose up --build -d
      - run:
          name: docker-compose stop
          command: |
            set -x
            docker-compose stop
      - run:
          name: docker-compose up
          command: |
            set -x
            docker-compose up -d
      - run:
          name: wait for rdb
          command: |
            set -x
            chmod 777 wait-for-it.sh
            sudo bash ./wait-for-it.sh -h 127.0.0.1 -p 3306 # ←テストDBが起動するまで待つ
      - run:
          name: library setup
          command: |
            set -x
            sudo apt update
            sudo apt install mysql-common libmysqlclient20 libmysqlclient-dev # ←pytestで内で必要だったので入れました
            sudo apt install python-dev imagemagick-6.q16 # ←pytestで内で必要だったので入れました

      - run:
          name: pyenv setup
          command: |
            set -x
            git clone git://github.com/yyuu/pyenv-update.git /opt/circleci/.pyenv/plugins/pyenv-update  # ←デフォルトだと選べるバージョンが少ないのでupdateする
            pyenv update
            pyenv install 3.8.2
            pyenv global 3.8.2
            which python
            python -V
            pip install --upgrade pip
            pip -V

      - run:
          name: test
          command: |
            set -x
            pip install -e '.[test]' # ←テスト
            mkdir /tmp/test-results
            ENV=test pytest -v --junitxml=/tmp/test-results/pytest-junit.xml
      - store_test_results:
          path: /tmp/test-results

      - run:
          name: docker-compose down
          command: docker-compose down

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?