digdagãDockerizeãã¦ECSä¸ã§éç¨ãããã¨ã«ãã¾ãã
ãã¼ã¿åæãå¯è¦åã«ä¼´ãè¤éãªã¸ã§ãããã¼ã®æ¹åã«ã¯digdagã便å©ã§ãã
å°ããã¤æ¡ç¨äºä¾ãå¢ãã¦ããããã§ãã
ä»åã¯ããããªä¾¿å©ãªdigdagãECSä¸ã«æ§ç¯ãã¾ããã
äºåç¥è
digdagã«é¢ããåºæ¬çãªç¥èã¯ã以åã®ã¨ã³ããªãåèã«ãã¦ãã ããã
ã³ã¼ã
ãµã³ãã«ç¨ã«ã³ã¼ããå ¬éãã¾ããã
digdagãDockerizeããè¨å®ãã¡ã¤ã«(digãã¡ã¤ã«)ãä¸ç·ã«åºãã¦ECRã«pushãã¦ãã¾ãã
ã¤ã¾ããdigdagã®ææ°ã®è¨å®ãã¡ã¤ã«ã¯å¸¸ã«ECRã«ããç¶æ
ã§ãã
digdagã®è¨å®ãã¡ã¤ã«ãå¤æ´ãããã©ã³ããmasterã«ãã¼ã¸ãããã¨ãshippableãdocker buildã»digdag checkã»docker pushã»ECSã«é¢ããå¦çããããªããå¤ãdigdagã³ã³ãããç ´æ£ãããæ°ããdigdagã³ã³ãããç«ã¤ã¨ããã©ã¤ããµã¤ã¯ã«ã§ãã
éçºè
ã®ä½æ¥ã¯GitHubã ãã§å®çµãã¾ãã
ç¾ç¶ãç»é²ããã¸ã§ããã¾ã å°ãªãã®ã§ãç¡åæ¢éç¨ãé å¼µããdigdagã³ã³ãããæ¯åæ°ãã«ç«ã¦ãã¨ããéç¨ã«ãã¦ãã¾ãã
ã¡ãªã¿ã«ãdigdagã«ã¯æå®ããdocker imageã§ã¿ã¹ã¯ãå®è¡ããããdigdag pushã¨ããè¨å®ãã¡ã¤ã«ãç»é²ããæ©æ§ãããã®ã§ãããããæ´»ç¨ããã°ç¡åæ¢éç¨ãå¯è½ã§ãã
é¸å®çç±
ECSã使ãçç±
ä»å¹´1æã«JUBILEE WORKSã¨ããä¼ç¤¾ã«è»¢è·ãããã®ã§ãããããã§ã¯åºæ¬çã«å
¨ã¦ã®ç°å¢ãECSä¸ã«æ§ç¯ããã¦ãã¾ãã
ãããã£ã¦ããªã«ããå°å
¥ããã¨ãã¯Dockerizeãã¦ECSä¸ã«ç«ã¦ã¦ãã¾ãã®ãä¸çªä½æ¥ã³ã¹ããä½ãã§ãã
ãECSä¸ã«ç«ã¦ã¦digdagãã¹ã±ã¼ã©ããªãã£ã«ï¼ããããããã¤ï¼ç¡åæ¢éç¨ï¼ãã¨ãããããã³ã³ãããAWSä¸ã§åãããªãECSãä¸çªæ¥½ã ããããããã®æ°è»½ãªæè¦ã§ãã
digdagã使ãçç±
ä»åãMySQLã®ãã¼ã¿ãEmbulkã§BigQueryã«å
¥ãã¦Re:dashã§å¯è¦å&åæããããªãããã§ã
MySQLããBigQueryã¸ã®ä¸é£ã®ã¯ã¼ã¯ããã¼ãå¹çããçµãã®ã«digdagãæé©ã§ããã
digdagã使ãã¨ãåå¦çã並åã§å®è¡ã§ããã®ã§ä¾¿å©ã§ãã
ã¾ããå¤æ°ãfor_eachã使ãã¨ä¼¼ããããªEmbulkã®ymlãæ¸ããªãã¦æ¸ãã®ã便å©ã§ãã
shippableã使ãçç±
主ã«Dockerã³ã³ããã®ãã£ãã·ã¥ç®çã§ãã
ãã以å¤ã®æ©è½ã¯ã ãããã©ãã®CIãµã¼ãã¹ã§ãåãã¦ãããã®ãå¤ãã§ãã
æ§ç¯æã®ãã¤ã³ã
digdagã®dockerize
以ä¸ã®ããã«ãªãã¾ããã
FROM java:8 MAINTAINER yukiyan <[email protected]> ENV DIGDAG_VERSION=0.9.3 RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \ jruby && \ curl -o /usr/local/bin/digdag --create-dirs -L "https://dl.digdag.io/digdag-${DIGDAG_VERSION}" && \ chmod +x /usr/local/bin/digdag && \ curl -o /usr/local/bin/embulk --create-dirs -L "http://dl.embulk.org/embulk-latest.jar" && \ chmod +x /usr/local/bin/embulk && \ apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* && \ adduser --shell /sbin/nologin --disabled-password --gecos "" digdag USER digdag WORKDIR /home/digdag RUN embulk gem install \ embulk-input-mysql \ embulk-output-bigquery COPY tasks tasks COPY main-digdag.dig . EXPOSE 65432 CMD ["java", "-jar", "/usr/local/bin/digdag", "scheduler", "-m"]
java:8-alpine
ã使ãããã£ãã®ã§ãããdigdagå
ã§ã®Embulkã®å¦çã®é¨åã§ãã¾ããããªãã£ãã®ã§æ念ãã¾ãã(ãããªã«åé¡ã§ã¯ãªã)ã
ãã¨ãCMD ["digdag", "scheduler", "-m"]
ã§ã¯ãªãjava -jar
ã§å®è¡ããªãã¨ã¨ã©ã¼ã«ãªãã¾ãã
ãã®issueãåèã«ãªãã¾ãã
jrubyã¯embulk-input-mysqlã®ã¤ã³ã¹ãã¼ã«æã«å¿ è¦ãªã®ã§å ¥ãã¦ã¾ãã
ã¾ããdigdagã§RubyãPythonã®ãªãã¬ã¼ã¿ã使ãå ´åã¯ãããå
¥ããå¿
è¦ãããã¾ãã
ä»ã¯ã¾ã Embulkãã使ã£ã¦ãªãã®ã§å
¥ãã¦ã¾ããã
digdagã®è¨å®ãã¡ã¤ã«ã®ä½æ
ãMySQLããBigQueryã¸Embulkã§ãã¼ããããã¨ããã¯ã¼ã¯ããã¼ãçµãã¨ã以ä¸ã®ãããªè¨å®ãã¡ã¤ã«ã«ãªãã¾ãã
åç´ãªæ§é ãªã®ã§ããªãã¨ãªãé°å²æ°ã¯æ´ããã¨æãã¾ãã
# main-digdag.dig timezone: UTC schedule: daily>: 00:00:00 +main: _export: host: 'mysql.hogehoge.ap-northeast-1.rds.amazonaws.com' user: 'hoge' password: 'fuga' project_id: 'bigquery_sample_project' dataset: 'bigquery_sample_dataset' +all_load: _parallel: true +load_db1: !include : 'tasks/db/db1.dig' +load_db2: !include : 'tasks/db/db2.dig'
ã¡ã¤ã³ã®digãã¡ã¤ã«ã§ãã
_export:
ã¯å¤æ°ãå®ç¾©ãã¦ãã¾ãã${host}
ã®ããã«ãã¦åç
§ã§ãã¾ãã
!include:
ã使ãã¨digãã¡ã¤ã«ãåå²ã§ãã¾ãã
_parallel: true
ãæå®ãããã¨ã§åã¿ã¹ã¯ã§ãã+load_db1
ã¨+load_db2
ã並åã§å®è¡ããã¾ããå«ã¿ã¹ã¯ã«ã¯å½±é¿ãã¾ããã
# tasks/db/db1.dig +mysql_bigquery: _export: database: 'db1' +load: for_each>: table: [ hoge_table_1, hoge_table_2, hoge_table_3, hoge_table_4, ] _do: embulk>: tasks/db/embulk/mysql_bigquery.yml
# tasks/db/db2.dig +mysql_bigquery: _export: database: 'db2' +load: for_each>: table: [ sample_table_1, sample_table_2, sample_table_3, sample_table_4, ] _do: embulk>: tasks/db/embulk/mysql_bigquery.yml
åã¿ã¹ã¯ã®digãã¡ã¤ã«ã§ãã
for_each
ã®ãããã§ä»¥ä¸ã®ãããªåé·ãªè¨è¿°ãã¹ãã¼ãã«æ¸ãã¾ãã
for_each
å
ã_parallel: true
ã§ä¸¦åå¦çå¯è½ã§ããããã¾ã並å度ãå¢ãããããã¨lockç³»ã®è¦åãåºãã®ã§ãããã¯ããã¦ä¸¦åã«ãã¾ããã§ããã
# åé·ãªè¨è¿°ã®ä¾ +mysql_bigquery: _export: database: 'db1' +load: _export: table: 'hoge_table_1' embulk>: tasks/db/embulk/mysql_bigquery.yml _export: table: 'hoge_table_2' embulk>: tasks/db/embulk/mysql_bigquery.yml _export: table: 'hoge_table_3' embulk>: tasks/db/embulk/mysql_bigquery.yml _export: table: 'hoge_table_4' embulk>: tasks/db/embulk/mysql_bigquery.yml
# tasks/db/embulk/mysql_bigquery.yml in: type: mysql host: ${host} user: ${user} password: '${password}' database: ${database} table: ${table} out: type: bigquery mode: replace auth_method: json_key json_keyfile: content: | { "private_key_id": "123456789", "private_key": "-----BEGIN PRIVATE KEY-----\nABCDEF", "client_email": "..." } project: ${project_id} dataset: ${dataset} auto_create_table: true table: ${table}_${session_date_compact} allow_quoted_newlines: true
Embulkã®è¨å®ãã¡ã¤ã«ã§ãã
ããã¾ã§ã®digãã¡ã¤ã«ã®_export
ã§å®ç¾©ããå¤æ°ãæ´»ç¨ãããã¨ã§ãä¼¼ããããªEmbulkã®è¨å®ãã¡ã¤ã«ãä½ãå¿
è¦ãç¡ããªãã¾ãã
ãã¨ãpassword:
ã®ç®æã®ã¿ã§ããã${password}
ã§ã¯ãªã'${password}'
ã«ããªãã¨ã¨ã©ã¼ã«ãªãã¾ããããã¯ãã¶ãembulk-input-mysqlã®ãã°ããã
digdagã®ãã°
digdagã®ãã°ã¯ããã©ã«ãã§ã¯æ¨æºåºåã«åãããã®ã§ãlog driverã使ã£ã¦cloudwatch logsã«éã£ã¦ãã¾ãã
digdag: image: 123456.dkr.ecr.ap-northeast-1.amazonaws.com/digdag:${BUILD_NUMBER} ports: - 65432:65432 memory: 2000 essential: true log_driver: awslogs log_opt: awslogs-group: /ecs/digdag awslogs-region: ap-northeast-1
shippableã®è¨å®ãã¡ã¤ã«ã®ä½æ
ã¤ã¡ã¼ã¸ã®buildã»ECRã¸ã®pushã»ECSã®Task definitionã®ç»é²ãupdate-serviceã¯shippableã«ä»»ãã¦ãã¾ãã
shippableã«ã¤ãã¦ã¯ãr7kamuraããã®è¨äºãåèã«ãã¦ãã ããã
ecs-formationã«ã¤ãã¦ã¯ç¤¾å
ã§å©ç¨å®ç¸¾ãããã®ã§ä½¿ã£ã¦ãã¾ãã
使ãæ¹ã¯ä½è
ã®stormcatããã®è¨äºãåèã«ãã¦ãã ããã
language: go go: - 1.5 env: global: - secure: hogehoge build: ci: - export DOCKER_TAG=${ECR_REPOSITORY_URL}:${BUILD_NUMBER} - docker build --tag ${DOCKER_TAG} . - docker run ${DOCKER_TAG} java -jar /usr/local/bin/digdag check post_ci: - > go get github.com/stormcat24/ecs-formation; echo -e "project_dir: $SHIPPABLE_BUILD_DIR/ecs-formation\naws_region: ap-northeast-1" > $HOME/.ecs-formation.yml - ecs-formation task plan -p BUILD_NUMBER=${BUILD_NUMBER} -t digdag - > if [[ "${BRANCH}" == "master" ]]; then sudo docker push ${DOCKER_TAG} ecs-formation task -p BUILD_NUMBER=${BUILD_NUMBER} apply -t digdag aws ecs update-service --cluster digdag --service digdag --task-definition digdag --deployment-configuration maximumPercent=100,minimumHealthyPercent=0 fi integrations: hub: - integrationName: ecr type: ecr region: ap-northeast-1 branches: only: - master notifications: - integrationName: email type: email on_success: never on_failure: never on_pull_request: never - integrationName: slack type: slack on_failure: always on_success: always recipients: - "#sandbox" branches: only: - master
secure: hogehoge
ã®ä¸ã«ã¯ãAWSã®ãã¼ã¯ã³çã®ç§å¿å¤ãæå·åããã¦ã¾ãã
BUILD_NUMBERãSHIPPABLE_BUILD_DIRã¯shippableã®å®æ°ã§ãä»ã«ãããã¤ãããã¾ãã
ææ
ä»åã¯digdagãschedulerã¨ãã¦å¸¸æèµ·åããããã«ãã¦ãã¾ãããä»å¾AWS Batchã§ä»£æ¿ã§ããããªæ°ããã¾ãã
ãªã®ã§ãAWS Batchã§digdag runãå®æå®è¡ãããã®ãçµæ§è¯ããããªæ°ããã¾ããã¤ã³ã¹ã¿ã³ã¹ã®å¸¸æèµ·åä¸è¦ã«ãªãããã¹ãããã¤ã³ã¹ã¿ã³ã¹ãæ´»ç¨ããããããæ¥æ¬ãªã¼ã¸ã§ã³æ¥ããæ¤è¨¼ãããã§ãã
AWS Batchã®è£å´ã¯ECSãªã®ã§ãECSã§åãããã¨ãããã¨ã¯AWS Batchã§ãåãã¾ã(ãããã...)ã
ãã¨ãshippableã¯dockerã³ã³ããããã£ãã·ã¥ãã¦ããããããã§ãããéãã¦å¿«é©ã§ãã