diff --git a/Dockerfile b/Dockerfile index f952f47..1c4f2c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,20 @@ -# syntax=docker/dockerfile:1 - -FROM golang:1.18-alpine - -# hadolint ignore=DL3018 -RUN apk --no-cache add \ - gcc \ - musl-dev +FROM node:18-alpine3.16 as build-stage WORKDIR /app -COPY backend/ . +COPY package*.json ./ -RUN CGO_ENABLED=1 GOOS=linux \ - go build -o /rfd-fyi \ - # Additional flags are necessary for sqlite support - -a -ldflags '-linkmode external -extldflags "-static"' . +RUN yarn install -EXPOSE 8080 +COPY . . -CMD [ "/rfd-fyi" ] +RUN yarn build + +FROM nginx:stable-alpine as production-stage + +COPY --from=build-stage /app/dist /usr/share/nginx/html + +COPY nginx.conf /etc/nginx/ + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/Makefile b/Makefile deleted file mode 100644 index 05a3644..0000000 --- a/Makefile +++ /dev/null @@ -1,64 +0,0 @@ -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/README.md b/README.md index 494f3b3..39d45a1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rfd-launcher +# rfd-fyi ## Project setup ``` diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..e8d5dc7 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.18-alpine as go-build + +# hadolint ignore=DL3018 +RUN apk --no-cache add \ + gcc \ + musl-dev + +COPY . /backend + +WORKDIR /backend + +RUN CGO_ENABLED=1 GOOS=linux \ + go build -o server \ + # Additional flags are necessary for sqlite support + -a -ldflags '-linkmode external -extldflags "-static"' . + +EXPOSE 8080 + +CMD [ "/backend/server" ] diff --git a/backend/Makefile b/backend/Makefile deleted file mode 100644 index b1af039..0000000 --- a/backend/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -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-launcher -.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 - -## container: Build a container image with Docker -container: - docker build . -t rfd-launcher -.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-launcher" \ - rfd-launcher -.PHONY: container-run diff --git a/backend/app.go b/backend/app.go index 3ca52b1..418a50f 100644 --- a/backend/app.go +++ b/backend/app.go @@ -14,7 +14,7 @@ import ( _ "github.com/jinzhu/gorm/dialects/sqlite" ) -// @title RFD LAUNCHER API +// @title RFD FYI API // @version 1.0 // @description An API for issue tracking // @termsOfService http://swagger.io/terms/ diff --git a/backend/go.mod b/backend/go.mod index 6e9a41b..7130922 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,4 +1,4 @@ -module github.com/davegallant/rfd-launcher +module github.com/davegallant/rfd-fyi go 1.18 diff --git a/backend/main.go b/backend/main.go index a5af6ac..1e7d2b0 100644 --- a/backend/main.go +++ b/backend/main.go @@ -10,10 +10,10 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - utils "github.com/davegallant/rfd-launcher/pkg/utils" + utils "github.com/davegallant/rfd-fyi/pkg/utils" ) -// @title RFD Launcher API +// @title RFD FYI API // @version 1.0 // @description An API for an issue tracking service // @termsOfService http://swagger.io/terms/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3389b11 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.9" +services: + frontend: + build: + dockerfile: Dockerfile + ports: + - 80:80 + links: + - "backend:backend" + backend: + build: + dockerfile: Dockerfile + context: backend + ports: + - 8080:8080 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..ba1165a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,30 @@ +events { + worker_connections 1024; +} + +http { + + upstream backend { + server backend:8080; + } + + server { + listen 80 default_server; + listen [::]:80 default_server; + + location / { + root /usr/share/nginx/html; + } + + location /api/ { + proxy_pass http://backend; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } + + } + +} diff --git a/package-lock.json b/package-lock.json index 5bf5d66..2e8e978 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "rfd-launcher", + "name": "rfd-fyi", "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "rfd-launcher", + "name": "rfd-fyi", "version": "0.1.0", "dependencies": { "@popperjs/core": "^2.11.5", diff --git a/package.json b/package.json index 2e86fb3..4cb14f1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "rfd-launcher", + "name": "rfd-fyi", "version": "0.1.0", "private": true, "scripts": { diff --git a/src/App.vue b/src/App.vue index d7889ba..9d1598a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -38,7 +38,7 @@ > {{ topic.total_views }} - {{ topic.votes.up - topic.votes.down }} + {{ formatDate(topic.last_post_time) }} @@ -75,7 +75,7 @@ export default { }, fetchDeals() { axios - .get("http://localhost:8081/api/v1/topics") + .get("api/v1/topics") .then((response) => { this.topics = response.data; this.isLoading = false; diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue deleted file mode 100644 index 879051a..0000000 --- a/src/components/HelloWorld.vue +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - diff --git a/vue.config.js b/vue.config.js index abbc0dc..038d8dc 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,7 +1,7 @@ -const { defineConfig } = require('@vue/cli-service') +const { defineConfig } = require("@vue/cli-service"); module.exports = defineConfig({ transpileDependencies: true, devServer: { - proxy: 'http://localhost:8080' - } -}) + proxy: "http://localhost:8080", + }, +});