# Makefile and Docker-Compose

<figure><img src="https://3659592921-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MT9ekEKLz6OnDzyE_M_%2Fuploads%2FJtfmn56auOvRZCf6ocGW%2Fduoforce.png?alt=media&#x26;token=305f5a24-124d-424d-b2ac-7f9940dfff6e" alt=""><figcaption></figcaption></figure>

#### <mark style="color:orange;">**`Make`**</mark> for task running and dependency management:

{% hint style="success" %}

* Manages reusable, consistent task running for CI/CD with minimal dependency
* Can run prerequisite tasks / commands for dependency chaining
* Allows flexibility to run tasks that don't require containerization (eg: for a linux only environment, running a `curl` task natively doesn't require a docker container)
* Native to Unix based Operating Systems and WSL2. 3mb executable on Windows
* Small learning curve with widely available standards and patterns
* A mature and industry-wide used tool with a large online community
* Entirely Opensource
  {% endhint %}

{% code title="Example:" %}

```sh
# Variables
s3_bucket = "my-frontend-website"

# Install npm dependencies and start container on port "http://localhost:3001"
start:
	docker-compose up -d --build node
	echo "Navigate to http://localhost:3001"

# Build application for deployment
build:
	docker-compose run --rm --entrypoint "npm run build" node

# First run the dependent "build" task then deploy build folder to AWS S3 using awscli
deploy: build
	aws s3 sync build/ s3://$(s3_bucket) --acl public-read"
	echo "Upload complete."

```

{% endcode %}

#### <mark style="color:yellow;">**`Docker-Compose`**</mark> for container management:

{% hint style="success" %}

* A mature and Industry wide used tool with a large online community
* YAML based configuration with small learning curve
* Decoupled from task running and dependency management
* On it's own `docker-compose` has limitations which are mitigated by `make` which takes care of container based task running and task dependencies
  {% endhint %}

{% code title="Example:" %}

```yaml
version: '3.7'

services:
  node:
    container_name: node
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - '.:/app'
      - '/app/node_modules'
    ports:
      - 3001:3000
    environment:
      - CHOKIDAR_USEPOLLING=true

```

{% endcode %}

&#x20;:point\_down: *Strongly influenced by the "3 musketeers" pattern and put into practice at enterprise scale*

{% embed url="<https://3musketeers.io/guide/>" %}
