{"id":16771534,"url":"https://github.com/meysam81/dockercon2022-talk","last_synced_at":"2025-03-17T02:31:31.307Z","repository":{"id":99614492,"uuid":"482526020","full_name":"meysam81/dockercon2022-talk","owner":"meysam81","description":"The source, configs and deployments of the DockerCon 2022 talk all in one place.","archived":false,"fork":false,"pushed_at":"2025-02-03T19:59:03.000Z","size":140,"stargazers_count":29,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T16:47:44.153Z","etag":null,"topics":["awesome-docker","docker","docker-compose","dockercon"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meysam81.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-17T13:08:59.000Z","updated_at":"2024-10-20T07:33:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"b382ccc9-4204-443f-ba93-720149310fea","html_url":"https://github.com/meysam81/dockercon2022-talk","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/meysam81%2Fdockercon2022-talk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysam81%2Fdockercon2022-talk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysam81%2Fdockercon2022-talk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meysam81%2Fdockercon2022-talk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meysam81","download_url":"https://codeload.github.com/meysam81/dockercon2022-talk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841125,"owners_count":20356440,"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":["awesome-docker","docker","docker-compose","dockercon"],"created_at":"2024-10-13T06:28:24.623Z","updated_at":"2025-03-17T02:31:30.732Z","avatar_url":"https://github.com/meysam81.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DockerCon 2022 Talk\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Architecture](#architecture)\n- [Structure of the repo](#structure-of-the-repo)\n  - [How to run it?](#how-to-run-it)\n    - [Prerequisites](#prerequisites)\n    - [1. Separately](#1-separately)\n    - [2. Entire platform](#2-entire-platform)\n    - [URLs](#urls)\n- [Agenda](#agenda)\n  - [Development](#development)\n  - [Dockerfile](#dockerfile)\n  - [docker-compose.yml](#docker-composeyml)\n- [Bonus](#bonus)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\nThis repo contains all the source, configurations, deployment tweaks that were\npresented as a talk to [DockerCon 2022](https://mobile.twitter.com/dockercon).\n\nTo run the entire stack all in one place, just head to the `entire-platform`\ndirectory and run `docker-compose up -d`.\n\n## Architecture\n\nThe design of the platform is simple and straightforward, containing three apps\nthat are all web-apps listening on a HTTP port.\n\nService2 can also contact Service3 for a query in which it caches for future\nreference. The invalidation of the cache is nothing special; it expires after\n10 minutes (configurable).\n\nThe third service is a sample CRUD app that is talking to PostgreSQL for its\nprocessing.\n\nHere's an overview of the system:\n\n![arch](docs/static/arch.png)\n\n## Structure of the repo\n\nEach service has its own directory in here, but in real-life applications, each\nof the following directories would have their own repository:\n\n- service1\n- service2\n- service3\n\nAlso, the `traefik` directory contains the gateway/reverse-proxy and it's\ngenerally just for the ease of access, and not necessarily a service for its\nown.\n\nAdditionally, for ease of access, also the `entire-platform` directory is\nplaced next to others, but, again, in real life scenarios, it would have had\nits own repository.\n\n### How to run it?\n\n**IMPORTANT NOTE**: Don't forget to\n[update](https://github.com/docker/compose/releases) your docker-compose binary\nto v2.\n\n#### Prerequisites\n\nYou will need to add these two entries to your `/etc/hosts` file, regardless of\nwhich approach you choose:\n\n```env\n127.0.0.1    svc.dockercon2022.com\n127.0.0.1    svc-crud.dockercon2022.com\n```\n\nThis is to tell our local DNS resolver to send the traffics of the mentioned\ndomains to the local machine (and ultimately to the `traefik` service).\n\n#### 1. Separately\n\n1. If you want to run the services separately, head to the\n`individual-services` directory.\n2. First, head to `traefik` directory and bring\nup the app: `docker-compose up -d`. Now you're able to head to this link to see\nyour services and endpoints: \u003chttp://localhost:8080\u003e\n3. Head to each `serviceN` directory where `N` is the number of the service\nand then bring up that service (again `docker-compose up -d`).\n\n#### 2. Entire platform\n\nHead to the `entire-platform` directory and bring up the apps, as easy as\n`docker-compose up -d`.\n\n#### URLs\n\nThese are the URLs you can access, whichever approach you choose:\n\n| Service | Endpoint | Considerations |\n| --- | --- | --- |\n| service1 | \u003chttp://svc.dockercon2022.com/v1/\u003e |\n| service2 | \u003chttp://svc.dockercon2022.com/v2/\u003e |\n| service2-copy | \u003chttp://svc.dockercon2022.com/v3/\u003e | Only `entire-platform` |\n| service3 | \u003chttp://svc-crud.dockercon2022.com/v1/\u003e |\n\n## Agenda\n\nThe talk consists of three main components:\n\n1. Development\n2. Dockerfile\n3. docker-compose.yml\n\n### Development\n\n- Anything that can be configurable and might need to be changed, should be\nused as a configuration and not hard-coded.\n- DO NOT commit environmental variables and especially secrets to your code.\nHere's a link to help you better understand how to cleanly separate code from\nconfigurations:\n[Link to article](https://medium.com/licenseware/stop-committing-configurations-to-your-source-code-fb37be351492)\n- You can place env-files in your Dockerfile, but try not to place secrets in\nthere, and also be midnful that they should be able to easily be overwritten\nif they operations team wants to change them.\n- Use GitHub Copilot to make your life much easier!\n\n### Dockerfile\n\n- Place static lines at the top of your Dockerfile. Here's a link to better\nunderstand the advantages and the HOW-TOs:\n[Link to article](https://medium.com/skilluped/10-tips-on-writing-a-proper-dockerfile-13956ceb435f)\n- As much as possible, try to base your docker images from the smallest image;\nthis is both a security recommendation and an operation one.\n- Use multi-stage builds to easily separate out different deployment modes.\n- By default, the last stage of a multi-stage Dockerfile will be used if not\notherwise specified, so put your default stage on the last.\n- It's always a good idea to use health-checks, they make your life a lot\neasier and the visibility of your app/platform much more enhanced. You can also\nplace them in your `docker-compose.yml` file. The example for both approaches\nare included in the repo:\n  - Health check in `Dockerfile` inside `service1` directory\n  - Health check in `compose-svc2.yml` file inside `entire-platform`\n- For the sake of both security and maintainability, try to put\n[dumb-init](https://github.com/Yelp/dumb-init/releases) as your entrypoint. It\nmay not look like it, but it's always a peace and comfort to your mind,\nalthough any web-server would handle the signals for you these days.\n\n### docker-compose.yml\n\n- Everything you see in this repo has been tried with docker-compose v2, so\nbefore going any further, make sure you update your docker-compose binary.\n- Try to put ONLY the related services inside the same network, both for\nsecurity and for a good isolation. This way, those that don't have any business\nwith each other, won't be able to communicate (a security best practice).\n- Use `env_file` directive in your `docker-compose.yml` files because otherwise\nyour file gets larger and harder to maintain.\n- Try to expose the port in which your application is listening, so that you\nand others can easily spot where to send the traffic. It can also be placed\ninside the `Dockerfile` but because of the fact that the operation team might\ndecide to change it, you'd be better doing that in the `docker-compose.yml` for\na more consistent behavior.\n- use `COMPOSE_FILE` to specify which files you would like to include for a\nsingle stack. This will enable your to remove `-f compose-file.yml` from your\nregular command line usage.\n- `restart` is a very good directive to have in your docker-compose, don't\nforget to include that for your services. Here's link to one article in that\nregard:\n[Link to article](https://medium.com/skilluped/stop-writing-mediocre-docker-compose-files-26b7b4c9bd14)\n- ✅ Put related services in their own compose files so that you can easily\nseparate them out and change them accordingly without confusion.\n- Don't try to mix the responsibility of services into a single container.\nAlways try to separate migrations, background-workers, web-apps, etc. into\ntheir own container.\n- In your local machine, you might find it useful to combine `extra_hosts`\ndirective with `/etc/hosts` file to forward the traffic from inside a\ncontainer to your own local machine and back to another container. Example\ninclude `svc2` \u0026 `svc2-copy` in the `entire-platform` directory for different\napproaches to communicate between your services.\n- Use `tmux` and `-d` flag when you want to bring up your application. You\ndon't have to suffer from having multiple terminals open to have access to your\nmachine. Here's a link that you might find useful in that regard:\n[Link to article](https://medium.com/amerandish/a-tmux-a-beginners-guide-7c129733148)\n- The order of `COMPOSE_FILE` variable matters; try to place the definitions\nfirst (left) and the invokation last (right). Checkout `.env` inside\n`entire-platform` directory for an example.\n- When using multiple `env_file` in your compose files for different services,\nthere's a good chance that some configurations are needed for more than one\nservice with the exact same value; try to follow DRY and use substitution so\nthat you don't have to write some key-value pair multiple times, but rather\nrefer back to it in the specific child `.env` file. That way, whenever you want\nto change the value, you only need to change one place.\n- Use `COMPOSE_PROJECT_NAME` to group your stack under a unified hierarchy.\nThis is done by default using directory name by docker, but try to take\ncontrol instead of letting it choose for you.\n\n## Bonus\n\nAs a sample, the AWS CloudFormation sample template of how the real life stack\nwould be deployed has been placed inside the source code. In order to not\npollute the config, only a single service has a cloud-formation:\n`individual-services/service1/cloudformation-templates/service1-dev.yml`\n\nAlso, the complete stack CloudFormation template has also been placed inside\nthe following directory:\n`entire-platform/cloudformation-templates/stack-dev.yml`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeysam81%2Fdockercon2022-talk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeysam81%2Fdockercon2022-talk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeysam81%2Fdockercon2022-talk/lists"}