Add Dockerfile

This commit is contained in:
Dave Gallant
2022-08-21 02:30:43 +00:00
parent 269b394d3e
commit 9605d395f4
6 changed files with 91 additions and 0 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ node_modules
**.db
backend/bin/
.vscode
*.pem

21
Dockerfile Normal file
View File

@@ -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" ]

64
Makefile Normal file
View File

@@ -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

2
backend/.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
.git
.github

View File

@@ -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")

View File

@@ -12,6 +12,7 @@
<tr>
<th scope="col">Deal</th>
<th scope="col">Views</th>
<th scope="col">Score</th>
<th scope="col">Last Post</th>
</tr>
</thead>
@@ -37,6 +38,7 @@
></a>
</td>
<td scope="col">{{ topic.total_views }}</td>
<td scope="col">{{ topic.votes.up - topic.votes.down }}</td>
<td scope="col">{{ formatDate(topic.last_post_time) }}</td>
</tr>
</tbody>