8
0

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 1 year has passed since last update.

CI/CDの基礎を学習してみよう

Last updated at Posted at 2022-12-21

はじめに

最近見たいいツイート

こういうドキュメント化のルール等明確に定めておくと、「めんどくさいからいいやぁ」って後回しにすることがなくなりそうですね。
チーム単位でこういった方針を持っておくことはとても大切だと思います。

さて、本題です。
アプリケーションの品質担保や開発スピードの向上をさせるためのCI/CDについて基礎知識を学習していこうと思います。

CIとは?CDとは?

CIとは、継続的インテグレーション(Continuous Integration)を意味し、CDは、継続的デリバリー(Continuous Delivery)を指します。
このCICD一連の流れは「パイプライン」と呼ばれることもあります。

ci-cd-flow-desktop.png
引用:RedHat公式サイト

もう少し身近なサービスで見てみましょう。
基本的に開発現場ではCI/CDはGithubのActionに紐づいて実行されることが多いです。

CIの例

  • git push

    • github hooksでpre-push時に静的解析・自動テスト等を行う
  • push, merge, pull requestされたタイミング

    • 特定ブランチにpushされたら静的解析・テストを実行するworkflowを設定する(Github Actions)

CDの例

※ 区分が難しいですが、シェルスクリプトを実行するというのも一応手段としてあります。

サンプル

Github pre-push

pre-pushというファイル名の

pre-push
#!/bin/bash
export PATH=/usr/local/bin:$PATH

set -x
set -e
set -o pipefail

echo 'Push前処理の実行'
yarn install
yarn cache clean
yarn test

Github Action

Github ActionsでSSH接続し、Laravelをデプロイする例

deplot_to_ec2.yml
name: EC2 Auto Deploy

on:
  push:
    branches:
      - develop

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Git Checkout
      uses: actions/checkout@v3

    - name: Deploy Laravel to EC2
      uses: appleboy/ssh-action@master
      with: 
        host: ${{ secrets.EC2_API_HOST_NAME }}
        username: ${{ secrets.EC2_API_USER_NAME }}
        key: ${{ secrets.EC2_PRIVATE_KEY }}
        timeout: 180s
        script: |
          cd /apps
          git fetch --prune
          git checkout develop
          git pull origin develop
          php artisan optimize
          php artisan config:clear
          php artisan cache:clear
8
0
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
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?