File tree Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Original file line number Diff line number Diff line change 1
1
build
2
+ etc /_cli
Original file line number Diff line number Diff line change 1
1
# Paths to tools needed in dependencies
2
2
GO := $(shell which go)
3
+ DOCKER := $(shell which docker)
3
4
4
5
# Build flags
5
6
BUILD_MODULE := $(shell cat go.mod | head -1 | cut -d ' ' -f 2)
@@ -10,28 +11,48 @@ BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitHash=$(shell git rev-parse H
10
11
BUILD_LD_FLAGS += -X $(BUILD_MODULE ) /pkg/version.GoBuildTime=$(shell date -u '+% Y-% m-% dT% H:% M:% SZ')
11
12
BUILD_FLAGS = -ldflags "-s -w $(BUILD_LD_FLAGS ) "
12
13
14
+ # Set OS and Architecture
15
+ ARCH ?= $(shell arch | tr A-Z a-z | sed 's/x86_64/amd64/' | sed 's/i386/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/')
16
+ OS ?= $(shell uname | tr A-Z a-z)
17
+ VERSION ?= $(shell git describe --tags --always | sed 's/^v//')
18
+
13
19
# Paths to locations, etc
14
20
BUILD_DIR := "build"
15
21
CMD_DIR := $(wildcard cmd/* )
22
+ BUILD_TAG := go-client-${OS}-${ARCH}:${VERSION}
16
23
17
24
# Targets
18
25
all : clean cmd
19
26
20
27
cmd : $(CMD_DIR )
21
28
22
- test :
29
+ docker : docker-dep
30
+ @echo build docker image: ${BUILD_TAG} for ${OS} /${ARCH}
31
+ @${DOCKER} build \
32
+ --tag ${BUILD_TAG} \
33
+ --build-arg ARCH=${ARCH} \
34
+ --build-arg OS=${OS} \
35
+ --build-arg SOURCE=${BUILD_MODULE} \
36
+ --build-arg VERSION=${VERSION} \
37
+ -f etc/Dockerfile .
38
+
39
+ test : go-dep
40
+ @echo Test
23
41
@${GO} mod tidy
24
42
@${GO} test ./pkg/...
25
43
26
- $(CMD_DIR ) : dependencies mkdir
44
+ $(CMD_DIR ) : go-dep mkdir
27
45
@echo Build cmd $(notdir $@ )
28
46
@${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR} /$(notdir $@ ) ./$@
29
47
30
48
FORCE :
31
49
32
- dependencies :
50
+ go-dep :
33
51
@test -f " ${GO} " && test -x " ${GO} " || (echo " Missing go binary" && exit 1)
34
52
53
+ docker-dep :
54
+ @test -f " ${DOCKER} " && test -x " ${DOCKER} " || (echo " Missing docker binary" && exit 1)
55
+
35
56
mkdir :
36
57
@echo Mkdir ${BUILD_DIR}
37
58
@install -d ${BUILD_DIR}
Original file line number Diff line number Diff line change
1
+ ARG OS
2
+ ARG ARCH
3
+
4
+ # Run makefile to build all the commands
5
+ FROM --platform=${OS}/${ARCH} golang:1.21-bullseye AS builder
6
+ ARG OS
7
+ ARG ARCH
8
+ WORKDIR /usr/src/app
9
+ COPY . .
10
+ RUN OS=${OS} ARCH=${ARCH} make
11
+
12
+ # Copy server to /usr/local/bin
13
+ FROM --platform=${OS}/${ARCH} debian:bullseye-slim
14
+ ARG OS
15
+ ARG ARCH
16
+ ARG SOURCE
17
+ RUN apt update && apt install -y ca-certificates
18
+ COPY --from=builder /usr/src/app/build/* /usr/local/bin/
19
+ COPY etc/entrypoint.sh .
20
+
21
+ # Labels
22
+ LABEL org.opencontainers.image.source=${SOURCE}
23
+
24
+ # Entrypoint when running the server
25
+ ENTRYPOINT [ "/entrypoint.sh" ]
26
+ CMD [ "/usr/local/bin/api" ]
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ if [ -z " $1 " ]; then
4
+ echo " No command specified"
5
+ exit 1
6
+ fi
7
+
8
+ # Nomad: Create the /alloc/logs folder if it doesn't exist
9
+ install -d -m 0755 /alloc/logs || exit 1
10
+
11
+ # Run the command
12
+ set -e
13
+ exec " $@ "
You can’t perform that action at this time.
0 commit comments