Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose.yml 간소화 #23

Open
dongwook-chan opened this issue Jul 26, 2023 · 1 comment
Open

docker-compose.yml 간소화 #23

dongwook-chan opened this issue Jul 26, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@dongwook-chan
Copy link

dongwook-chan commented Jul 26, 2023

많은 분들이 의견주신대로 docker-compose에 버전/벤더별로 많은 서비스들이 추가될 수 있을 것 같은데요,
제가 예전에 작성했던 테스트 돌리려면 적어도 MySQL 8.0.16 이상 서비스 1개는 추가되어야 할 것 같네요
YAML anchor 기능을 활용해서 공통 되는 설정값들을 간소하게/깔끔하게 표현할 수 있을 것 같아서 다음과 같이 수정하고 원본 reop에 PR 넣어보려고 합니다.
충은님(@cucuridas)이 깔끔하게 작성해주신 docker-compose.yml에 영감을 받아 숟가락 얹어 봅니다.

수정 전

version: '3.2'
services:
  percona-5.7:
    image: percona:5.7
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: true
    ports:
      - 3306:3306
    command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates

  percona-5.7-ctl:
    image: percona:5.7
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: true
    ports:
      - 3307:3307
    command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307

  percona-8.0.16:
    image: percona:8.0.16
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: true
    ports:
      - 3309:3307
    command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307

  mariadb-10.6:
    image: mariadb:10.6
    environment:
      MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
    ports:
      - "3308:3306"
    command: |
      --server-id=1
      --default-authentication-plugin=mysql_native_password
      --log-bin=master-bin
      --binlog-format=row
      --log-slave-updates=on

수정 후

version: '3.2'

x-mysql: &mysql
  environment:
    MYSQL_ALLOW_EMPTY_PASSWORD: true
  command: >
    mysqld
    --log-bin=mysql-bin.log
    --server-id 1
    --binlog-format=row
    --gtid_mode=on
    --enforce-gtid-consistency=on
    --log_slave_updates

x-mariadb: &mariadb
  environment:
    MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
  command: |
    --server-id=1
    --default-authentication-plugin=mysql_native_password
    --log-bin=master-bin
    --binlog-format=row
    --log-slave-updates=on
  
services:
  percona-5.7:
    <<: *mysql
    image: percona:5.7
    ports:
      - 3306:3306

  percona-5.7-ctl:
    <<: *mysql
    image: percona:5.7
    ports:
      - 3307:3306
      
  percona-8.0.16:
    <<: *mysql
    image: percona:8.0.16
    ports:
      - 3309:3306

  mariadb-10.6:
    <<: *mariadb
    image: mariadb:10.6
    ports:
      - 3308:3306
  • x- 로 시작하는 element들은 docker-compose의 extension 기능을 활용한 것으로, 실제로 실행되는 부분은 아닙니다.
  • Anchor 적용하면 어떤 모습인지는 https://yaml-online-parser.appspot.com 에서 확인 가능하십니다~
  • --log_slave_updates는 필요 없는 인자인 것 같아서 원본 repo에 삭제 예고(?) 해놓았습니다.
@dongwook-chan dongwook-chan added the enhancement New feature or request label Jul 26, 2023
@chungeun-choi
Copy link

저 기능을 anchor라고 했었군요...또 하나 배워갑니다 :)
확장성을 고려한 좋은 방법인거 같아요! 감사합니다! 좋은 거 많이 배우네요 ㅎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants