Compare commits
13 Commits
e7387be995
...
master
Author | SHA1 | Date | |
---|---|---|---|
7e4b39f2e6
|
|||
f519b94392
|
|||
5a0da6560d
|
|||
6aed7cb7fa
|
|||
5ed16bdab3
|
|||
7939a6fde1
|
|||
e78d0a7276
|
|||
e544ea8426
|
|||
56adeaf1b8
|
|||
a72eead432
|
|||
6e0375c666
|
|||
ff2a90ed3d
|
|||
6d92358f79
|
35
.gitea/workflows/image-build.yaml
Normal file
35
.gitea/workflows/image-build.yaml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
name: Build and Push Docker Image on Tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build and Push Docker Image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: code.dlmw.ch
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: code.dlmw.ch/dlmw/qv:${{ env.GITHUB_REF_NAME }}
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -29,4 +29,5 @@ go.work.sum
|
|||||||
*.sqlite
|
*.sqlite
|
||||||
|
|
||||||
# exclude built binary
|
# exclude built binary
|
||||||
web
|
web
|
||||||
|
dist/
|
||||||
|
43
.goreleaser.yaml
Normal file
43
.goreleaser.yaml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod tidy
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- id: qv
|
||||||
|
main: ./cmd/web
|
||||||
|
binary: qv
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
- darwin
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
goamd64:
|
||||||
|
- v1
|
||||||
|
- v2
|
||||||
|
- v3
|
||||||
|
- v4
|
||||||
|
goarm64:
|
||||||
|
- v8.0
|
||||||
|
ldflags:
|
||||||
|
- -s -w
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- id: qv-archive
|
||||||
|
name_template: >-
|
||||||
|
{{ .ProjectName }}_
|
||||||
|
{{- .Version }}_
|
||||||
|
{{- .Os }}_
|
||||||
|
{{- .Arch }}_
|
||||||
|
{{- if eq .Arch "amd64" }}{{ .Amd64 }}
|
||||||
|
{{- else if eq .Arch "arm64" }}{{ .Arm64 }}
|
||||||
|
{{- end }}
|
||||||
|
formats: [ "tar.gz" ]
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
formats: [ "zip" ]
|
15
Dockerfile
15
Dockerfile
@ -1,7 +1,4 @@
|
|||||||
FROM golang:1.23-alpine
|
FROM golang:1.23-alpine AS build
|
||||||
|
|
||||||
RUN mkdir /qv
|
|
||||||
ENV QV_DATABASE_PATH="/qv/qv.sqlite"
|
|
||||||
|
|
||||||
WORKDIR /usr/src/qv
|
WORKDIR /usr/src/qv
|
||||||
|
|
||||||
@ -11,4 +8,12 @@ RUN go mod download && go mod verify
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN go build -ldflags "-s -w" -v -o /usr/local/bin/qv ./cmd/web/
|
RUN go build -ldflags "-s -w" -v -o /usr/local/bin/qv ./cmd/web/
|
||||||
|
|
||||||
CMD ["qv"]
|
FROM alpine
|
||||||
|
|
||||||
|
RUN mkdir /qv
|
||||||
|
ENV QV_DATABASE_PATH="/qv/qv.sqlite"
|
||||||
|
VOLUME /qv
|
||||||
|
|
||||||
|
COPY --from=build /usr/local/bin/qv /usr/local/bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["qv"]
|
20
Makefile
20
Makefile
@ -1,18 +1,10 @@
|
|||||||
BINARY_NAME=qv
|
.PHONY: compile compile-snapshot clean
|
||||||
LD_FLAGS=-s -w
|
|
||||||
PLATFORMS=linux/amd64 darwin/amd64 windows/amd64
|
|
||||||
|
|
||||||
.PHONY: compile clean
|
|
||||||
|
|
||||||
compile:
|
compile:
|
||||||
@for PLATFORM in $(PLATFORMS); do \
|
@goreleaser release --clean --skip=publish
|
||||||
GOOS=$$(echo $$PLATFORM | cut -d'/' -f1); \
|
|
||||||
GOARCH=$$(echo $$PLATFORM | cut -d'/' -f2); \
|
compile-snapshot:
|
||||||
echo "Building for $$GOOS/$$GOARCH..."; \
|
@goreleaser release --clean --snapshot --skip=publish
|
||||||
go build -ldflags="$(LD_FLAGS)" -o "$(BINARY_NAME)-$$GOOS-$$GOARCH" ./cmd/web/ && \
|
|
||||||
echo "Build successful: $(BINARY_NAME)-$$GOOS-$$GOARCH" || \
|
|
||||||
echo "Build failed for $$GOOS/$$GOARCH"; \
|
|
||||||
done
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm qv-*-amd64
|
@rm -r dist/
|
@ -277,7 +277,7 @@ func (app *application) createVotesHandleKnownVotersElection(w http.ResponseWrit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) createVotesHandleUnknownVotersElection(w http.ResponseWriter, r *http.Request, election *models.Election) (string, error) {
|
func (app *application) createVotesHandleUnknownVotersElection(w http.ResponseWriter, r *http.Request, election *models.Election) (string, error) {
|
||||||
voterIdentity := r.RemoteAddr
|
voterIdentity := realIP(r)
|
||||||
|
|
||||||
voterExists, err := app.voters.Exists(voterIdentity, election.ID)
|
voterExists, err := app.voters.Exists(voterIdentity, election.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,7 +5,9 @@ import (
|
|||||||
"code.dlmw.ch/dlmw/qv/internal/validator"
|
"code.dlmw.ch/dlmw/qv/internal/validator"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *application) serverError(w http.ResponseWriter, r *http.Request, err error) {
|
func (app *application) serverError(w http.ResponseWriter, r *http.Request, err error) {
|
||||||
@ -67,3 +69,23 @@ func (app *application) unmarshalRequest(r *http.Request, dst any) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func realIP(r *http.Request) string {
|
||||||
|
var ip string
|
||||||
|
|
||||||
|
if tcip := r.Header.Get(http.CanonicalHeaderKey("True-Client-IP")); tcip != "" {
|
||||||
|
ip = tcip
|
||||||
|
} else if xrip := r.Header.Get(http.CanonicalHeaderKey("X-Real-IP")); xrip != "" {
|
||||||
|
ip = xrip
|
||||||
|
} else if xff := r.Header.Get(http.CanonicalHeaderKey("X-Forwarded-For")); xff != "" {
|
||||||
|
i := strings.Index(xff, ",")
|
||||||
|
if i == -1 {
|
||||||
|
i = len(xff)
|
||||||
|
}
|
||||||
|
ip = xff[:i]
|
||||||
|
}
|
||||||
|
if ip == "" || net.ParseIP(ip) == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@ func (app *application) recoverPanic(next http.Handler) http.Handler {
|
|||||||
func (app *application) logRequest(next http.Handler) http.Handler {
|
func (app *application) logRequest(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
ip = r.RemoteAddr
|
ip = realIP(r)
|
||||||
proto = r.Proto
|
proto = r.Proto
|
||||||
method = r.Method
|
method = r.Method
|
||||||
uri = r.URL.RequestURI()
|
uri = r.URL.RequestURI()
|
||||||
|
@ -3,7 +3,7 @@ info:
|
|||||||
title: qv - dlmw
|
title: qv - dlmw
|
||||||
description: |-
|
description: |-
|
||||||
This is the documentation for the qv (Quadratic Voting) API.
|
This is the documentation for the qv (Quadratic Voting) API.
|
||||||
termsOfService: http://swagger.io/terms/
|
termsOfService:
|
||||||
contact:
|
contact:
|
||||||
email: dylan@dlmw.ch
|
email: dylan@dlmw.ch
|
||||||
license:
|
license:
|
||||||
@ -11,10 +11,10 @@ info:
|
|||||||
url: https://www.gnu.org/licenses/gpl-3.0.txt
|
url: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
externalDocs:
|
externalDocs:
|
||||||
description: Find out more about qv # todo
|
description: Get the code
|
||||||
url: http://swagger.io # todo
|
url: https://code.dlmw.ch/dlmw/qv
|
||||||
servers:
|
servers:
|
||||||
- url: https://petstore3.swagger.io/api/v3 # todo
|
- url: https://qv.dlmw.ch/api
|
||||||
tags:
|
tags:
|
||||||
- name: election
|
- name: election
|
||||||
description: Retrieve data related to elections
|
description: Retrieve data related to elections
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module code.dlmw.ch/dlmw/qv
|
module code.dlmw.ch/dlmw/qv
|
||||||
|
|
||||||
go 1.23.4
|
go 1.24
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/golang-migrate/migrate/v4 v4.18.1
|
github.com/golang-migrate/migrate/v4 v4.18.1
|
||||||
|
@ -98,7 +98,15 @@
|
|||||||
:href="`/election/${createdElectionId}`"
|
:href="`/election/${createdElectionId}`"
|
||||||
class="text-blue-600 underline hover:text-blue-800"
|
class="text-blue-600 underline hover:text-blue-800"
|
||||||
target="_blank">
|
target="_blank">
|
||||||
View Election
|
View election
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a
|
||||||
|
:href="`/election/${createdElectionId}/results`"
|
||||||
|
class="text-blue-600 underline hover:text-blue-800"
|
||||||
|
target="_blank">
|
||||||
|
View results
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user