Skip to content

Commit ddff55b

Browse files
committed
Added Dockerfile
1 parent 51f3c6b commit ddff55b

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build
2+
etc/_cli

Makefile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Paths to tools needed in dependencies
22
GO := $(shell which go)
3+
DOCKER := $(shell which docker)
34

45
# Build flags
56
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
1011
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GoBuildTime=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
1112
BUILD_FLAGS = -ldflags "-s -w $(BUILD_LD_FLAGS)"
1213

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+
1319
# Paths to locations, etc
1420
BUILD_DIR := "build"
1521
CMD_DIR := $(wildcard cmd/*)
22+
BUILD_TAG := go-client-${OS}-${ARCH}:${VERSION}
1623

1724
# Targets
1825
all: clean cmd
1926

2027
cmd: $(CMD_DIR)
2128

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
2341
@${GO} mod tidy
2442
@${GO} test ./pkg/...
2543

26-
$(CMD_DIR): dependencies mkdir
44+
$(CMD_DIR): go-dep mkdir
2745
@echo Build cmd $(notdir $@)
2846
@${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/$(notdir $@) ./$@
2947

3048
FORCE:
3149

32-
dependencies:
50+
go-dep:
3351
@test -f "${GO}" && test -x "${GO}" || (echo "Missing go binary" && exit 1)
3452

53+
docker-dep:
54+
@test -f "${DOCKER}" && test -x "${DOCKER}" || (echo "Missing docker binary" && exit 1)
55+
3556
mkdir:
3657
@echo Mkdir ${BUILD_DIR}
3758
@install -d ${BUILD_DIR}

etc/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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" ]

etc/entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 "$@"

0 commit comments

Comments
 (0)