forked from fabianlee/golang-github-action-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·78 lines (60 loc) · 2.08 KB
/
Makefile
File metadata and controls
executable file
·78 lines (60 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
OWNER := fabianlee
PROJECT := golang-github-action-example
VERSION := 1.0.0
OPV := $(OWNER)/$(PROJECT):$(VERSION)
WEBPORT := 8080:8080
# you may need to change to "sudo docker" if not a member of 'docker' group
DOCKERCMD := "docker"
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
# unique id from last git commit
MY_GITREF := $(shell git rev-parse --short HEAD)
BUILT_BY := Dockerfile
BUILD_ARGS := --build-arg MY_VERSION=$(VERSION) --build-arg MY_BUILTBY=$(BUILT_BY)
## builds docker image
docker-build:
echo MY_GITREF is $(MY_GITREF)
$(DOCKERCMD) build $(BUILD_ARGS) -f Dockerfile -t $(OPV) .
docker-builder-then-stop:
echo MY_GITREF is $(MY_GITREF)
$(DOCKERCMD) build --target builder $(BUILD_ARGS) -f Dockerfile -t $(OPV) .
## cleans docker image
clean:
$(DOCKERCMD) image rm $(OPV) | true
## runs container in foreground
docker-test-fg:
$(DOCKERCMD) run -it -p $(WEBPORT) --rm $(OPV)
docker-hub-pull-latest:
git describe --tags
docker pull $(OWNER)/$(PROJECT):latest
$(DOCKERCMD) run -it -p $(WEBPORT) --rm $(OWNER)/$(PROJECT):latest
## runs container in foreground, override entrypoint to use use shell
docker-test-cli:
$(DOCKERCMD) run -it --rm --entrypoint "/bin/sh" $(OPV)
## run container in background
docker-run-bg:
$(DOCKERCMD) run -d -p $(WEBPORT) --rm --name $(PROJECT) $(OPV)
## get into console of container running in background
docker-cli-bg:
$(DOCKERCMD) exec -it $(PROJECT) /bin/sh
## tails $(DOCKERCMD)logs
docker-logs:
$(DOCKERCMD) logs -f $(PROJECT)
## stops container running in background
docker-stop:
$(DOCKERCMD) stop $(PROJECT)
## pushes to $(DOCKERCMD)hub
docker-push:
$(DOCKERCMD) push $(OPV)
# test source program build from host (must have GoLang installed)
golang-build-local:
mkdir -p build
cp src/main.go build/main.go
cd build && \
[ -f go.mod ] || go mod init $(OWNER)/$(PROJECT) && \
go mod tidy && \
go build -ldflags "-X main.Version=$(VERSION) -X main.BuiltBy=makefile" main.go
## pushes to kubernetes cluster
k8s-apply:
sed -e 's/1.0.0/$(VERSION)/' golang-signal-web.yaml | kubectl apply -f -
k8s-delete:
kubectl delete -f golang-signal-web.yaml