Added docker config files and make handler to build the server into a docker container

This commit is contained in:
Martin Donnelly 2024-08-29 13:08:19 +01:00
parent 46838a5349
commit 2427895aa8
5 changed files with 88 additions and 0 deletions

40
Makefile Normal file
View File

@ -0,0 +1,40 @@
PROJECT = go-pb-jubilee
VERSION=`git describe --tags`
BUILD=`date +%FT%T%z`
ECR_REPO = git.caliban.io/martin
APP_IMAGE = $(ECR_REPO)/$(PROJECT):$(VERSION)
NO_CACHE = true
LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}"
.PHONY: build
build:
#CC=/usr/local/musl/bin/musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' server.go
GCO_ENABLED=0 GOOS=linux go build ${LDFLAGS} -o ${PROJECT} main.go
# go build ${LDFLAGS} -o ${PROJECT} server.go
# docker build ./docker/. -t $(APP_IMAGE) --build-arg VERSION=$(VERSION) --no-cache=$(NO_CACHE) --compress=true
docker build --platform linux/amd64 --no-cache -force-rm --tag ${APP_IMAGE} --file ./docker/Dockerfile .
#push docker image to registry
.PHONY: push
push: build
docker push $(APP_IMAGE)
#push docker image to registry
.PHONY: run
run: build
docker run $(APP_IMAGE)
ver:
@echo '$(VERSION)'
#echo $ERSION
.PHONY: ver

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
version: '3.5'
services:
trainserver:
container_name: jubilee
image: git.caliban.io/martin/go-pb-jubilee:1.0.0
restart: always
ports:
- "8090:8090"

30
docker/Dockerfile Normal file
View File

@ -0,0 +1,30 @@
FROM debian:12-slim
# FROM alpine:latest
WORKDIR /app
RUN mkdir -p /app/dist
COPY ./go-pb-jubilee ./docker/start.sh /app/
COPY ./pb_data /app/pb_data
COPY ./pb_public /app/pb_public
RUN apt-get update && apt-get install -y ca-certificates
# Need the following to get a go app to run inside a docker container
# as per: https://www.fairlyusefulcode.co.uk/post/go-alpine-linux/ -- DEAD!!!
# RUN apk upgrade musl
# RUN apk add gcompat
# RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
# RUN ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
RUN chmod +x /app/go-pb-jubilee
RUN chmod +x /app/start.sh
EXPOSE 8090
CMD [ "/app/go-pb-jubilee", "serve", "--http=0.0.0.0:8090"]
# CMD [ "/app/start.sh"]

9
docker/start.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
set -ex
# npm run dev
# npm run start
while true; do sleep infinity; done

BIN
go-pb-jubilee Executable file

Binary file not shown.