Skip to content

Commit 5184d16

Browse files
vwalchValerie Walch
andauthored
Fix training labels error (#18)
* Added docker files. * Added instructions for docker. * ExtractTrainingLabel errors no longer stop processing. --------- Co-authored-by: Valerie Walch <roboticvalkyrie@gmail.com>
1 parent e9c040c commit 5184d16

10 files changed

Lines changed: 89 additions & 15 deletions

File tree

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.22.2
4+
5+
WORKDIR /app
6+
7+
COPY go.mod go.sum ./
8+
9+
RUN go mod download
10+
11+
COPY auth ./auth
12+
COPY config ./config
13+
COPY db ./db
14+
COPY docs ./docs
15+
COPY handlers ./handlers
16+
COPY models ./models
17+
COPY services ./services
18+
COPY setup ./setup
19+
COPY utils ./utils
20+
COPY webhooks ./webhooks
21+
COPY data ./data
22+
COPY web-ui ./web-ui
23+
COPY config.yaml key.pem cert.pem main.go rsakey.pem build.sh run.sh ./
24+
25+
RUN CGO_ENABLED=1 GOOS=linux go build -o dingus-server
26+
27+
# Optional:
28+
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
29+
# But we can document in the Dockerfile what ports
30+
# the application is going to listen on by default.
31+
# https://docs.docker.com/reference/dockerfile/#expose
32+
EXPOSE 443
33+
34+
# Run
35+
CMD ["/app/run.sh"]

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,28 @@ This project is an RFID access control system's backend server written in Golang
4848
- `web-ui`: Frontend assets.
4949

5050
## Getting Started
51+
### Docker
52+
#### Build
53+
`docker-compose build`
54+
#### Run Interactive
55+
`docker-compose up`
5156

52-
### Prerequisites
57+
`ctrl-c` to stop.
58+
59+
#### Run in background (Detached)
60+
`docker-compose up -d`
61+
#### Stop
62+
`docker-compose down`
63+
64+
### Native
65+
#### Prerequisites
5366

5467
- [Go](https://go.dev/doc/install) (latest stable version)
5568
- Access to [Wild Apricot API](https://gethelp.wildapricot.com/en/articles/182-using-wildapricot-s-api)
5669
- SSL certificate and key
5770
- GCC for SQLite Go package compilation (requires cgo)
5871

59-
### Setting CGO_ENABLED
72+
#### Setting CGO_ENABLED
6073

6174
To successfully build and run this project, `CGO_ENABLED` must be set to `1`. This allows for the compilation of C code, a requirement for the SQLite package used in the project.
6275

build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
export WILD_APRICOT_API_KEY=ilyglbbwzai5suuxt4nai0kqx5evvh
4+
export WILD_APRICOT_WEBHOOK_TOKEN=08a7gv08abwDYGd77cxv980asdfy98zxc87
5+
export WILD_APRICOT_SSO_CLIENT_ID=t8jw60pj3f
6+
export WILD_APRICOT_SSO_CLIENT_SECRET=5k8nct39ootl8wt0gkpxe22v8phi5a
7+
export WILD_APRICOT_SSO_REDIRECT_URI=/replaceme
8+
export LOG_LEVEL=INFO
9+
export COOKIE_STORE_SECRET=cookiestoresecret
10+
export CGO_ENABLED=1
11+
export GOOS=linux
12+
/usr/local/go/bin/go build -o dingus-server

compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
dingus-server:
3+
build: .
4+
ports:
5+
- "443:443"

config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
cert_file: .ssh/id_rsa/dev_pubkey.pem
1+
cert_file: cert.pem
22
contact_filter_query: "(Status eq Active or Status eq PendingRenewal) and 'Door Key' ne NULL"
3-
database_path: db/data/tagsdb.sqlite
4-
key_file: .ssh/id_rsa/dev_secret.pem
3+
database_path: data/tagsdb.sqlite
4+
key_file: key.pem
55
tag_id_field_name: Door Key
66
training_field_name: Safety Training
77
wild_apricot_account_id: 232582

db/data/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

models/wildApricotContact.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ func (c *Contact) ExtractContactData(cfg *config.Config) (int, uint32, []string,
6565

6666
trainingLabels, err := c.ExtractTrainingLabels(cfg)
6767
if err != nil {
68-
return 0, 0, nil, fmt.Errorf("error extracting training labels for contact %d: %v", c.Id, err)
68+
err = fmt.Errorf("error extracting training labels for contact %d: %v", c.Id, err)
6969
}
7070

71-
return c.Id, tagID, trainingLabels, nil
71+
return c.Id, tagID, trainingLabels, err
7272
}
7373

7474
func parseTagId(fieldValue FieldValue) (uint32, error) {

run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
export WILD_APRICOT_API_KEY=ilyglbbwzai5suuxt4nai0kqx5evvh
4+
export WILD_APRICOT_WEBHOOK_TOKEN=08a7gv08abwDYGd77cxv980asdfy98zxc87
5+
export WILD_APRICOT_SSO_CLIENT_ID=t8jw60pj3f
6+
export WILD_APRICOT_SSO_CLIENT_SECRET=5k8nct39ootl8wt0gkpxe22v8phi5a
7+
export WILD_APRICOT_SSO_REDIRECT_URI=/replaceme
8+
export LOG_LEVEL=INFO
9+
export COOKIE_STORE_SECRET=cookiestoresecret
10+
export CGO_ENABLED=1
11+
export GOOS=linux
12+
./dingus-server

services/dbService.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func (s *DBService) ProcessContactsData(contacts []models.Contact) error {
134134
for _, contact := range contacts {
135135
contactId, tagId, trainingLabels, err := contact.ExtractContactData(s.cfg)
136136
if err != nil {
137-
return err
137+
// output the error and save any data that was retrieved.
138+
s.log.Error(err)
138139
}
139140

140141
if contactId != 0 && tagId != 0 {
@@ -167,6 +168,7 @@ func (s *DBService) ProcessContactsData(contacts []models.Contact) error {
167168
tx.Rollback()
168169
return err
169170
}
171+
170172
return tx.Commit()
171173
}
172174

services/wildApricotService.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net/http"
109
"net/url"
1110
"rfid-backend/config"
@@ -47,7 +46,7 @@ func NewWildApricotService(cfg *config.Config, logger *logrus.Logger) *WildApric
4746

4847
func readResponseBody(resp *http.Response) ([]byte, error) {
4948
defer resp.Body.Close()
50-
return ioutil.ReadAll(resp.Body)
49+
return io.ReadAll(resp.Body)
5150
}
5251

5352
func handleHTTPError(resp *http.Response) error {
@@ -169,6 +168,7 @@ func (s *WildApricotService) GetContacts() ([]models.Contact, error) {
169168
}
170169

171170
s.log.Infof("Parsed %d contacts from response", len(contacts))
171+
172172
return contacts, nil
173173
}
174174

0 commit comments

Comments
 (0)