-
Notifications
You must be signed in to change notification settings - Fork 1
Makefile Usage
This document explains how to use the Makefile provided in the go-api project. The Makefile contains various targets to help you manage the build, run, and deployment processes of the application.
-
APP_NAME: The name of the application. Default isgo-api. -
TZ: The timezone for the Docker container. Default isAsia/Shanghai. -
IMAGE_NAME: The name of the Docker image. Default is$(APP_NAME):latest. -
CONFIG_DIR: The directory for configuration files. Default is$(shell pwd)/bin/configs. -
GO_FLAGS: Flags for thego buildcommand. Default is-ldflags="-s -w". -
RUN_ENV: The environment in which the application will run. Default islocal.
The default target that includes formatting, linting, testing, and building the application.
make allFormats the source code using gofmt and organizes imports using goimports.
make fmtFormats the source code and builds the Go binary.
make buildRuns the application binary.
make runBuilds the Docker image for the application.
make docker-buildStops and removes any existing Docker container with the same name, then runs a new Docker container for the application.
make docker-runStops and removes any existing Docker container with the same name.
make docker-cleanCleans up build artifacts.
make clean-
Format the source code:
make fmt
-
Build the application:
make build
-
Run the application:
make run
-
Build the Docker image:
make docker-build
-
Run the Docker container:
make docker-run
-
Clean up build artifacts:
make clean
You can override the default variables by passing them as arguments when invoking make. Here are some examples:
-
Change the application name:
make build APP_NAME=myapp
-
Set a different timezone for the Docker container:
make docker-build TZ=America/New_York
-
Specify a custom Docker image name:
make docker-build IMAGE_NAME=myapp:1.0.0
-
Change the configuration directory:
make docker-run CONFIG_DIR=/path/to/configs
-
Set a different run environment:
make docker-run RUN_ENV=production
- Ensure that Docker is installed and running on your system before using the Docker-related targets.
- Customize the variables in the
Makefileas needed for your specific environment and requirements.