{"id":21685046,"url":"https://github.com/corpusops/setups.mysql","last_synced_at":"2025-07-18T05:32:20.932Z","repository":{"id":18496196,"uuid":"21692173","full_name":"corpusops/setups.mysql","owner":"corpusops","description":null,"archived":false,"fork":false,"pushed_at":"2020-01-16T13:34:56.000Z","size":88,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-03-15T00:03:18.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"SaltStack","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/corpusops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-10T11:43:37.000Z","updated_at":"2024-03-15T00:03:18.432Z","dependencies_parsed_at":"2022-07-30T13:39:30.361Z","dependency_job_id":null,"html_url":"https://github.com/corpusops/setups.mysql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corpusops%2Fsetups.mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corpusops%2Fsetups.mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corpusops%2Fsetups.mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corpusops%2Fsetups.mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/corpusops","download_url":"https://codeload.github.com/corpusops/setups.mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226358649,"owners_count":17612405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T16:18:06.250Z","updated_at":"2024-11-25T16:18:07.009Z","avatar_url":"https://github.com/corpusops.png","language":"SaltStack","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker based image for mysql\n\n\n\n## corpusops/mysql (CURRENT)\n### Description\nThis setups a nginx reverse proxy on http/https that forward requests\nto an underlying mysql worker.\n\nThis repository produces all those docker images:\n- [corpusops/mysql](https://hub.docker.com/r/corpusops/mysql/)\n\n### Volumes\n- We use two main volumes!\n    - a volume ``setup`` to share a configuration file to reconfigure fles\n    - a volume ``data`` to store user data\n\n#### Initialise setup volume\n- To reconfigure any setting upon container (re)start, create/edit ``/setup/reconfigure.yml``\n    - See [defaults](/ansible/roles/mysql/defaults/main.yml)\n\n    ```sh\n    mkdir -p local/setup\n    cat \u003elocal/setup/reconfigure.yml \u003c\u003c EOF\n    ---\n    setting: value\n    ```\n\n- To configure (add/modify/remove) new roles, db, \u0026 privs (resp. in this order),  we use custom corpusops modules which all wraps ansible official modules:\n   - [corpusops.roles/mysql_role](https://github.com/corpusops/roles/tree/master/mysql_role)\n   - [corpusops.roles/mysql_db](https://github.com/corpusops/roles/tree/master/mysql_db)\n- Exemple\n\n    ```yaml\n    cops_mysql__roles:\n    - name: dbuser\n      # generate/use password inside file: ./local/config/pwd_dbuser\n      password: foo\n    cops_mysql__databases:\n    - db: db\n      owner: dbuser\n    - db: db3\n      state: absent\n    cops_mysql__privs:\n    - roles: dbuser\n      database: db2\n      type: database\n      privs: ALL\n\n    ```\n\n- If you need to tune pgsql, you can add something to ``/setup/reconfigure.yml`` this way:\n\n    ```yaml\n    ---\n\tcorpusops_services_db_mysql_mode: myproject\n\tcorpusops_services_db_mysql_modes_myproject:\n\t  number_of_table_indicator: 1000\n\t  innodb_flush_method: 'O_DIRECT'\n\t  innodb_flush_log_at_trx_commit: 2\n\t  nb_connections: 250\n\t  memory_usage_percent: 20\n    cops_mysql_sysctls:\n    - kernel.shmall: 4026531840\n    - kernel.shmmax: 16106127360\n    ```\n\n#### Initialise user data volumes\n- You need to preseed some volumes from your image before running it\n    - db\n\n        ```sh\n        mkdir -p local/db\n        docker run --rm  -v $PWD/local/db:/ldb --entrypoint rsync \\\n            corpusops/mysql:9.6.5 \\\n            \"/var/lib/mysql/\" \"/ldb/\" \\\n           -av --delete\n        ```\n\n    - data\n\n        ```sh\n        mkdir -p local/data\n        docker run --rm  -v $PWD/local/data:/ldata --entrypoint rsync \\\n            corpusops/mysql:9.6.5 \\\n            \"/srv/projects/mysql/data/\" \"/ldata/\" \\\n            -av --delete --exclude \"pwd_*\" --delete-excluded\n        ```\n\n### Run this image through docker\n- To pull \u0026 run this image (PRODUCTION) \u003cbr/\u003e\n  Note that The folllowing command implicitly create 2 volumes against local directories and the goal\n  is to prepopulate the directories from the image content on the first run.\u003cbr/\u003e\n  Indeed, the -v option does not feed host directories, even if empty from an image content.\n\n    ```sh\n    # docker pull corpusops/mysql:\u003cTAG\u003e\n    docker pull corpusops/mysql:9.6.5\n    docker run \\\n      --name=my-mysql-container \\\n      -v /sys/fs/cgroup:/sys/fs/cgroup:ro \\\n      -v $(pwd)/local/setup:/setup:ro \\\n      -v \"$(pwd)/local/data:/srv/projects/mysql/data\" \\\n      -v \"$(pwd)/local/db:/var/lib/mysql\" \\\n      --security-opt seccomp=unconfined \\\n      -P -d -i -t corpusops/mysql:9.6.5\n    ```\n\n- In development, you can add the following knob to indicate that you want to\n  edit files.\n\n    ```sh\n    -e SUPEREDITORS=$(id -u)\n    ```\n\n### Build this image\n- Install ``hashicorp/packer`` \u0026\u0026 ``docker``\n- get the code\n- run ``./bin/build.sh``\n\n### Image provision notes\n- See ``.ansible``, the image is (re)-configured using ansible.\n\n### A note on file rights\n- Docker file rights are a nightmare for developers\n- We provide a very way to use, specially when you are on localhost,\u003cbr/\u003e\n  activly developping  your app to edit the files of the container,\u003cbr/\u003e\n  thanks to POSIX ACLS.\n- You need two things to configure your app (normally good by dedfault):\n    - ``cops_mysql_supereditors_paths`` Tell which paths will be \"opened\" to the outside user(s) if default does not suit your need\n    - ``cops_mysql_supereditors`` Tell which user(s), (attention **UIDS**).\u003cbr/\u003e\n      The aforementioned command to launch container includes the ``SUPEREDITORS`` env var configured with the loggued in user\n- Those settings can be overriden via ``/setup/reconfigure.yml``\n- File rights are enforced upon container (re-)start\n- If file rights are messed up too much, you can try this to enforce them\n\n    ```sh\n    docker exec -e SUPEREDITORS=\"$(id -u)\" -ti \u003cmycontainer\u003e bash\n    /srv/projects/\u003cmyproject\u003e/fixperms.sh\n    ```\n\n## ansible\n- Docker uses the [mysql role](.ansible/roles/mysql) underthehood which\n  is generic and is not docker specific.\n- You may use directly this role to provision mysql on another host type.\n- This code the raw [corpusops.roles/mysql role](https://github.com/corpusops/roles/tree/master/services_db_mysql)\n\n### Steps to create cops docker compliant images\n- We use via  bin/build.sh which launch [docker_build_chain](https://github.com/corpusops/corpusops.bootstrap/blob/master/hacking/docker_build_chain.py) ([doc](https://github.com/corpusops/corpusops.bootstrap/blob/master/doc/docker_build_chain.md#sumup-steps-to-create-corpusops-docker-compliant-images))\n\n\n\n## USE/Install with makina-states\n- makina-state deployment (legacy) can be found in .salt\n\n### Exemple pillar\n\n```yaml\n\n  makina-projects.pgsql:\n   data:\n    backup_disabled: false\n    pgver: 9.6\n    mail: sysadmin@foo.com\n    pg_optim:\n      #./pgtune/pgtune -i /etc/mysql/9.5/main/mysql.conf -M $((15842612*1024))\n      - default_statistics_target = 100\n      - maintenance_work_mem = 960MB\n      - checkpoint_completion_target = 0.9\n      - effective_cache_size = 11GB\n      - work_mem = 72MB\n      - shared_buffers = 3840MB\n    sysctls:\n      - kernel.shmall: 4026531840\n      - kernel.shmmax: 16106127360\n    databases:\n      - x:\n          password: \"x\"\n          user: x\n```\n     \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorpusops%2Fsetups.mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorpusops%2Fsetups.mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorpusops%2Fsetups.mysql/lists"}