From 64c234f07cfb0e8d2a57de5c7ea27537adf2b16a Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 23 May 2022 23:26:25 +0100 Subject: [PATCH] chore: add Dockerfile and basic CI test --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ .gitignore | 2 ++ Dockerfile | 13 +++++++++++++ Makefile | 24 ++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bfd7d95 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +--- +name: CI +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.18 + - name: Install dependencies + run: go mod download + - name: Build binary + run: make + - name: Run and make request + run: | + ./bin/dotkatapult --port=8080 & + curl --silent --retry 10 --retry-delay 1 --retry-connrefused \ + http://localhost:8080/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bbc06d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/* +/dotkatapult diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..17f5b7e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.18-alpine as builder + +RUN apk add --no-cache git make +WORKDIR /app +COPY . . +RUN env CGO_ENABLED=0 go build -a -o dotkatapult -ldflags "-s -w" + +FROM scratch +ENV PORT 8080 +EXPOSE 8080 +WORKDIR / +COPY --from=builder /app/dotkatapult / +CMD ["/dotkatapult"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9ccfb64 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +NAME = dotkatapult +BINARY = bin/${NAME} +VERSION ?= $(shell cat VERSION) +SOURCES = $(shell find . -name '*.go' -o -name 'Makefile') + +$(BINARY): $(SOURCES) + CGO_ENABLED=0 go build -a -o ${BINARY} -ldflags "-s -w" + +.PHONY: build +build: $(BINARY) + +.PHONY: run +run: $(BINARY) + $(BINARY) + +.PHONY: clean +clean: + $(eval BIN_DIR := $(shell dirname ${BINARY})) + if [ -f ${BINARY} ]; then rm ${BINARY}; fi + if [ -d ${BIN_DIR} ]; then rmdir ${BIN_DIR}; fi + +.PHONY: docker +docker: + docker build -t "$(shell whoami)/$(NAME)" .