From 9605d395f4b28e291476abf76b5470dbd24f4c6e Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Sun, 21 Aug 2022 02:30:43 +0000 Subject: [PATCH] Add Dockerfile --- .gitignore | 1 + Dockerfile | 21 ++++++++++++++ Makefile | 64 +++++++++++++++++++++++++++++++++++++++++++ backend/.dockerignore | 2 ++ backend/app.go | 1 + src/App.vue | 2 ++ 6 files changed, 91 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 backend/.dockerignore diff --git a/.gitignore b/.gitignore index f8cd609..e3b5d10 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules **.db backend/bin/ .vscode +*.pem diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f952f47 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.18-alpine + +# hadolint ignore=DL3018 +RUN apk --no-cache add \ + gcc \ + musl-dev + +WORKDIR /app + +COPY backend/ . + +RUN CGO_ENABLED=1 GOOS=linux \ + go build -o /rfd-fyi \ + # Additional flags are necessary for sqlite support + -a -ldflags '-linkmode external -extldflags "-static"' . + +EXPOSE 8080 + +CMD [ "/rfd-fyi" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..05a3644 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +SHELL := bash +.SHELLFLAGS := -eu -o pipefail -c +.DELETE_ON_ERROR: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules + +BASE_PATH ?= "http://localhost:8080" + +## help: Print this help message +help: + @echo + @echo "Usage:" + @echo + @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' | sort + @echo +.PHONY: help + +## build: Build the binary +build: + @mkdir -p bin + go build -o bin/rfd-fyi +.PHONY: build + +## test: Run tests in colour +test: + @go install github.com/rakyll/gotest@latest + gotest -v -count=1 +.PHONY: test + +## fmt: Format code (with gofumpt) +fmt: + @go install mvdan.cc/gofumpt@latest + gofumpt -w . +.PHONY: fmt + +## swagger: Generate swagger docs +swagger: + @go install github.com/swaggo/swag/cmd/swag@latest + swag init --outputTypes yaml +.PHONY: swagger + +## server: Build and run server from source +server: + @go run . +.PHONY: server + +## seed: Generate several issues via the create endpoint +seed: + BASE_PATH=$(BASE_PATH) ./scripts/generate-issues.sh +.PHONY: seed + +## container: Build a container image with Docker +container: + docker build . -t rfd-fyi +.PHONY: container + +## container-run: Build and run a container with Docker +container-run: container + @docker run \ + --network host \ + -u "$$(id -u)":"$$(id -g)"\ + -v "$$PWD":"/opt/rfd-fyi" \ + rfd-fyi +.PHONY: container-run diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..f4b1198 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,2 @@ +.git +.github diff --git a/backend/app.go b/backend/app.go index ce383ea..3ca52b1 100644 --- a/backend/app.go +++ b/backend/app.go @@ -90,6 +90,7 @@ func (a *App) listTopics(w http.ResponseWriter, r *http.Request) { func (a *App) refreshDeals() { topics := a.getDeals(9, 1, 10) + // only drop deals if a timer has been met log.Debug().Msg("Dropping deals") a.DB.DropTable(&Topic{}) log.Debug().Msg("Refreshing the deals") diff --git a/src/App.vue b/src/App.vue index 5b6b3dc..d7889ba 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,6 +12,7 @@ Deal Views + Score Last Post @@ -37,6 +38,7 @@ > {{ topic.total_views }} + {{ topic.votes.up - topic.votes.down }} {{ formatDate(topic.last_post_time) }}