Skip to content

Instantly share code, notes, and snippets.

@JackMoth
Forked from mpneuried/Makefile
Created March 16, 2018 08:46
Show Gist options
  • Save JackMoth/abeed8614579cf766be6130443a5994d to your computer and use it in GitHub Desktop.
Save JackMoth/abeed8614579cf766be6130443a5994d to your computer and use it in GitHub Desktop.

Revisions

  1. @mpneuried mpneuried revised this gist Dec 18, 2017. 2 changed files with 4 additions and 4 deletions.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@ endif
    ifdef AWS_CLI_REGION
    CMD_REPOLOGIN += " --region $(AWS_CLI_REGION)"
    endif
    CMD_REPOLOGIN += " get-login \)"
    CMD_REPOLOGIN += " get-login --no-include-email \)"

    # login to AWS-ECR
    repo-login: ## Auto login to AWS-ECR unsing aws-cli
    6 changes: 3 additions & 3 deletions Makefile.docker-compose
    Original file line number Diff line number Diff line change
    @@ -93,10 +93,10 @@ endif
    ifdef AWS_CLI_REGION
    CMD_REPOLOGIN += "--region $(AWS_CLI_REGION)"
    endif
    CMD_REPOLOGIN += "get-login"
    CMD_REPOLOGIN += "get-login --no-include-email"

    repo-login: ## auto login to AWS-ECR unsing aws-cli
    @echo $(CMD_REPOLOGIN) | sh | sed 's/-e none //' | sh
    repo-login: ## Auto login to AWS-ECR unsing aws-cli
    @eval $(CMD_REPOLOGIN)

    version: ## output to version
    @echo $(VERSION)
  2. @mpneuried mpneuried revised this gist Oct 9, 2017. 2 changed files with 19 additions and 26 deletions.
    22 changes: 9 additions & 13 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,14 @@
    # import config
    configfile=config.env
    ifdef cnf
    configfile=$(cnf)
    endif
    include $(configfile)
    export $(shell sed 's/=.*//' $(configfile))
    # import config.
    # You can change the default config with `make cnf="config_special.env" build`
    cnf ?= config.env
    include $(cnf)
    export $(shell sed 's/=.*//' $(cnf))

    # import deploy config
    deployfile=deploy.env
    ifdef dpl
    deployfile=$(dpl)
    endif
    include $(deployfile)
    export $(shell sed 's/=.*//' $(deployfile))
    # You can change the default deploy config with `make cnf="deploy_special.env" release`
    dpl ?= deploy.env
    include $(dpl)
    export $(shell sed 's/=.*//' $(dpl))

    # grep the version from the mix file
    VERSION=$(shell ./version.sh)
    23 changes: 10 additions & 13 deletions Makefile.docker-compose
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,16 @@
    ### THIS IST THE VERSION WITH docker-compose
    # import config
    configfile=config.env
    ifdef cnf
    configfile=$(cnf)
    endif
    include $(configfile)
    export $(shell sed 's/=.*//' $(configfile))

    # import config.
    # You can change the default config with `make cnf="config_special.env" build`
    cnf ?= config.env
    include $(cnf)
    export $(shell sed 's/=.*//' $(cnf))

    # import deploy config
    deployfile=deploy.env
    ifdef dpl
    deployfile=$(dpl)
    endif
    include $(deployfile)
    export $(shell sed 's/=.*//' $(deployfile))
    # You can change the default deploy config with `make cnf="deploy_special.env" release`
    dpl ?= deploy.env
    include $(dpl)
    export $(shell sed 's/=.*//' $(dpl))

    # grep the version from the mix file
    VERSION=$(shell ./version.sh)
  3. @mpneuried mpneuried revised this gist Oct 9, 2017. 2 changed files with 67 additions and 66 deletions.
    46 changes: 27 additions & 19 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -17,47 +17,56 @@ export $(shell sed 's/=.*//' $(deployfile))
    # grep the version from the mix file
    VERSION=$(shell ./version.sh)


    # HELP
    # This will output the help for each task
    # thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
    .PHONY: help

    help: ## This help.
    @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

    .DEFAULT_GOAL := help


    # DOCKER TASKS
    # Build the container
    build:
    build: ## Build the container
    docker build -t $(APP_NAME) .

    # Build the container without cache
    build-nc:
    build-nc: ## Build the container without caching
    docker build --no-cache -t $(APP_NAME) .

    # Run container on port configured in `config.env`
    run:
    run: ## Run container on port configured in `config.env`
    docker run -i -t --rm --env-file=./config.env -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

    # Build and run the container
    up: build run

    stop:
    up: build run ## Run container on port configured in `config.env` (Alias to run)

    stop: ## Stop and remove a running container
    docker stop $(APP_NAME); docker rm $(APP_NAME)

    # Docker release - build, tag and push the container
    release: build-nc publish
    release: build-nc publish ## Make a release by building and publishing the `{version}` ans `latest` tagged containers to ECR

    # Docker publish
    publish: repo-login publish-latest publish-version
    publish: repo-login publish-latest publish-version ## Publish the `{version}` ans `latest` tagged containers to ECR

    publish-latest: tag-latest
    publish-latest: tag-latest ## Publish the `latest` taged container to ECR
    @echo 'publish latest to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO)/$(APP_NAME):latest

    publish-version: tag-version
    publish-version: tag-version ## Publish the `{version}` taged container to ECR
    @echo 'publish $(VERSION) to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    # Docker tagging
    tag: tag-latest tag-version
    tag: tag-latest tag-version ## Generate container tags for the `{version}` ans `latest` tags

    tag-latest:
    tag-latest: ## Generate container `{version}` tag
    @echo 'create tag latest'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest

    tag-version:
    tag-version: ## Generate container `latest` tag
    @echo 'create tag $(VERSION)'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    @@ -74,10 +83,9 @@ endif
    CMD_REPOLOGIN += " get-login \)"

    # login to AWS-ECR
    repo-login:
    repo-login: ## Auto login to AWS-ECR unsing aws-cli
    @eval $(CMD_REPOLOGIN)

    # output to version
    version:
    version: ## Output the current version
    @echo $(VERSION)

    87 changes: 40 additions & 47 deletions Makefile.docker-compose
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    ### THIS IST THE VERSION WITH docker-compose

    # import config
    configfile=config.env
    ifdef cnf
    @@ -19,94 +18,88 @@ export $(shell sed 's/=.*//' $(deployfile))
    # grep the version from the mix file
    VERSION=$(shell ./version.sh)

    # HELP
    # This will output the help for each task
    # thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
    .PHONY: help

    help: ## This help.
    @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

    .DEFAULT_GOAL := help



    # DOCKER TASKS

    # Build the container
    build:
    build: ## Build the release and develoment container. The development
    docker-compose build --no-cache $(APP_NAME)
    docker-compose run $(APP_NAME) grunt build
    docker build -t $(APP_NAME) .

    # Run container on port configured in `config.env`
    run: stop

    run: stop ## Run container on port configured in `config.env`
    docker run -i -t --rm --env-file=./config.env -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

    dev:
    docker-compose build --no-cache test && docker-compose run test

    dev: ## Run container in development mode
    docker-compose build --no-cache $(APP_NAME) && docker-compose run $(APP_NAME)

    # Build and run the container
    up:
    up: ## Spin up the project
    docker-compose up --build $(APP_NAME)

    stop:
    stop: ## Stop running containers
    docker stop $(APP_NAME)

    rm: stop
    rm: stop ## Stop and remove running containers
    docker rm $(APP_NAME)

    tc=1
    ifdef count
    tc=$(count)
    endif
    test:
    docker-compose build --no-cache test
    @if [ $(tc) = 1 ]; then\
    docker-compose run test\
    else\
    docker-compose scale test=$(tc)\
    docker-compose logs -f test\
    fi


    test-live:
    docker-compose build --no-cache testlive
    @if [ $(tc) = 1 ]; then\
    docker-compose run testlive\
    else\
    docker-compose scale testlive=$(tc)\
    docker-compose logs -f testlive\
    fi
    clean: ## Clean the generated/compiles files
    echo "nothing clean ..."

    # Docker release - build, tag and push the container
    release: build publish
    release: build publish ## Make a release by building and publishing the `{version}` ans `latest` tagged containers to ECR

    # Docker publish
    publish: repo-login publish-latest publish-version
    publish: repo-login publish-latest publish-version ## publish the `{version}` ans `latest` tagged containers to ECR

    publish-latest: tag-latest
    publish-latest: tag-latest ## publish the `latest` taged container to ECR
    @echo 'publish latest to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO)/$(APP_NAME):latest

    publish-version: tag-version
    publish-version: tag-version ## publish the `{version}` taged container to ECR
    @echo 'publish $(VERSION) to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    # Docker tagging
    tag: tag-latest tag-version
    tag: tag-latest tag-version ## Generate container tags for the `{version}` ans `latest` tags

    tag-latest:
    tag-latest: ## Generate container `{version}` tag
    @echo 'create tag latest'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest

    tag-version:
    tag-version: ## Generate container `latest` tag
    @echo 'create tag $(VERSION)'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)



    # HELPERS

    # generate script to login to aws docker repo
    CMD_REPOLOGIN := "eval $$\( aws ecr"
    CMD_REPOLOGIN := "aws ecr"
    ifdef AWS_CLI_PROFILE
    CMD_REPOLOGIN += " --profile $(AWS_CLI_PROFILE)"
    CMD_REPOLOGIN += "--profile $(AWS_CLI_PROFILE)"
    endif
    ifdef AWS_CLI_REGION
    CMD_REPOLOGIN += " --region $(AWS_CLI_REGION)"
    CMD_REPOLOGIN += "--region $(AWS_CLI_REGION)"
    endif
    CMD_REPOLOGIN += " get-login \)"
    CMD_REPOLOGIN += "get-login"

    # login to AWS-ECR
    repo-login:
    @eval $(CMD_REPOLOGIN)
    repo-login: ## auto login to AWS-ECR unsing aws-cli
    @echo $(CMD_REPOLOGIN) | sh | sed 's/-e none //' | sh

    # output to version
    version:
    version: ## output to version
    @echo $(VERSION)
  4. @mpneuried mpneuried revised this gist Oct 31, 2016. 1 changed file with 112 additions and 0 deletions.
    112 changes: 112 additions & 0 deletions Makefile.docker-compose
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,112 @@
    ### THIS IST THE VERSION WITH docker-compose

    # import config
    configfile=config.env
    ifdef cnf
    configfile=$(cnf)
    endif
    include $(configfile)
    export $(shell sed 's/=.*//' $(configfile))

    # import deploy config
    deployfile=deploy.env
    ifdef dpl
    deployfile=$(dpl)
    endif
    include $(deployfile)
    export $(shell sed 's/=.*//' $(deployfile))

    # grep the version from the mix file
    VERSION=$(shell ./version.sh)

    # DOCKER TASKS
    # Build the container
    build:
    docker-compose build --no-cache $(APP_NAME)
    docker-compose run $(APP_NAME) grunt build
    docker build -t $(APP_NAME) .

    # Run container on port configured in `config.env`
    run: stop
    docker run -i -t --rm --env-file=./config.env -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

    dev:
    docker-compose build --no-cache test && docker-compose run test

    # Build and run the container
    up:
    docker-compose up --build $(APP_NAME)

    stop:
    docker stop $(APP_NAME)

    rm: stop
    docker rm $(APP_NAME)

    tc=1
    ifdef count
    tc=$(count)
    endif
    test:
    docker-compose build --no-cache test
    @if [ $(tc) = 1 ]; then\
    docker-compose run test\
    else\
    docker-compose scale test=$(tc)\
    docker-compose logs -f test\
    fi


    test-live:
    docker-compose build --no-cache testlive
    @if [ $(tc) = 1 ]; then\
    docker-compose run testlive\
    else\
    docker-compose scale testlive=$(tc)\
    docker-compose logs -f testlive\
    fi

    # Docker release - build, tag and push the container
    release: build publish

    # Docker publish
    publish: repo-login publish-latest publish-version

    publish-latest: tag-latest
    @echo 'publish latest to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO)/$(APP_NAME):latest

    publish-version: tag-version
    @echo 'publish $(VERSION) to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    # Docker tagging
    tag: tag-latest tag-version

    tag-latest:
    @echo 'create tag latest'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest

    tag-version:
    @echo 'create tag $(VERSION)'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    # HELPERS

    # generate script to login to aws docker repo
    CMD_REPOLOGIN := "eval $$\( aws ecr"
    ifdef AWS_CLI_PROFILE
    CMD_REPOLOGIN += " --profile $(AWS_CLI_PROFILE)"
    endif
    ifdef AWS_CLI_REGION
    CMD_REPOLOGIN += " --region $(AWS_CLI_REGION)"
    endif
    CMD_REPOLOGIN += " get-login \)"

    # login to AWS-ECR
    repo-login:
    @eval $(CMD_REPOLOGIN)

    # output to version
    version:
    @echo $(VERSION)
  5. @mpneuried mpneuried revised this gist Oct 27, 2016. 2 changed files with 16 additions and 5 deletions.
    16 changes: 12 additions & 4 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,18 @@
    # import config
    include config.env
    export $(shell sed 's/=.*//' config.env)
    configfile=config.env
    ifdef cnf
    configfile=$(cnf)
    endif
    include $(configfile)
    export $(shell sed 's/=.*//' $(configfile))

    # import deploy config
    include deploy.env
    export $(shell sed 's/=.*//' deploy.env)
    deployfile=deploy.env
    ifdef dpl
    deployfile=$(dpl)
    endif
    include $(deployfile)
    export $(shell sed 's/=.*//' $(deployfile))

    # grep the version from the mix file
    VERSION=$(shell ./version.sh)
    5 changes: 4 additions & 1 deletion usage.sh
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,7 @@ make run
    make up

    # Stop the running container
    make stop
    make stop

    # Build the container with differnt config and deploy file
    make cnf=another_config.env dpl=another_deploy.env build
  6. @mpneuried mpneuried revised this gist Oct 13, 2016. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ build-nc:

    # Run container on port configured in `config.env`
    run:
    docker run --env-file=./config.env -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)
    docker run -i -t --rm --env-file=./config.env -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

    # Build and run the container
    up: build run
    2 changes: 1 addition & 1 deletion usage.sh
    Original file line number Diff line number Diff line change
    @@ -19,5 +19,5 @@ make run
    # Build an run the container
    make up

    # Stop the running container (needs to executed in a seperate shell)
    # Stop the running container
    make stop
  7. @mpneuried mpneuried revised this gist Oct 13, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -36,11 +36,11 @@ publish: repo-login publish-latest publish-version

    publish-latest: tag-latest
    @echo 'publish latest to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO):latest
    docker push $(DOCKER_REPO)/$(APP_NAME):latest

    publish-version: tag-version
    @echo 'publish $(VERSION) to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO):$(VERSION)
    docker push $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    # Docker tagging
    tag: tag-latest tag-version
  8. @mpneuried mpneuried revised this gist Oct 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deploy.env
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # You have to define teh values in {}
    # You have to define the values in {}
    APP_NAME=my-super-app
    DOCKER_REPO={account-nr}.dkr.ecr.{region}.amazonaws.com
    # optional aws-cli options
  9. @mpneuried mpneuried revised this gist Oct 13, 2016. 2 changed files with 12 additions and 3 deletions.
    5 changes: 5 additions & 0 deletions usage.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    # INSTALL
    # - copy the files deploy.env, config.env, version.sh and Makefile to your repo
    # - replace the vars in deploy.env
    # - define the version script

    # Build the container
    make build

    10 changes: 7 additions & 3 deletions version.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    # grep the version from a mix file
    cat mix.exs | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o
    # grep the version from a package.json file with jq
    # Example version script.
    # Please choose one version or create your own

    # Node.js: grep the version from a package.json file with jq
    jq -rM '.version' package.json

    # Elixir: grep the version from a mix file
    cat mix.exs | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o
  10. @mpneuried mpneuried created this gist Oct 13, 2016.
    75 changes: 75 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    # import config
    include config.env
    export $(shell sed 's/=.*//' config.env)

    # import deploy config
    include deploy.env
    export $(shell sed 's/=.*//' deploy.env)

    # grep the version from the mix file
    VERSION=$(shell ./version.sh)

    # DOCKER TASKS
    # Build the container
    build:
    docker build -t $(APP_NAME) .

    # Build the container without cache
    build-nc:
    docker build --no-cache -t $(APP_NAME) .

    # Run container on port configured in `config.env`
    run:
    docker run --env-file=./config.env -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

    # Build and run the container
    up: build run

    stop:
    docker stop $(APP_NAME); docker rm $(APP_NAME)

    # Docker release - build, tag and push the container
    release: build-nc publish

    # Docker publish
    publish: repo-login publish-latest publish-version

    publish-latest: tag-latest
    @echo 'publish latest to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO):latest

    publish-version: tag-version
    @echo 'publish $(VERSION) to $(DOCKER_REPO)'
    docker push $(DOCKER_REPO):$(VERSION)

    # Docker tagging
    tag: tag-latest tag-version

    tag-latest:
    @echo 'create tag latest'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest

    tag-version:
    @echo 'create tag $(VERSION)'
    docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)

    # HELPERS

    # generate script to login to aws docker repo
    CMD_REPOLOGIN := "eval $$\( aws ecr"
    ifdef AWS_CLI_PROFILE
    CMD_REPOLOGIN += " --profile $(AWS_CLI_PROFILE)"
    endif
    ifdef AWS_CLI_REGION
    CMD_REPOLOGIN += " --region $(AWS_CLI_REGION)"
    endif
    CMD_REPOLOGIN += " get-login \)"

    # login to AWS-ECR
    repo-login:
    @eval $(CMD_REPOLOGIN)

    # output to version
    version:
    @echo $(VERSION)

    4 changes: 4 additions & 0 deletions config.env
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # Port to run the container
    PORT=4000

    # Until here you can define all the individual configurations for your app
    6 changes: 6 additions & 0 deletions deploy.env
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # You have to define teh values in {}
    APP_NAME=my-super-app
    DOCKER_REPO={account-nr}.dkr.ecr.{region}.amazonaws.com
    # optional aws-cli options
    AWS_CLI_PROFILE={aws-cli-profile}
    AWS_CLI_REGION={aws-cli-region}
    18 changes: 18 additions & 0 deletions usage.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Build the container
    make build

    # Build and publish the container
    make release

    # Publish a container to AWS-ECR.
    # This includes the login to the repo
    make publish

    # Run the container
    make run

    # Build an run the container
    make up

    # Stop the running container (needs to executed in a seperate shell)
    make stop
    4 changes: 4 additions & 0 deletions version.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # grep the version from a mix file
    cat mix.exs | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o
    # grep the version from a package.json file with jq
    jq -rM '.version' package.json