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

feat(makefile): adding docker-build and docker-run targets to the makefile #71

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
GO_BUILD= go build
GOFLAGS= CGO_ENABLED=0
REGISTRY_IMAGE_NAME=golang_app
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atallison I would replace the var name with DOCKER_REPO for 2 reasons: the prefix DOCKER signifies the scope and a docker repo is usually synonymous with <registry>/<image>.

I would also replace the value to rog-golang-buddies/template.


## help: Print this help message
.PHONY: help
Expand Down Expand Up @@ -40,3 +41,17 @@ fmt:
.PHONY: build
build:
$(GOFLAGS) $(GO_BUILD) -a -v -ldflags="-w -s" -o bin/app cmd/main.go

## docker-build: Builds a docker image
.PHONY: docker-build
docker-build:
docker build . -t $(REGISTRY_IMAGE_NAME)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we can run this as make docker REGISTRY_IMAGE_NAME=template override the image, we should also use DOCKER_TAG with a default value of latest. That way the tag can be explicitly set, specially in CI.


## docker-run: Runs the docker image built by make docker-build
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atallison, Can we keep the help messages consistent? "Build" instead of "Builds" etc.

Maybe we should update the message to "Runs the docker image built via [make docker-build]" to separate out that it is a command?

.PHONY: docker-run
docker-run:
docker run $(REGISTRY_IMAGE_NAME)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atallison, We should probably add the --rm option to automatically removes the container on exit.


## docker: Builds and runs the docker image
.PHONY: docker
docker: docker-build docker-run