Skip to content

Instantly share code, notes, and snippets.

@marjamis
Last active April 20, 2023 09:39
Show Gist options
  • Save marjamis/d5d17ae8c01addd438aa3f92f3698692 to your computer and use it in GitHub Desktop.
Save marjamis/d5d17ae8c01addd438aa3f92f3698692 to your computer and use it in GitHub Desktop.
Starter application files
FROM golang:1.19 as build
WORKDIR /go/src/
COPY go.* .
RUN go mod download
COPY . .
# --mount flag allows for speedier builds of the binary
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux go build -o app main.go
# Final image in the build process
FROM scratch
COPY --from=build /go/src/app /app
ENTRYPOINT ["/app"]
#!/bin/bash -e
COMMAND_LINE_OPTIONS_HELP="helper"
function help {
echo "Usage: helper -h for help";
echo "$COMMAND_LINE_OPTIONS_HELP"
}
function error {
printf "Error: $1\n"
if [ ! "$3" == "no" ] ; then
printf "Printing help...\n\n"
help
fi
exit $2
}
function select_action {
LIST="Option #1
Option #2
"
ACTION=$(echo -e "$LIST" | gum choose)
case "$ACTION" in
"New Day") action_new_function ;;
\?) error "E_OPTERROR_UNKNOWNOPTION" 2 ;;
*) error "E_OPTERROR_NOOPTION" 3 ;;
esac
}
# Start of script execution
# Check if gum is installed and if not exit with details on how to install
if [ ! $(command -v gum) ] ; then
error "Gum is not installed. Please refer to the documentation: https://github.com/charmbracelet/gum" 1 "no"
fi
while getopts ":h" flag ; do
case "$flag" in
h) help ;;
\?) error "E_OPTERROR_UNKNOWNOPTION" 2 ;;
*) error "E_OPTERROR_NOOPTION" 3 ;;
esac
done
# Checks that a flag was provided and runs the script proper
if [ "$#" == 0 ]; then
select_action
fi
.DEFAULT_GOAL := helper
GIT_COMMIT ?= $(shell git rev-parse --short=12 HEAD || echo "NoGit")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d_%H:%M:%S')
TEXT_RED = \033[0;31m
TEXT_BLUE = \033[0;34;1m
TEXT_GREEN = \033[0;32;1m
TEXT_NOCOLOR = \033[0m
helper: # Adapted from: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@echo "Available targets..." # @ will not output shell command part to stdout that Makefiles normally do but will execute and display the output.
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
command:
echo "Application run: $(OPTIONS)"
test: ## Builds and then runs tests against the application
prod: ## Runs the prod version of the application
$(MAKE) command OPTIONS="-p 8080"
dev: ## Runs a dev version of the application
$(MAKE) command
clean: ## Cleans up any old/unneeded items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment