かべぎわブログ

ブログです

CircleCIで順番に実行されるWorkflowをつくる

概要

CircleCIで順番に実行されるworkflowをつくってみます。
ユニットテストの後、デプロイするようなイメージです。

コード等はこれを利用しています。

github.com

.circleci/config.yml

testとdeployのjobをつくって、Workflowの箇所でrequiresを設定してあげています。

version: 2
jobs:
  test:
    docker:
      - image: circleci/python:3.7
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: unittest 
          command: |
            python ./handler.py

  deploy:
    docker:
      - image: circleci/python:3.7.6-stretch-node-browsers
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: Install Serverless CLI and dependencies
          command: |
            sudo npm install -g serverless
            npm install 
      - deploy: 
          name: Deploy
          command: |
            npm install --save serverless-python-requirements
            sls deploy 

workflows:
  version: 2
  test_and_deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test

結果

無事できました。
f:id:kabegiwakun:20200206220749p:plain

おまけ

Pythonでのunittest

import requests
import unittest

def main(event, context):
    response = requests.get('https://www.kabegiwablog.com/')
    return response.status_code

class test(unittest.TestCase):
    def test_main(self):
        self.assertEqual(main('',''),200)

if __name__ == '__main__':
    unittest.main()
    main('', '')

CCNA Collaboration CICD 210-060 Official Cert Guide

CCNA Collaboration CICD 210-060 Official Cert Guide

  • 作者:Michael H. Valentine
  • 出版社/メーカー: Cisco Press
  • 発売日: 2015/10/23
  • メディア: ハードカバー