πŸ”§ DevOps

Workflow

Workflow

An automated work flow. GitHub Actions workflows. Defined in YAML.

Detailed Explanation

A workflow is an automated flow of tasks defined to achieve a specific goal. In DevOps, it mainly refers to CI/CD pipelines, data processing pipelines, and infrastructure automation scenarios. GitHub Actions, Argo Workflows, and Apache Airflow are representative workflow engines.

A workflow consists of triggers, jobs, and steps. A trigger is an event that starts the workflow (push, schedule, webhook), a job is a unit of work that runs independently, and a step is an individual command within a job. You can define dependencies between jobs and conditional execution.

Declarative definition is the key. When you define a workflow in YAML, JSON, or a DSL, the engine manages its execution. State management, retries, parallel execution, and logging are handled automatically, so you do not need to implement complex orchestration logic yourself.

In practice, workflows are used to automate build-test-deploy when code is pushed, to run regular data processing (ETL), and for infrastructure provisioning. Managing workflows as code (Workflow as Code) makes version control, review, and reuse possible.

Code Example

# GitHub Actions CI/CD μ›Œν¬ν”Œλ‘œμš° 예제
# .github/workflows/ci-cd.yml

name: CI/CD Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]
  # μˆ˜λ™ μ‹€ν–‰ κ°€λŠ₯
  workflow_dispatch:
    inputs:
      environment:
        description: '배포 ν™˜κ²½'
        required: true
        default: 'staging'
        type: choice
        options:
          - staging
          - production

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  # 1단계: 린트 및 νƒ€μž… 체크
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run ESLint
        run: npm run lint

      - name: Run TypeScript check
        run: npm run type-check

  # 2단계: ν…ŒμŠ€νŠΈ (λ¦°νŠΈμ™€ 병렬 μ‹€ν–‰)
  test:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_PASSWORD: test
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test -- --coverage
        env:
          DATABASE_URL: postgresql://postgres:test@localhost:5432/test

      - name: Upload coverage
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

  # 3단계: λΉŒλ“œ (린트, ν…ŒμŠ€νŠΈ μ™„λ£Œ ν›„)
  build:
    needs: [lint, test]
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    outputs:
      image-tag: ${{ steps.meta.outputs.tags }}

    steps:
      - uses: actions/checkout@v4

      - name: Log in to Container Registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          tags: |
            type=sha,prefix=
            type=ref,event=branch

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

  # 4단계: 배포 (main 브랜치만)
  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://myapp.example.com

    steps:
      - name: Deploy to Kubernetes
        uses: azure/k8s-deploy@v4
        with:
          action: deploy
          manifests: k8s/
          images: ${{ needs.build.outputs.image-tag }}

      - name: Notify Slack
        uses: slackapi/slack-github-action@v1
        with:
          payload: |
            {
              "text": "Deployed ${{ github.sha }} to production"
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

How It's Said in Practice

Senior: "We're running tests manually for every PR, but if you create a GitHub Actions workflow, it runs automatically on every push."

Junior: "Can we block merging if the tests don't pass?"

Senior: "Yes, if you set required status checks in the Branch Protection Rule, the merge button is enabled only when the workflow succeeds."

Interviewer: "Please describe your experience designing CI/CD pipelines."

Candidate: "I set up a build-test-deploy workflow with GitHub Actions. I ran the lint and test jobs in parallel to shorten the time, and I set up the dependency with needs so that the build job runs only when both succeed. The deploy job runs only on pushes to the main branch, and I used environment approval to require approval before production deployment."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

Reviewer: "You used npm install instead of npm ci in the workflow, but ci is more stable because it is based on the lock file."

Developer: "I'll switch to npm ci and also add the cache option of actions/setup-node to reduce dependency installation time."

Cautions

Learn More