Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GitLab CI/CDとECS Fargateでリリース作業が楽になった話

orfx
April 24, 2019

GitLab CI/CDとECS Fargateでリリース作業が楽になった話

2019/04/24(水)
GitLab Meetup Tokyo #16: 新年度応援
https://gitlab-jp.connpass.com/event/126533/

orfx

April 24, 2019
Tweet

More Decks by orfx

Other Decks in Technology

Transcript

  1. Build Stage build: stage: build script: - docker build -t

    image_name:ci . - docker save image_name:ci -o ${ARTIFACT_PATH} artifacts: paths: - ${ARTIFACT_PATH} expire_in: 1h • docker build ͰϏϧυͨ͠ΠϝʔδΛ docker save ͰϑΝΠϧʹॻ͖ग़͢ɻ • ॻ͖ग़ͨ͠ϑΝΠϧ͸ GitLab ͷ artifacts ػೳͰ δϣϒ׬ྃޙʹ GitLab ΁ࣗಈΞοϓϩʔυͤ͞Δɻ
  2. Test Stage unittest: stage: test script: - docker load -i

    ${ARTIFACT_PATH} - docker-compose up --exit-code-from service_name • artifacts ͰΞοϓϩʔυ͞ΕͨϑΝΠϧ͸࣍ͷδϣϒ։࢝࣌ ʹࣗಈμ΢ϯϩʔυ͞ΕΔͷͰ docker load ͰಡΈࠐΉɻ • ͦͷΠϝʔδΛ༻͍ͯ docker-compose Ͱ UnitTest ʹඞཁ ͳίϯςφҰࣜΛཱͪ͛ͯςετΛ࣮ߦ͢Δɻ
  3. Push Stage push: stage: push script: - docker load -i

    ${ARTIFACT_PATH} - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker tag image_name:ci $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG • ಉ༷ʹࣗಈμ΢ϯϩʔυ͞ΕͨϏϧυΠϝʔδΛಡΈࠐΉɻ • docker login Ͱ GitLab Container Registry ʹϩάΠϯͯ͠ɺ docker push ͰϨδετϦʹΠϝʔδΛΞοϓϩʔυ͢Δɻ
  4. Deploy Stage deploy: stage: deploy variables: RELEASE_TAG: $CI_COMMIT_REF_SLUG script: -

    ecs-cli compose -p ${SERVICE_NAME} -f ${CLUSTER_NAME} service up தུ environment: name: ${ENVIRONMENT} when: manual • ECS CLI Ͱ docker-compose ϑΝΠϧΛ࢖༻ͯ͠αʔϏεΞοϓ ͢Δɻ͜Ε͚ͩͰ ECS ͕͍͍ײ͡ʹσϓϩΠͯ͘͠ΕΔ (ࡶ) • σϓϩΠδϣϒ͸ when: manual Λࢦఆͯࣗ͠ಈ࣮ߦ͞Εͳ͍Α ͏ʹ͢Δɻ -> ͜Ε͕ઌ΄Ͳͷԡ͚ͩ͢ͷϘλϯ
  5. Artifacts ػೳ • Runner ͕ෳ਺͋Δ؀ڥͰɺύΠϓϥΠϯதʹผͷ Runner Ͱॲཧ͕࣮ߦ͞Εͯ͠·ͬͯ΋ɺδϣϒ࣮ߦʹඞ ཁͳϑΝΠϧΛ؆୯ʹڞ༗͢Δ͜ͱ͕Ͱ͖Δɻ • expire_in

    Ͱ༗ޮظݶΛઃఆ͢ΔͱࣗಈͰ࡟আͯ͘͠Ε Δɻ • Ξοϓϩʔυͨ͠ϑΝΠϧ͸΢ΣϒαΠτ্͔Β௚઀μ ΢ϯϩʔυͰ͖Δɻ
  6. Environment ػೳ deploy: stage: deploy variables: RELEASE_TAG: $CI_COMMIT_REF_SLUG script: -

    ecs-cli compose -f compose.yml தུ environment: name: ${ENVIRONMENT} when: manual δϣϒʹ؀ڥ໊Λఆ͓͚ٛͯͩ͘͠Ͱ…
  7. Container Registry ͱ Fargate Fargate Secrets Manager Container Registry ᶃ

    ᶄ ᶅ ᶆ 1. CI/CD ͕ Registry ʹΠϝʔδΛϓογϡ 2. CI/CD ͕λεΫఆٛͱαʔϏεΛߋ৽ AWS७ਖ਼ͷ Container Registry (ECR) ͡Όͳͯ͘΋ Deploy Token ͱ Secrets Manager Ͱ Fargate ʹσϓϩΠͰ͖·͢ʂ 3. Fargate ͕ SM ͔Β Deploy Token Λೖख 4. Fargate ͕ Deploy Token Λ࢖ͬͯΠϝʔδΛऔಘ